1 | /* |
2 | SPDX-FileCopyrightText: 2003 Zack Rusin <zack@kde.org> |
3 | SPDX-FileCopyrightText: 2009-2010 Michel Ludwig <michel.ludwig@kdemail.net> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef SPELLCHECK_BAR_H |
9 | #define SPELLCHECK_BAR_H |
10 | |
11 | #include "kateviewhelpers.h" |
12 | |
13 | class QListWidgetItem; |
14 | class QModelIndex; |
15 | |
16 | namespace Sonnet |
17 | { |
18 | class BackgroundChecker; |
19 | } |
20 | |
21 | /** |
22 | * @short Spellcheck dialog |
23 | * |
24 | * \code |
25 | * Sonnet::SpellCheckBar dlg = new Sonnet::SpellCheckBar( |
26 | * new Sonnet::BackgroundChecker(this), this); |
27 | * //connect signals |
28 | * ... |
29 | * dlg->setBuffer( someText ); |
30 | * dlg->show(); |
31 | * \endcode |
32 | * |
33 | * You can change buffer inside a slot connected to done() signal |
34 | * and spellcheck will continue with new data automatically. |
35 | */ |
36 | class SpellCheckBar : public KateViewBarWidget |
37 | { |
38 | Q_OBJECT |
39 | public: |
40 | SpellCheckBar(Sonnet::BackgroundChecker *checker, QWidget *parent); |
41 | ~SpellCheckBar() override; |
42 | |
43 | QString originalBuffer() const; |
44 | QString buffer() const; |
45 | |
46 | void closed() override; |
47 | |
48 | void show(); |
49 | void activeAutoCorrect(bool _active); |
50 | |
51 | /** |
52 | * Controls whether an (indefinite) progress dialog is shown when the spell |
53 | * checking takes longer than the given time to complete. By default no |
54 | * progress dialog is shown. If the progress dialog is set to be shown, no |
55 | * time consuming operation (for example, showing a notification message) should |
56 | * be performed in a slot connected to the 'done' signal as this might trigger |
57 | * the progress dialog unnecessarily. |
58 | * |
59 | * @param timeout time after which the progress dialog should appear; a negative |
60 | * value can be used to hide it |
61 | * @since 4.4 |
62 | */ |
63 | void showProgressDialog(int timeout = 500); |
64 | |
65 | /** |
66 | * Controls whether a message box indicating the completion of the spell checking |
67 | * is shown or not. By default it is not shown. |
68 | * |
69 | * @since 4.4 |
70 | */ |
71 | void showSpellCheckCompletionMessage(bool b = true); |
72 | |
73 | /** |
74 | * Controls whether the spell checking is continued after the replacement of a |
75 | * misspelled word has been performed. By default it is continued. |
76 | * |
77 | * @since 4.4 |
78 | */ |
79 | void setSpellCheckContinuedAfterReplacement(bool b); |
80 | |
81 | public Q_SLOTS: |
82 | void setBuffer(const QString &); |
83 | |
84 | Q_SIGNALS: |
85 | /** |
86 | * The dialog won't be closed if you setBuffer() in slot connected to this signal |
87 | * |
88 | * Also emitted after stop() signal |
89 | */ |
90 | void done(const QString &newBuffer); |
91 | void misspelling(const QString &word, int start); |
92 | void replace(const QString &oldWord, int start, const QString &newWord); |
93 | |
94 | void stop(); |
95 | void cancel(); |
96 | void autoCorrect(const QString ¤tWord, const QString &replaceWord); |
97 | |
98 | /** |
99 | * Signal sends when spell checking is finished/stopped/completed |
100 | * @since 4.1 |
101 | */ |
102 | void spellCheckStatus(const QString &); |
103 | |
104 | /** |
105 | * Emitted when the user changes the language used for spellchecking, |
106 | * which is shown in a combobox of this dialog. |
107 | * |
108 | * @param language the new language the user selected |
109 | * @since 4.1 |
110 | */ |
111 | void languageChanged(const QString &language); |
112 | |
113 | private Q_SLOTS: |
114 | void slotMisspelling(const QString &word, int start); |
115 | void slotDone(); |
116 | |
117 | void slotCancel(); |
118 | |
119 | void slotAddWord(); |
120 | void slotReplaceWord(); |
121 | void slotReplaceAll(); |
122 | void slotSkip(); |
123 | void slotSkipAll(); |
124 | void slotSuggest(); |
125 | void slotChangeLanguage(const QString &); |
126 | void slotAutocorrect(); |
127 | |
128 | void setGuiEnabled(bool b); |
129 | void setProgressDialogVisible(bool b); |
130 | |
131 | private: |
132 | void updateDialog(const QString &word); |
133 | void fillDictionaryComboBox(); |
134 | void updateDictionaryComboBox(); |
135 | void fillSuggestions(const QStringList &suggs); |
136 | void initConnections(); |
137 | void initGui(); |
138 | void continueChecking(); |
139 | |
140 | private: |
141 | class Private; |
142 | Private *const d; |
143 | }; |
144 | |
145 | #endif |
146 | |