Merge pull request #166 from kiwix/open-article-enter

Auto completion search bar
This commit is contained in:
Matthieu Gautier 2019-06-12 10:06:13 +02:00 committed by GitHub
commit 8cdfe50033
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 33 deletions

View File

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

View File

@ -40,7 +40,6 @@ private:
private slots:
void updateCompletion(const QString& text);
void openCompletion(const QModelIndex& index);
void openTitle();
};
#endif // SEARCHBAR_H