diff --git a/resources/i18n/en.json b/resources/i18n/en.json index 3d1690c..9dfc1d6 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -171,5 +171,6 @@ "save-page-as": "Save As...", "portable-disabled-tooltip": "Function disabled in portable mode", "scroll-next-tab": "Scroll to next tab", - "scroll-previous-tab": "Scroll to previous tab" + "scroll-previous-tab": "Scroll to previous tab", + "kiwix-search": "Kiwix search" } diff --git a/resources/i18n/qqq.json b/resources/i18n/qqq.json index e45891b..55846a1 100644 --- a/resources/i18n/qqq.json +++ b/resources/i18n/qqq.json @@ -179,5 +179,6 @@ "save-page-as": "Represents the action of saving the current tab content to a file chosen by the user.", "portable-disabled-tooltip": "Tooltip used to explain disabled components in the portable version.", "scroll-next-tab": "Represents the action of scrolling to the next tab of the current tab which toward the end of the tab bar.", - "scroll-previous-tab": "Represents the action of scrolling to the previous tab of the current tab which toward the start of the tab bar." + "scroll-previous-tab": "Represents the action of scrolling to the previous tab of the current tab which toward the start of the tab bar.", + "kiwix-search": "Title text for a list of search results, which notes to the user those are from Kiwix's Search Engine" } diff --git a/src/searchbar.cpp b/src/searchbar.cpp index f9af121..c544dda 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -50,6 +50,7 @@ void BookmarkButton::on_buttonClicked() SearchBarLineEdit::SearchBarLineEdit(QWidget *parent) : QLineEdit(parent), + m_suggestionView(new QTreeView), m_completer(&m_suggestionModel, this) { installEventFilter(this); @@ -72,7 +73,13 @@ SearchBarLineEdit::SearchBarLineEdit(QWidget *parent) : m_completer.setMaxVisibleItems(SuggestionListWorker::getFetchSize() / 2); setCompleter(&m_completer); - m_completer.popup()->setStyleSheet(KiwixApp::instance()->parseStyleFromFile(":/css/popup.css")); + /* QCompleter's uses default list views, which do not have headers. */ + m_completer.setPopup(m_suggestionView); + + m_suggestionView->header()->setStretchLastSection(true); + m_suggestionView->setRootIsDecorated(false); + m_suggestionView->setStyleSheet(KiwixApp::instance()->parseStyleFromFile(":/css/popup.css")); + connect(m_completer.popup()->verticalScrollBar(), &QScrollBar::valueChanged, this, &SearchBarLineEdit::onScroll); diff --git a/src/searchbar.h b/src/searchbar.h index 52a865e..b759830 100644 --- a/src/searchbar.h +++ b/src/searchbar.h @@ -12,6 +12,8 @@ #include #include "suggestionlistmodel.h" +class QTreeView; + class BookmarkButton : public QToolButton { Q_OBJECT public: @@ -42,6 +44,7 @@ protected: virtual void focusOutEvent(QFocusEvent *); private: SuggestionListModel m_suggestionModel; + QTreeView *m_suggestionView; QCompleter m_completer; QString m_title; QString m_searchbarInput; diff --git a/src/suggestionlistmodel.cpp b/src/suggestionlistmodel.cpp index de1be9b..6fe99da 100644 --- a/src/suggestionlistmodel.cpp +++ b/src/suggestionlistmodel.cpp @@ -42,6 +42,21 @@ QVariant SuggestionListModel::data(const QModelIndex &index, int role) const return QVariant(); } +QVariant SuggestionListModel::headerData(int section, + Qt::Orientation orientation, + int role) const +{ + if (section != 0 || orientation != Qt::Orientation::Horizontal) + return QVariant(); + + switch (role) + { + case Qt::DisplayRole: + return gt("kiwix-search"); + } + return QVariant(); +} + void SuggestionListModel::resetSuggestions() { beginResetModel(); diff --git a/src/suggestionlistmodel.h b/src/suggestionlistmodel.h index 047708d..0115461 100644 --- a/src/suggestionlistmodel.h +++ b/src/suggestionlistmodel.h @@ -22,6 +22,7 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; void resetSuggestions(); void append(const QList& suggestionList);