Messagelib

findbarsourceview.cpp
1 /* SPDX-FileCopyrightText: 2011-2021 Laurent Montel <[email protected]>
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 
11 using namespace MessageViewer;
12 
13 FindBarSourceView::FindBarSourceView(QPlainTextEdit *view, QWidget *parent)
14  : WebEngineViewer::FindBarBase(parent)
15  , mView(view)
16 {
17 }
18 
19 FindBarSourceView::~FindBarSourceView() = default;
20 
21 void FindBarSourceView::searchText(bool backward, bool isAutoSearch)
22 {
23  QTextDocument::FindFlags searchOptions = {};
24  if (backward) {
25  searchOptions |= QTextDocument::FindBackward;
26  }
27  if (mCaseSensitiveAct->isChecked()) {
28  searchOptions |= QTextDocument::FindCaseSensitively;
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 
44 void 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 
54 void FindBarSourceView::updateHighLight(bool)
55 {
56  clearSelections();
57 }
58 
59 void FindBarSourceView::updateSensitivity(bool)
60 {
61  QTextDocument::FindFlags searchOptions = {};
62  if (mCaseSensitiveAct->isChecked()) {
63  searchOptions |= QTextDocument::FindCaseSensitively;
64  }
65  mLastSearchStr = mSearch->text();
66  const bool found = mView->find(mLastSearchStr, searchOptions);
67  setFoundMatch(found);
68 }
QCursor cursor() const const
void clearSelection()
bool isChecked() const const
int selectionStart() const const
CaseSensitive
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
typedef FindFlags
void setPosition(int pos, QTextCursor::MoveMode m)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Dec 4 2021 23:12:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.