mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 12:07:00 -04:00
Proper Size for Suggestion View
Header&Row evenly spread with fixed height.
This commit is contained in:
parent
5a6f2b27c8
commit
357e4dbad0
@ -3,6 +3,23 @@ QWidget {
|
||||
border: none;
|
||||
}
|
||||
|
||||
QHeaderView {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
QHeaderView::section {
|
||||
border: none;
|
||||
color: #3b3b3b;
|
||||
background-color: white;
|
||||
|
||||
margin-top: 5px; /* XXX: duplicated in css_constants.h */
|
||||
padding: 5px 10px; /* XXX: duplicated in css_constants.h */
|
||||
|
||||
font-size: 16px;
|
||||
line-height: 24px; /* XXX: duplicated in css_constants.h */
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
QScrollBar {
|
||||
width: 5px;
|
||||
border: none;
|
||||
|
@ -43,6 +43,17 @@ namespace QTreeView {
|
||||
}
|
||||
}
|
||||
|
||||
/* In popup.css */
|
||||
namespace PopupCSS {
|
||||
namespace QHeaderView {
|
||||
namespace section {
|
||||
const int marginTop = 5;
|
||||
const int lineHeight = 24;
|
||||
const int paddingVertical = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // CSS_CONSTANTS_H
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include "suggestionlistworker.h"
|
||||
#include "css_constants.h"
|
||||
|
||||
namespace HeaderSectionCSS = CSS::PopupCSS::QHeaderView::section;
|
||||
|
||||
BookmarkButton::BookmarkButton(QWidget *parent) :
|
||||
QToolButton(parent)
|
||||
{
|
||||
@ -81,6 +83,24 @@ SearchBarLineEdit::SearchBarLineEdit(QWidget *parent) :
|
||||
m_suggestionView->setRootIsDecorated(false);
|
||||
m_suggestionView->setStyleSheet(KiwixApp::instance()->parseStyleFromFile(":/css/popup.css"));
|
||||
|
||||
const int contentHeight = HeaderSectionCSS::lineHeight;
|
||||
m_suggestionView->setIconSize(QSize(contentHeight, contentHeight));
|
||||
|
||||
/* The suggestionView sizing unfortunately is not aware of headers. We
|
||||
have to do this manually. We also sized header the same as items.
|
||||
*/
|
||||
connect(&m_suggestionModel, &QAbstractListModel::modelReset, [=](){
|
||||
/* +1 for header. */
|
||||
const int maxItem = m_completer.maxVisibleItems();
|
||||
const int count = std::min(m_suggestionModel.rowCount(), maxItem) + 1;
|
||||
|
||||
const int itemHeight = m_suggestionView->sizeHintForRow(0);
|
||||
|
||||
/* Extra space styling above header and below last suggestion item. */
|
||||
const int extraMargin = 2 * HeaderSectionCSS::marginTop;
|
||||
m_suggestionView->setFixedHeight(itemHeight * count + extraMargin);
|
||||
});
|
||||
|
||||
connect(m_suggestionView->verticalScrollBar(), &QScrollBar::valueChanged,
|
||||
this, &SearchBarLineEdit::onScroll);
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
#include "suggestionlistmodel.h"
|
||||
#include "kiwixapp.h"
|
||||
#include "css_constants.h"
|
||||
|
||||
#include <QIcon>
|
||||
|
||||
namespace HeaderSectionCSS = CSS::PopupCSS::QHeaderView::section;
|
||||
|
||||
QString getZimIdFromUrl(QUrl url);
|
||||
|
||||
SuggestionListModel::SuggestionListModel(QObject *parent)
|
||||
@ -35,10 +38,21 @@ QVariant SuggestionListModel::data(const QModelIndex &index, int role) const
|
||||
case Qt::UserRole:
|
||||
return m_suggestions.at(row).url;
|
||||
case Qt::DecorationRole:
|
||||
{
|
||||
const auto library = KiwixApp::instance()->getLibrary();
|
||||
const auto zimId = getZimIdFromUrl(m_suggestions.at(row).url);
|
||||
return library->getBookIcon(zimId);
|
||||
}
|
||||
case Qt::SizeHintRole:
|
||||
{
|
||||
/* Padding in css can't change height, we have to achieve padding
|
||||
by increasing height.
|
||||
*/
|
||||
const int padding = HeaderSectionCSS::paddingVertical;
|
||||
const int lineHeight = HeaderSectionCSS::lineHeight;
|
||||
return QSize(0, lineHeight + 2 * padding);
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user