mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 11:37:56 -04:00
Merge pull request #166 from kiwix/open-article-enter
Auto completion search bar
This commit is contained in:
commit
8cdfe50033
@ -62,15 +62,11 @@ SearchBar::SearchBar(QWidget *parent) :
|
||||
{
|
||||
setPlaceholderText(tr("Search"));
|
||||
m_completer.setCompletionMode(QCompleter::UnfilteredPopupCompletion);
|
||||
m_completer.setCaseSensitivity(Qt::CaseInsensitive);
|
||||
setCompleter(&m_completer);
|
||||
connect(this, &QLineEdit::textEdited, this, &SearchBar::updateCompletion);
|
||||
#if 0 //The `activated` signal seems to not be emitted if user navigate in the page.
|
||||
// Something is broken here .. :/
|
||||
connect(&m_completer, QOverload<const QModelIndex &>::of(&QCompleter::activated),
|
||||
this, &SearchBar::openCompletion);
|
||||
#else
|
||||
connect(this, &QLineEdit::returnPressed, this, &SearchBar::openTitle);
|
||||
#endif
|
||||
connect(KiwixApp::instance(), &KiwixApp::currentTitleChanged,
|
||||
this, &SearchBar::on_currentTitleChanged);
|
||||
}
|
||||
@ -115,33 +111,6 @@ void SearchBar::updateCompletion(const QString &text)
|
||||
m_completionModel.setStringList(wordList);
|
||||
}
|
||||
|
||||
void SearchBar::openTitle()
|
||||
{
|
||||
QString title = text();
|
||||
clear();
|
||||
auto tabWidget = KiwixApp::instance()->getTabWidget();
|
||||
auto zimId = tabWidget->currentZimId();
|
||||
auto reader = KiwixApp::instance()->getLibrary()->getReader(zimId);
|
||||
if ( reader == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::string path;
|
||||
try {
|
||||
auto entry = reader->getEntryFromTitle(title.toStdString());
|
||||
path = entry.getPath();
|
||||
} catch (kiwix::NoEntry& e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QUrl qurl;
|
||||
qurl.setScheme("zim");
|
||||
qurl.setHost(zimId+".zim");
|
||||
qurl.setPath("/" + QString::fromStdString(path));
|
||||
QTimer::singleShot(0, [=](){KiwixApp::instance()->openUrl(qurl, false);});
|
||||
clearFocus();
|
||||
}
|
||||
|
||||
void SearchBar::openCompletion(const QModelIndex &index)
|
||||
{
|
||||
auto url = m_urlList.at(index.row());
|
||||
|
@ -40,7 +40,6 @@ private:
|
||||
private slots:
|
||||
void updateCompletion(const QString& text);
|
||||
void openCompletion(const QModelIndex& index);
|
||||
void openTitle();
|
||||
};
|
||||
|
||||
#endif // SEARCHBAR_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user