Messagelib

findbarwebengineview.cpp
1 /* SPDX-FileCopyrightText: 2016-2023 Laurent Montel <[email protected]>
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 <QWebEngineView>
10 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
11 #include <QWebEngineFindTextResult>
12 #endif
13 using namespace WebEngineViewer;
14 
15 class WebEngineViewer::FindBarWebEngineViewPrivate
16 {
17 public:
18  FindBarWebEngineViewPrivate(QWebEngineView *view)
19  : mView(view)
20  {
21  }
22 
23  QWebEngineView *const mView;
24 };
25 
26 FindBarWebEngineView::FindBarWebEngineView(QWebEngineView *view, QWidget *parent)
27  : FindBarBase(parent)
28  , d(new WebEngineViewer::FindBarWebEngineViewPrivate(view))
29 {
30 }
31 
32 FindBarWebEngineView::~FindBarWebEngineView() = default;
33 
34 void FindBarWebEngineView::searchText(bool backward, bool isAutoSearch)
35 {
36  QWebEnginePage::FindFlags searchOptions;
37 
38  if (backward) {
39  searchOptions |= QWebEnginePage::FindBackward;
40  }
41  if (mCaseSensitiveAct->isChecked()) {
42  searchOptions |= QWebEnginePage::FindCaseSensitively;
43  }
44  const QString searchWord(mSearch->text());
45  if (!isAutoSearch && !mLastSearchStr.contains(searchWord, Qt::CaseSensitive)) {
46  clearSelections();
47  }
48  d->mView->findText(QString()); // Clear an existing highlight
49  mLastSearchStr = searchWord;
50 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
51  d->mView->findText(mLastSearchStr, searchOptions, [this](const QWebEngineFindTextResult &result) {
52  setFoundMatch(result.numberOfMatches() > 0);
53  });
54 #else
55  d->mView->findText(mLastSearchStr, searchOptions, [this](bool found) {
56  setFoundMatch(found);
57  });
58 #endif
59 }
60 
61 void FindBarWebEngineView::updateSensitivity(bool sensitivity)
62 {
63  QWebEnginePage::FindFlags searchOptions;
64  if (sensitivity) {
65  searchOptions |= QWebEnginePage::FindCaseSensitively;
66  d->mView->findText(QString()); // Clear an existing highlight
67  }
68 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
69  d->mView->findText(QString(), searchOptions, [this](const QWebEngineFindTextResult &result) {
70  setFoundMatch(result.numberOfMatches() > 0);
71  });
72 #else
73  d->mView->findText(QString(), searchOptions, [this](bool found) {
74  setFoundMatch(found);
75  });
76 #endif
77 }
78 
79 void FindBarWebEngineView::clearSelections()
80 {
81  d->mView->findText(QString());
82  mLastSearchStr.clear();
83  FindBarBase::clearSelections();
84 }
CaseSensitive
The FindBarBase class.
Definition: findbarbase.h:24
void clear()
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isChecked() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Mar 24 2023 04:08:31 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.