Introduce Kiwix Search Header

This commit is contained in:
ShaopengLin 2024-09-17 01:19:28 -04:00
parent 951917f14d
commit ff50e9d870
6 changed files with 31 additions and 3 deletions

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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);

View File

@ -12,6 +12,8 @@
#include <QToolBar>
#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;

View File

@ -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();

View File

@ -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<SuggestionData>& suggestionList);