Messagelib

findbarsourceview.cpp
1/* SPDX-FileCopyrightText: 2011-2024 Laurent Montel <montel@kde.org>
2 *
3 * SPDX-License-Identifier: LGPL-2.0-or-later
4 */
5#include "findbarsourceview.h"
6#include <PimCommon/LineEditWithCompleterNg>
7
8#include <QAction>
9#include <QPlainTextEdit>
10
11using namespace MessageViewer;
12
13FindBarSourceView::FindBarSourceView(QPlainTextEdit *view, QWidget *parent)
14 : WebEngineViewer::FindBarBase(parent)
15 , mView(view)
16{
17}
18
19FindBarSourceView::~FindBarSourceView() = default;
20
21void FindBarSourceView::searchText(bool backward, bool isAutoSearch)
22{
23 QTextDocument::FindFlags searchOptions = {};
24 if (backward) {
25 searchOptions |= QTextDocument::FindBackward;
26 }
27 if (mCaseSensitiveAct->isChecked()) {
29 }
30
31 if (isAutoSearch) {
32 QTextCursor cursor = mView->textCursor();
33 cursor.setPosition(cursor.selectionStart());
34 mView->setTextCursor(cursor);
35 } else if (!mLastSearchStr.contains(mSearch->text(), Qt::CaseSensitive)) {
36 clearSelections();
37 }
38 mLastSearchStr = mSearch->text();
39 const bool found = mView->find(mLastSearchStr, searchOptions);
40
41 setFoundMatch(found);
42}
43
44void FindBarSourceView::clearSelections()
45{
46 QTextCursor textCursor = mView->textCursor();
47 textCursor.clearSelection();
48 textCursor.setPosition(0);
49 mView->setTextCursor(textCursor);
50
51 WebEngineViewer::FindBarBase::clearSelections();
52}
53
54void FindBarSourceView::updateHighLight(bool)
55{
56 clearSelections();
57}
58
59void FindBarSourceView::updateSensitivity(bool)
60{
61 QTextDocument::FindFlags searchOptions = {};
62 if (mCaseSensitiveAct->isChecked()) {
64 }
65 mLastSearchStr = mSearch->text();
66 const bool found = mView->find(mLastSearchStr, searchOptions);
67 setFoundMatch(found);
68}
69
70#include "moc_findbarsourceview.cpp"
bool isChecked() const const
bool find(const QRegularExpression &exp, QTextDocument::FindFlags options)
void setTextCursor(const QTextCursor &cursor)
QTextCursor textCursor() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
CaseSensitive
void clearSelection()
void setPosition(int pos, MoveMode m)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:50:55 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.