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

source code of sonnet/src/ui/dialog.h