Messagelib

findbarwebengineview.cpp
1/* SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
2 *
3 * SPDX-License-Identifier: LGPL-2.0-or-later
4 */
5
6#include "findbarwebengineview.h"
7#include <PimCommon/LineEditWithCompleterNg>
8#include <QAction>
9#include <QWebEngineFindTextResult>
10#include <QWebEngineView>
11using namespace WebEngineViewer;
12
13class WebEngineViewer::FindBarWebEngineViewPrivate
14{
15public:
16 FindBarWebEngineViewPrivate(QWebEngineView *view)
17 : mView(view)
18 {
19 }
20
21 QWebEngineView *const mView;
22};
23
24FindBarWebEngineView::FindBarWebEngineView(QWebEngineView *view, QWidget *parent)
25 : FindBarBase(parent)
26 , d(new WebEngineViewer::FindBarWebEngineViewPrivate(view))
27{
28}
29
30FindBarWebEngineView::~FindBarWebEngineView() = default;
31
32void FindBarWebEngineView::searchText(bool backward, bool isAutoSearch)
33{
34 QWebEnginePage::FindFlags searchOptions;
35
36 if (backward) {
37 searchOptions |= QWebEnginePage::FindBackward;
38 }
39 if (mCaseSensitiveAct->isChecked()) {
40 searchOptions |= QWebEnginePage::FindCaseSensitively;
41 }
42 const QString searchWord(mSearch->text());
43 if (!isAutoSearch && !mLastSearchStr.contains(searchWord, Qt::CaseSensitive)) {
44 clearSelections();
45 }
46 d->mView->findText(QString()); // Clear an existing highlight
47 mLastSearchStr = searchWord;
48 d->mView->findText(mLastSearchStr, searchOptions, [this](const QWebEngineFindTextResult &result) {
49 setFoundMatch(result.numberOfMatches() > 0);
50 });
51}
52
53void FindBarWebEngineView::updateSensitivity(bool sensitivity)
54{
55 QWebEnginePage::FindFlags searchOptions;
56 if (sensitivity) {
57 searchOptions |= QWebEnginePage::FindCaseSensitively;
58 d->mView->findText(QString()); // Clear an existing highlight
59 }
60 d->mView->findText(QString(), searchOptions, [this](const QWebEngineFindTextResult &result) {
61 setFoundMatch(result.numberOfMatches() > 0);
62 });
63}
64
65void FindBarWebEngineView::clearSelections()
66{
67 d->mView->findText(QString());
68 mLastSearchStr.clear();
69 FindBarBase::clearSelections();
70}
71
72#include "moc_findbarwebengineview.cpp"
The FindBarBase class.
Definition findbarbase.h:25
bool isChecked() const const
T qobject_cast(QObject *object)
void clear()
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
CaseSensitive
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:37:31 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.