Messagelib

findbarwebengineview.cpp
1 /* SPDX-FileCopyrightText: 2016-2021 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 
11 using namespace WebEngineViewer;
12 
13 class WebEngineViewer::FindBarWebEngineViewPrivate
14 {
15 public:
16  FindBarWebEngineViewPrivate(QWebEngineView *view)
17  : mView(view)
18  {
19  }
20 
21  QWebEngineView *const mView;
22 };
23 
24 FindBarWebEngineView::FindBarWebEngineView(QWebEngineView *view, QWidget *parent)
25  : FindBarBase(parent)
26  , d(new WebEngineViewer::FindBarWebEngineViewPrivate(view))
27 {
28 }
29 
30 FindBarWebEngineView::~FindBarWebEngineView() = default;
31 
32 void 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](bool found) {
49  setFoundMatch(found);
50  });
51 }
52 
53 void 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](bool found) {
61  setFoundMatch(found);
62  });
63 }
64 
65 void FindBarWebEngineView::clearSelections()
66 {
67  d->mView->findText(QString());
68  mLastSearchStr.clear();
69  FindBarBase::clearSelections();
70 }
bool isChecked() const const
void clear()
CaseSensitive
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
The FindBarBase class.
Definition: findbarbase.h:24
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Dec 6 2021 23:04:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.