KTextAddons

richtexteditor.h
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "textcustomeditor_export.h"
10#include <QTextEdit>
11
13class QMenu;
14namespace Sonnet
15{
16class Highlighter;
17class SpellCheckDecorator;
18}
19namespace TextCustomEditor
20{
21/**
22 * @brief The RichTextEditor class
23 * @author Laurent Montel <montel@kde.org>
24 */
25class TEXTCUSTOMEDITOR_EXPORT RichTextEditor : public QTextEdit
26{
27 Q_OBJECT
28 Q_PROPERTY(bool searchSupport READ searchSupport WRITE setSearchSupport)
29 Q_PROPERTY(bool spellCheckingSupport READ spellCheckingSupport WRITE setSpellCheckingSupport)
30 Q_PROPERTY(bool textToSpeechSupport READ textToSpeechSupport WRITE setTextToSpeechSupport)
31 Q_PROPERTY(bool activateLanguageMenu READ activateLanguageMenu WRITE setActivateLanguageMenu)
32 Q_PROPERTY(bool tabSupport READ allowTabSupport WRITE setAllowTabSupport)
33 Q_PROPERTY(bool webShortcutSupport READ webShortcutSupport WRITE setWebShortcutSupport)
34 Q_PROPERTY(bool emojiSupport READ emojiSupport WRITE setEmojiSupport)
35public:
36 explicit RichTextEditor(QWidget *parent = nullptr);
37 ~RichTextEditor() override;
38 enum SupportFeature {
39 None = 0,
40 Search = 1,
41 SpellChecking = 2,
42 TextToSpeech = 4,
43 AllowTab = 8,
44 AllowWebShortcut = 16,
45 Emoji = 32,
46 };
47 Q_DECLARE_FLAGS(SupportFeatures, SupportFeature)
48
49 void setSearchSupport(bool b);
50 [[nodiscard]] bool searchSupport() const;
51
52 [[nodiscard]] bool spellCheckingSupport() const;
53 void setSpellCheckingSupport(bool check);
54
55 void setSpellCheckingConfigFileName(const QString &_fileName);
56
57 [[nodiscard]] bool checkSpellingEnabled() const;
58 void setCheckSpellingEnabled(bool check);
59
60 void setSpellCheckingLanguage(const QString &_language);
61 [[nodiscard]] const QString &spellCheckingLanguage() const;
62
63 virtual void setReadOnly(bool readOnly);
64 virtual void createHighlighter();
65
66 [[nodiscard]] bool textToSpeechSupport() const;
67 void setTextToSpeechSupport(bool b);
68 [[nodiscard]] Sonnet::Highlighter *highlighter() const;
69
70 [[nodiscard]] bool activateLanguageMenu() const;
71 void setActivateLanguageMenu(bool activate);
72
73 void setAllowTabSupport(bool b);
74 [[nodiscard]] bool allowTabSupport() const;
75
76 void setShowAutoCorrectButton(bool b);
77 [[nodiscard]] bool showAutoCorrectButton() const;
78
79 void forceSpellChecking();
80 [[nodiscard]] QString spellCheckingConfigFileName() const;
81
82 void setWebShortcutSupport(bool b);
83 [[nodiscard]] bool webShortcutSupport() const;
84
85 void addIgnoreWords(const QStringList &lst);
86
87 // Reimplement it in subclass
88 virtual void forceAutoCorrection(bool selectedText = false);
89
90 void setDefaultFontSize(int val);
91 [[nodiscard]] int zoomFactor() const;
92 void setEmojiSupport(bool b);
93 [[nodiscard]] bool emojiSupport() const;
94
95public Q_SLOTS:
96 void slotDisplayMessageIndicator(const QString &message);
97 void slotSpeakText();
98 void slotCheckSpelling();
99 void slotZoomReset();
100
101protected:
102 virtual void addExtraMenuEntry(QMenu *menu, QPoint pos);
103 void contextMenuEvent(QContextMenuEvent *event) override;
104 void focusInEvent(QFocusEvent *event) override;
105 [[nodiscard]] bool event(QEvent *ev) override;
106 void keyPressEvent(QKeyEvent *event) override;
107 void wheelEvent(QWheelEvent *e) override;
108
109 QMenu *mousePopupMenu(QPoint pos);
110 virtual Sonnet::SpellCheckDecorator *createSpellCheckDecorator();
111 void setHighlighter(Sonnet::Highlighter *_highLighter);
112
113 virtual void updateHighLighter();
114 virtual void clearDecorator();
115
116Q_SIGNALS:
117 void say(const QString &text);
118 void findText();
119 void replaceText();
120 void spellCheckerAutoCorrect(const QString &currentWord, const QString &autoCorrectWord);
121 void checkSpellingChanged(bool);
122 void languageChanged(const QString &);
123 void spellCheckStatus(const QString &);
124 void spellCheckingFinished();
125 void spellCheckingCanceled();
126
127private:
128 TEXTCUSTOMEDITOR_NO_EXPORT void slotUndoableClear();
129 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerMisspelling(const QString &text, int pos);
130 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerCorrected(const QString &, int, const QString &);
131 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerAutoCorrect(const QString &, const QString &);
132 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerCanceled();
133 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerFinished();
134 TEXTCUSTOMEDITOR_NO_EXPORT void slotToggleAutoSpellCheck();
135 TEXTCUSTOMEDITOR_NO_EXPORT void slotLanguageSelected();
136 TEXTCUSTOMEDITOR_NO_EXPORT void slotAllowTab();
137
138 TEXTCUSTOMEDITOR_NO_EXPORT void addIgnoreWordsToHighLighter();
139 TEXTCUSTOMEDITOR_NO_EXPORT bool handleShortcut(QKeyEvent *event);
140 TEXTCUSTOMEDITOR_NO_EXPORT bool overrideShortcut(QKeyEvent *event);
141 TEXTCUSTOMEDITOR_NO_EXPORT void deleteWordBack();
142 TEXTCUSTOMEDITOR_NO_EXPORT void deleteWordForward();
143 TEXTCUSTOMEDITOR_NO_EXPORT void highlightWord(int length, int pos);
144 TEXTCUSTOMEDITOR_NO_EXPORT void checkSpelling(bool force);
145 TEXTCUSTOMEDITOR_NO_EXPORT void moveLineUpDown(bool moveUp);
146 TEXTCUSTOMEDITOR_NO_EXPORT void moveCursorBeginUpDown(bool moveUp);
147 TEXTCUSTOMEDITOR_NO_EXPORT void regenerateColorScheme();
148 TEXTCUSTOMEDITOR_NO_EXPORT void updateReadOnlyColor();
149 TEXTCUSTOMEDITOR_NO_EXPORT void slotInsertEmoticon(const QString &str);
150 class RichTextEditorPrivate;
151 std::unique_ptr<RichTextEditorPrivate> const d;
152};
153}
The RichTextEditor class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:51:15 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.