From 18d123bcfbbb8ae6b7de68061d10fb191cbf9fe2 Mon Sep 17 00:00:00 2001 From: luddens Date: Tue, 28 May 2019 17:34:25 +0200 Subject: [PATCH 1/2] Set the completer case insensitive Set the completer case insensitive to match with the suggestion's list --- src/searchbar.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/searchbar.cpp b/src/searchbar.cpp index bc330bd..3676bd3 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -62,6 +62,7 @@ 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. From c8ace2fb7eeb368dce3734356fe072a4bb414dc6 Mon Sep 17 00:00:00 2001 From: luddens Date: Tue, 11 Jun 2019 13:43:08 +0200 Subject: [PATCH 2/2] re-use openCompletion method Re-use the connect with openCompletion method that works fine to handle mouse click and enter key press to open article Remove the openTitle method that is no longer usefull. --- src/searchbar.cpp | 32 -------------------------------- src/searchbar.h | 1 - 2 files changed, 33 deletions(-) diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 3676bd3..0bfbf81 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -65,13 +65,8 @@ SearchBar::SearchBar(QWidget *parent) : 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::of(&QCompleter::activated), this, &SearchBar::openCompletion); -#else - connect(this, &QLineEdit::returnPressed, this, &SearchBar::openTitle); -#endif connect(KiwixApp::instance(), &KiwixApp::currentTitleChanged, this, &SearchBar::on_currentTitleChanged); } @@ -116,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()); diff --git a/src/searchbar.h b/src/searchbar.h index 21372ff..dfa99e3 100644 --- a/src/searchbar.h +++ b/src/searchbar.h @@ -40,7 +40,6 @@ private: private slots: void updateCompletion(const QString& text); void openCompletion(const QModelIndex& index); - void openTitle(); }; #endif // SEARCHBAR_H