KTextAddons

plaintexteditor.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
11#include <QPlainTextEdit>
12
13namespace Sonnet
14{
15class Highlighter;
16class SpellCheckDecorator;
17}
18namespace TextCustomEditor
19{
20/**
21 * @brief The PlainTextEditor class
22 * @author Laurent Montel <montel@kde.org>
23 */
24class TEXTCUSTOMEDITOR_EXPORT PlainTextEditor : public QPlainTextEdit
25{
26 Q_OBJECT
27 Q_PROPERTY(bool searchSupport READ searchSupport WRITE setSearchSupport)
28 Q_PROPERTY(bool spellCheckingSupport READ spellCheckingSupport WRITE setSpellCheckingSupport)
29 Q_PROPERTY(bool textToSpeechSupport READ textToSpeechSupport WRITE setTextToSpeechSupport)
30 Q_PROPERTY(bool webShortcutSupport READ webShortcutSupport WRITE setWebShortcutSupport)
31 Q_PROPERTY(bool emojiSupport READ emojiSupport WRITE setEmojiSupport)
32public:
33 explicit PlainTextEditor(QWidget *parent = nullptr);
34 ~PlainTextEditor() override;
35
36 enum SupportFeature {
37 None = 0,
38 Search = 1,
39 SpellChecking = 2,
40 TextToSpeech = 4,
41 AllowWebShortcut = 8,
42 Emoji = 16,
43 };
44 Q_DECLARE_FLAGS(SupportFeatures, SupportFeature)
45
46 void setSearchSupport(bool b);
47 [[nodiscard]] bool searchSupport() const;
48
49 [[nodiscard]] bool spellCheckingSupport() const;
50 void setSpellCheckingSupport(bool check);
51
52 virtual void setReadOnly(bool readOnly);
53
54 void setTextToSpeechSupport(bool b);
55 [[nodiscard]] bool textToSpeechSupport() const;
56
57 void setWebShortcutSupport(bool b);
58 [[nodiscard]] bool webShortcutSupport() const;
59
60 virtual void createHighlighter();
61
62 void addIgnoreWords(const QStringList &lst);
63 [[nodiscard]] bool activateLanguageMenu() const;
64 void setActivateLanguageMenu(bool activate);
65 [[nodiscard]] Sonnet::Highlighter *highlighter() const;
66 [[nodiscard]] bool checkSpellingEnabled() const;
67 void setCheckSpellingEnabled(bool check);
68 void setSpellCheckingConfigFileName(const QString &_fileName);
69 [[nodiscard]] QString spellCheckingConfigFileName() const;
70 [[nodiscard]] const QString &spellCheckingLanguage() const;
71 void setSpellCheckingLanguage(const QString &_language);
72
73 void setEmojiSupport(bool b);
74 [[nodiscard]] bool emojiSupport() const;
75
76public Q_SLOTS:
77 void slotDisplayMessageIndicator(const QString &message);
78 void slotCheckSpelling();
79 void slotSpeakText();
80 void slotZoomReset();
81
82protected:
83 virtual void addExtraMenuEntry(QMenu *menu, QPoint pos);
84 void contextMenuEvent(QContextMenuEvent *event) override;
85 [[nodiscard]] bool event(QEvent *ev) override;
86 void keyPressEvent(QKeyEvent *event) override;
87 [[nodiscard]] bool overrideShortcut(QKeyEvent *event);
88 [[nodiscard]] bool handleShortcut(QKeyEvent *event);
89 void wheelEvent(QWheelEvent *event) override;
90
91 virtual Sonnet::SpellCheckDecorator *createSpellCheckDecorator();
92 void setHighlighter(Sonnet::Highlighter *_highLighter);
93 void focusInEvent(QFocusEvent *event) override;
94 virtual void updateHighLighter();
95 virtual void clearDecorator();
96
97Q_SIGNALS:
98 void findText();
99 void replaceText();
100 void spellCheckerAutoCorrect(const QString &currentWord, const QString &autoCorrectWord);
101 void checkSpellingChanged(bool);
102 void languageChanged(const QString &);
103 void spellCheckStatus(const QString &);
104 void say(const QString &text);
105
106private:
107 TEXTCUSTOMEDITOR_NO_EXPORT void slotUndoableClear();
108 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerMisspelling(const QString &text, int pos);
109 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerCorrected(const QString &, int, const QString &);
110 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerAutoCorrect(const QString &, const QString &);
111 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerCanceled();
112 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerFinished();
113
114 TEXTCUSTOMEDITOR_NO_EXPORT void slotLanguageSelected();
115 TEXTCUSTOMEDITOR_NO_EXPORT void slotToggleAutoSpellCheck();
116 TEXTCUSTOMEDITOR_NO_EXPORT void addIgnoreWordsToHighLighter();
117 TEXTCUSTOMEDITOR_NO_EXPORT void deleteWordBack();
118 TEXTCUSTOMEDITOR_NO_EXPORT void deleteWordForward();
119 TEXTCUSTOMEDITOR_NO_EXPORT void highlightWord(int length, int pos);
120 TEXTCUSTOMEDITOR_NO_EXPORT void deleteEndOfLine();
121 TEXTCUSTOMEDITOR_NO_EXPORT void moveLineUpDown(bool moveUp);
122 TEXTCUSTOMEDITOR_NO_EXPORT void moveCursorBeginUpDown(bool moveUp);
123 TEXTCUSTOMEDITOR_NO_EXPORT void regenerateColorScheme();
124 TEXTCUSTOMEDITOR_NO_EXPORT void updateReadOnlyColor();
125 TEXTCUSTOMEDITOR_NO_EXPORT void slotInsertEmoticon(const QString &str);
126 class PlainTextEditorPrivate;
127 std::unique_ptr<PlainTextEditorPrivate> const d;
128};
129}
The PlainTextEditor class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:29:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.