Libksieve

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 KSieveUi;
12
13class KSieveUi::FindBarWebEngineViewPrivate
14{
15public:
16 FindBarWebEngineViewPrivate() = default;
17
18 QWebEngineView *mView = nullptr;
19};
20
21FindBarWebEngineView::FindBarWebEngineView(QWebEngineView *view, QWidget *parent)
22 : FindBarBase(parent)
23 , d(new KSieveUi::FindBarWebEngineViewPrivate)
24{
25 d->mView = view;
26}
27
28FindBarWebEngineView::~FindBarWebEngineView() = default;
29
30void FindBarWebEngineView::searchText(bool backward, bool isAutoSearch)
31{
32 QWebEnginePage::FindFlags searchOptions;
33
34 if (backward) {
35 searchOptions |= QWebEnginePage::FindBackward;
36 }
37 if (mCaseSensitiveAct->isChecked()) {
38 searchOptions |= QWebEnginePage::FindCaseSensitively;
39 }
40 const QString searchWord(mSearch->text());
41 if (!isAutoSearch && !mLastSearchStr.contains(searchWord, Qt::CaseSensitive)) {
42 clearSelections();
43 }
44 d->mView->findText(QString()); // Clear an existing highlight
45 mLastSearchStr = searchWord;
46 d->mView->findText(mLastSearchStr, searchOptions, [this](const QWebEngineFindTextResult &result) {
47 setFoundMatch(result.numberOfMatches() > 0);
48 });
49}
50
51void FindBarWebEngineView::updateSensitivity(bool sensitivity)
52{
53 QWebEnginePage::FindFlags searchOptions;
54 if (sensitivity) {
55 searchOptions |= QWebEnginePage::FindCaseSensitively;
56 d->mView->findText(QString()); // Clear an existing highligh
57 }
58 d->mView->findText(QString(), searchOptions, [this](const QWebEngineFindTextResult &result) {
59 setFoundMatch(result.numberOfMatches() > 0);
60 });
61}
62
63void FindBarWebEngineView::clearSelections()
64{
65 d->mView->findText(QString());
66 mLastSearchStr.clear();
67 FindBarBase::clearSelections();
68}
69
70#include "moc_findbarwebengineview.cpp"
bool isChecked() const const
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 Mon Nov 18 2024 12:14:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.