From 0e25b116cb7d0c12871ae82331b3477b97f23549 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Sat, 15 Feb 2020 15:25:51 +0100 Subject: [PATCH] SearchBar - Show number of matches found on page search Summary: BUG: 395429 Test Plan: Open searchbar on webpage and type some text which is present on the page Reviewers: #falkon, drosca Reviewed By: #falkon, drosca Subscribers: drosca, falkon Tags: #falkon Differential Revision: https://phabricator.kde.org/D27095 --- src/lib/webtab/searchtoolbar.cpp | 19 +++++++++++++++++++ src/lib/webtab/searchtoolbar.h | 9 +++++++++ src/lib/webtab/searchtoolbar.ui | 7 +++++++ 3 files changed, 35 insertions(+) diff --git a/src/lib/webtab/searchtoolbar.cpp b/src/lib/webtab/searchtoolbar.cpp index bdf1ef0aa..73bcfa2bb 100644 --- a/src/lib/webtab/searchtoolbar.cpp +++ b/src/lib/webtab/searchtoolbar.cpp @@ -38,6 +38,11 @@ SearchToolBar::SearchToolBar(WebView* view, QWidget* parent) ui->next->setShortcut(QKeySequence("Ctrl+G")); ui->previous->setShortcut(QKeySequence("Ctrl+Shift+G")); + ui->resultsInfo->hide(); +#if QTWEBENGINECORE_VERSION >= QT_VERSION_CHECK(5, 14, 0) + connect(view->page(), &QWebEnginePage::findTextFinished, this, &SearchToolBar::showSearchResults); +#endif + connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close())); connect(ui->lineEdit, &QLineEdit::textEdited, this, &SearchToolBar::findNext); connect(ui->next, &QAbstractButton::clicked, this, &SearchToolBar::findNext); @@ -137,6 +142,20 @@ void SearchToolBar::searchText(const QString &text) }); } +#if QTWEBENGINECORE_VERSION >= QT_VERSION_CHECK(5, 14, 0) +void SearchToolBar::showSearchResults(const QWebEngineFindTextResult &result) +{ + if (result.numberOfMatches() == 0) { + ui->resultsInfo->hide(); + return; + } + + ui->resultsInfo->setText(tr("%1 of %2").arg( + QString::number(result.activeMatch()), QString::number(result.numberOfMatches()))); + ui->resultsInfo->show(); +} +#endif + bool SearchToolBar::eventFilter(QObject* obj, QEvent* event) { Q_UNUSED(obj); diff --git a/src/lib/webtab/searchtoolbar.h b/src/lib/webtab/searchtoolbar.h index d018c74c4..b2d4ac231 100644 --- a/src/lib/webtab/searchtoolbar.h +++ b/src/lib/webtab/searchtoolbar.h @@ -19,6 +19,11 @@ #define SEARCHTOOLBAR_H #include +#include + +#if QTWEBENGINECORE_VERSION >= QT_VERSION_CHECK(5, 14, 0) +#include +#endif #include "qzcommon.h" @@ -53,6 +58,10 @@ public Q_SLOTS: void findNext(); void findPrevious(); +#if QTWEBENGINECORE_VERSION >= QT_VERSION_CHECK(5, 14, 0) + void showSearchResults(const QWebEngineFindTextResult &result); +#endif + void close(); private: diff --git a/src/lib/webtab/searchtoolbar.ui b/src/lib/webtab/searchtoolbar.ui index 1c760b6c2..358554b82 100644 --- a/src/lib/webtab/searchtoolbar.ui +++ b/src/lib/webtab/searchtoolbar.ui @@ -94,6 +94,13 @@ + + + + + + +