KTextAddons

richtextbrowserfindbar.cpp
1/*
2 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "richtextbrowserfindbar.h"
8#include "widgets/findutils.h"
9#include "widgets/textfindreplacewidget.h"
10
11#include <KLocalizedString>
12#include <TextUtils/ConvertText>
13
14#include <QRegularExpression>
15#include <QTextBrowser>
16
17using namespace TextCustomEditor;
18class Q_DECL_HIDDEN TextCustomEditor::RichTextBrowserFindBarPrivate
19{
20public:
21 RichTextBrowserFindBarPrivate(QTextBrowser *view)
22 : mView(view)
23 {
24 }
25
26 QTextBrowser *const mView;
27};
28
29RichTextBrowserFindBar::RichTextBrowserFindBar(QTextBrowser *view, QWidget *parent)
30 : TextEditFindBarBase(parent)
31 , d(new TextCustomEditor::RichTextBrowserFindBarPrivate(view))
32{
33}
34
35RichTextBrowserFindBar::~RichTextBrowserFindBar() = default;
36
37void RichTextBrowserFindBar::slotSearchText(bool backward, bool isAutoSearch)
38{
39 d->mView->moveCursor(QTextCursor::Start);
40 searchText(backward, isAutoSearch);
41}
42
43bool RichTextBrowserFindBar::viewIsReadOnly() const
44{
45 return true;
46}
47
48bool RichTextBrowserFindBar::documentIsEmpty() const
49{
50 return d->mView->document()->isEmpty();
51}
52
53bool RichTextBrowserFindBar::searchInDocument(const QString &text, TextEditFindBarBase::FindFlags searchOptions)
54{
55 bool found = false;
56 if (searchOptions & TextEditFindBarBase::FindRespectDiacritics) {
57 found = d->mView->find(text, FindUtils::convertTextEditFindFlags(searchOptions));
58 } else {
59 found = FindUtils::find(d->mView, text, FindUtils::convertTextEditFindFlags(searchOptions));
60 }
61 mFindWidget->setFoundMatch(found);
62 return found;
63}
64
65bool RichTextBrowserFindBar::searchInDocument(const QRegularExpression &regExp, TextEditFindBarBase::FindFlags searchOptions)
66{
67 const bool found = d->mView->find(regExp, FindUtils::convertTextEditFindFlags(searchOptions));
68 mFindWidget->setFoundMatch(found);
69 return found;
70}
71
72void RichTextBrowserFindBar::autoSearchMoveCursor()
73{
74 QTextCursor cursor = d->mView->textCursor();
75 cursor.setPosition(cursor.selectionStart());
76 d->mView->setTextCursor(cursor);
77}
78
79void RichTextBrowserFindBar::slotReplaceText()
80{
81 // Nothing as readonly
82}
83
84void RichTextBrowserFindBar::slotReplaceAllText()
85{
86 // Nothing as readonly
87}
88
89#include "moc_richtextbrowserfindbar.cpp"
The TextEditFindBarBase class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 27 2024 11:48:28 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.