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

KDE's Doxygen guidelines are available online.