File indexing completed on 2024-12-22 04:28:13
0001 /* 0002 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "textcustomeditor_export.h" 0010 #include <QTextEdit> 0011 0012 class QContextMenuEvent; 0013 class QMenu; 0014 namespace Sonnet 0015 { 0016 class Highlighter; 0017 class SpellCheckDecorator; 0018 } 0019 namespace TextCustomEditor 0020 { 0021 /** 0022 * @brief The RichTextEditor class 0023 * @author Laurent Montel <montel@kde.org> 0024 */ 0025 class TEXTCUSTOMEDITOR_EXPORT RichTextEditor : public QTextEdit 0026 { 0027 Q_OBJECT 0028 Q_PROPERTY(bool searchSupport READ searchSupport WRITE setSearchSupport) 0029 Q_PROPERTY(bool spellCheckingSupport READ spellCheckingSupport WRITE setSpellCheckingSupport) 0030 Q_PROPERTY(bool textToSpeechSupport READ textToSpeechSupport WRITE setTextToSpeechSupport) 0031 Q_PROPERTY(bool activateLanguageMenu READ activateLanguageMenu WRITE setActivateLanguageMenu) 0032 Q_PROPERTY(bool tabSupport READ allowTabSupport WRITE setAllowTabSupport) 0033 Q_PROPERTY(bool webShortcutSupport READ webShortcutSupport WRITE setWebShortcutSupport) 0034 Q_PROPERTY(bool emojiSupport READ emojiSupport WRITE setEmojiSupport) 0035 public: 0036 explicit RichTextEditor(QWidget *parent = nullptr); 0037 ~RichTextEditor() override; 0038 enum SupportFeature { 0039 None = 0, 0040 Search = 1, 0041 SpellChecking = 2, 0042 TextToSpeech = 4, 0043 AllowTab = 8, 0044 AllowWebShortcut = 16, 0045 Emoji = 32, 0046 }; 0047 Q_DECLARE_FLAGS(SupportFeatures, SupportFeature) 0048 0049 void setSearchSupport(bool b); 0050 [[nodiscard]] bool searchSupport() const; 0051 0052 [[nodiscard]] bool spellCheckingSupport() const; 0053 void setSpellCheckingSupport(bool check); 0054 0055 void setSpellCheckingConfigFileName(const QString &_fileName); 0056 0057 [[nodiscard]] bool checkSpellingEnabled() const; 0058 void setCheckSpellingEnabled(bool check); 0059 0060 void setSpellCheckingLanguage(const QString &_language); 0061 [[nodiscard]] const QString &spellCheckingLanguage() const; 0062 0063 virtual void setReadOnly(bool readOnly); 0064 virtual void createHighlighter(); 0065 0066 [[nodiscard]] bool textToSpeechSupport() const; 0067 void setTextToSpeechSupport(bool b); 0068 [[nodiscard]] Sonnet::Highlighter *highlighter() const; 0069 0070 [[nodiscard]] bool activateLanguageMenu() const; 0071 void setActivateLanguageMenu(bool activate); 0072 0073 void setAllowTabSupport(bool b); 0074 [[nodiscard]] bool allowTabSupport() const; 0075 0076 void setShowAutoCorrectButton(bool b); 0077 [[nodiscard]] bool showAutoCorrectButton() const; 0078 0079 void forceSpellChecking(); 0080 [[nodiscard]] QString spellCheckingConfigFileName() const; 0081 0082 void setWebShortcutSupport(bool b); 0083 [[nodiscard]] bool webShortcutSupport() const; 0084 0085 void addIgnoreWords(const QStringList &lst); 0086 0087 // Reimplement it in subclass 0088 virtual void forceAutoCorrection(bool selectedText = false); 0089 0090 void setDefaultFontSize(int val); 0091 [[nodiscard]] int zoomFactor() const; 0092 void setEmojiSupport(bool b); 0093 [[nodiscard]] bool emojiSupport() const; 0094 0095 public Q_SLOTS: 0096 void slotDisplayMessageIndicator(const QString &message); 0097 void slotSpeakText(); 0098 void slotCheckSpelling(); 0099 void slotZoomReset(); 0100 0101 protected: 0102 virtual void addExtraMenuEntry(QMenu *menu, QPoint pos); 0103 void contextMenuEvent(QContextMenuEvent *event) override; 0104 void focusInEvent(QFocusEvent *event) override; 0105 bool event(QEvent *ev) override; 0106 void keyPressEvent(QKeyEvent *event) override; 0107 void wheelEvent(QWheelEvent *e) override; 0108 0109 QMenu *mousePopupMenu(QPoint pos); 0110 virtual Sonnet::SpellCheckDecorator *createSpellCheckDecorator(); 0111 void setHighlighter(Sonnet::Highlighter *_highLighter); 0112 0113 virtual void updateHighLighter(); 0114 virtual void clearDecorator(); 0115 0116 Q_SIGNALS: 0117 void say(const QString &text); 0118 void findText(); 0119 void replaceText(); 0120 void spellCheckerAutoCorrect(const QString ¤tWord, const QString &autoCorrectWord); 0121 void checkSpellingChanged(bool); 0122 void languageChanged(const QString &); 0123 void spellCheckStatus(const QString &); 0124 void spellCheckingFinished(); 0125 void spellCheckingCanceled(); 0126 0127 private: 0128 TEXTCUSTOMEDITOR_NO_EXPORT void slotUndoableClear(); 0129 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerMisspelling(const QString &text, int pos); 0130 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerCorrected(const QString &, int, const QString &); 0131 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerAutoCorrect(const QString &, const QString &); 0132 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerCanceled(); 0133 TEXTCUSTOMEDITOR_NO_EXPORT void slotSpellCheckerFinished(); 0134 TEXTCUSTOMEDITOR_NO_EXPORT void slotToggleAutoSpellCheck(); 0135 TEXTCUSTOMEDITOR_NO_EXPORT void slotLanguageSelected(); 0136 TEXTCUSTOMEDITOR_NO_EXPORT void slotAllowTab(); 0137 0138 TEXTCUSTOMEDITOR_NO_EXPORT void addIgnoreWordsToHighLighter(); 0139 TEXTCUSTOMEDITOR_NO_EXPORT bool handleShortcut(QKeyEvent *event); 0140 TEXTCUSTOMEDITOR_NO_EXPORT bool overrideShortcut(QKeyEvent *event); 0141 TEXTCUSTOMEDITOR_NO_EXPORT void deleteWordBack(); 0142 TEXTCUSTOMEDITOR_NO_EXPORT void deleteWordForward(); 0143 TEXTCUSTOMEDITOR_NO_EXPORT void highlightWord(int length, int pos); 0144 TEXTCUSTOMEDITOR_NO_EXPORT void checkSpelling(bool force); 0145 TEXTCUSTOMEDITOR_NO_EXPORT void moveLineUpDown(bool moveUp); 0146 TEXTCUSTOMEDITOR_NO_EXPORT void moveCursorBeginUpDown(bool moveUp); 0147 TEXTCUSTOMEDITOR_NO_EXPORT void regenerateColorScheme(); 0148 TEXTCUSTOMEDITOR_NO_EXPORT void updateReadOnlyColor(); 0149 TEXTCUSTOMEDITOR_NO_EXPORT void slotInsertEmoticon(const QString &str); 0150 class RichTextEditorPrivate; 0151 std::unique_ptr<RichTextEditorPrivate> const d; 0152 }; 0153 }