1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

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
This commit is contained in:
Juraj Oravec 2020-02-15 15:25:51 +01:00
parent e0ea9fd04c
commit 0e25b116cb
3 changed files with 35 additions and 0 deletions

View File

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

View File

@ -19,6 +19,11 @@
#define SEARCHTOOLBAR_H
#include <QWebEnginePage>
#include <QtWebEngineCoreVersion>
#if QTWEBENGINECORE_VERSION >= QT_VERSION_CHECK(5, 14, 0)
#include <QWebEngineFindTextResult>
#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:

View File

@ -94,6 +94,13 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="resultsInfo">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>