| 1 | /* |
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 2002 Carsten Pfeiffer <pfeiffer@kde.org> |
| 4 | SPDX-FileCopyrightText: 2005 Michael Brade <brade@kde.org> |
| 5 | SPDX-FileCopyrightText: 2012 Laurent Montel <montel@kde.org> |
| 6 | |
| 7 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 8 | */ |
| 9 | |
| 10 | #ifndef KTEXTEDIT_P_H |
| 11 | #define KTEXTEDIT_P_H |
| 12 | |
| 13 | #include "kfind.h" |
| 14 | #include "kfinddialog.h" |
| 15 | #include "kreplace.h" |
| 16 | #include "kreplacedialog.h" |
| 17 | |
| 18 | #include <Sonnet/SpellCheckDecorator> |
| 19 | #include <Sonnet/Speller> |
| 20 | |
| 21 | #include <QSettings> |
| 22 | #include <QTextDocumentFragment> |
| 23 | #ifdef HAVE_SPEECH |
| 24 | #include <QTextToSpeech> |
| 25 | #endif |
| 26 | |
| 27 | class KTextEditPrivate |
| 28 | { |
| 29 | Q_DECLARE_PUBLIC(KTextEdit) |
| 30 | |
| 31 | public: |
| 32 | explicit KTextEditPrivate(KTextEdit *qq) |
| 33 | : q_ptr(qq) |
| 34 | , customPalette(false) |
| 35 | , spellCheckingEnabled(false) |
| 36 | , findReplaceEnabled(true) |
| 37 | , showTabAction(true) |
| 38 | , showAutoCorrectionButton(false) |
| 39 | { |
| 40 | // Check the default sonnet settings to see if spellchecking should be enabled. |
| 41 | QSettings settings(QStringLiteral("KDE" ), QStringLiteral("Sonnet" )); |
| 42 | spellCheckingEnabled = settings.value(QStringLiteral("checkerEnabledByDefault" ), defaultValue: false).toBool(); |
| 43 | } |
| 44 | |
| 45 | virtual ~KTextEditPrivate() |
| 46 | { |
| 47 | delete decorator; |
| 48 | delete findDlg; |
| 49 | delete find; |
| 50 | delete replace; |
| 51 | delete repDlg; |
| 52 | delete speller; |
| 53 | #ifdef HAVE_SPEECH |
| 54 | delete textToSpeech; |
| 55 | #endif |
| 56 | } |
| 57 | |
| 58 | /*! |
| 59 | * Checks whether we should/should not consume a key used as a shortcut. |
| 60 | * This makes it possible to handle shortcuts in the focused widget before any |
| 61 | * window-global QAction is triggered. |
| 62 | */ |
| 63 | bool overrideShortcut(const QKeyEvent *e); |
| 64 | /*! |
| 65 | * Actually handle a shortcut event. |
| 66 | */ |
| 67 | bool handleShortcut(const QKeyEvent *e); |
| 68 | |
| 69 | void spellCheckerMisspelling(const QString &text, int pos); |
| 70 | void spellCheckerCorrected(const QString &, int, const QString &); |
| 71 | void spellCheckerAutoCorrect(const QString &, const QString &); |
| 72 | void spellCheckerCanceled(); |
| 73 | void spellCheckerFinished(); |
| 74 | void toggleAutoSpellCheck(); |
| 75 | |
| 76 | void slotFindHighlight(const QString &text, int matchingIndex, int matchingLength); |
| 77 | void slotReplaceText(const QString &text, int replacementIndex, int /*replacedLength*/, int matchedLength); |
| 78 | |
| 79 | /*! |
| 80 | * Similar to QTextEdit::clear(), only that it is possible to undo this |
| 81 | * action. |
| 82 | */ |
| 83 | void undoableClear(); |
| 84 | |
| 85 | void slotAllowTab(); |
| 86 | void (QAction *action); |
| 87 | |
| 88 | void init(); |
| 89 | |
| 90 | void checkSpelling(bool force); |
| 91 | |
| 92 | KTextEdit *const q_ptr; |
| 93 | QAction *autoSpellCheckAction; |
| 94 | QAction *allowTab; |
| 95 | QAction *spellCheckAction; |
| 96 | QMenu * = nullptr; |
| 97 | bool customPalette : 1; |
| 98 | |
| 99 | bool spellCheckingEnabled : 1; |
| 100 | bool findReplaceEnabled : 1; |
| 101 | bool showTabAction : 1; |
| 102 | bool showAutoCorrectionButton : 1; |
| 103 | QTextDocumentFragment originalDoc; |
| 104 | QString spellCheckingLanguage; |
| 105 | Sonnet::SpellCheckDecorator *decorator = nullptr; |
| 106 | Sonnet::Speller *speller = nullptr; |
| 107 | KFindDialog *findDlg = nullptr; |
| 108 | KFind *find = nullptr; |
| 109 | KReplaceDialog *repDlg = nullptr; |
| 110 | KReplace *replace = nullptr; |
| 111 | #ifdef HAVE_SPEECH |
| 112 | QTextToSpeech *textToSpeech = nullptr; |
| 113 | #endif |
| 114 | |
| 115 | int findIndex = 0; |
| 116 | int repIndex = 0; |
| 117 | int lastReplacedPosition = -1; |
| 118 | }; |
| 119 | |
| 120 | #endif |
| 121 | |