10#include "ui_sonnetui.h"
12#include "backgroundchecker.h"
13#include "settingsimpl_p.h"
16#include <QProgressDialog>
18#include <QDialogButtonBox>
21#include <QStringListModel>
26#define NONSORTINGCOLUMN 2
47 ReadOnlyStringListModel *suggestionsModel =
nullptr;
52 BackgroundChecker *checker =
nullptr;
61 int progressDialogTimeout;
62 bool showCompletionMessageBox;
63 bool spellCheckContinuedAfterReplacement;
66 void deleteProgressDialog(
bool directly)
69 progressDialog->
hide();
71 delete progressDialog;
75 progressDialog =
nullptr;
80Dialog::Dialog(BackgroundChecker *checker,
QWidget *parent)
82 , d(new DialogPrivate)
85 setWindowTitle(tr(
"Check Spelling",
"@title:window"));
90 d->showCompletionMessageBox =
false;
91 d->spellCheckContinuedAfterReplacement =
true;
92 d->progressDialogTimeout = -1;
93 d->progressDialog =
nullptr;
99Dialog::~Dialog() =
default;
101void Dialog::initConnections()
109 connect(d->ui.m_language, &DictionaryComboBox::textActivated,
this, &Dialog::slotChangeLanguage);
111 connect(d->checker, &BackgroundChecker::misspelling,
this, &Dialog::slotMisspelling);
112 connect(d->checker, &BackgroundChecker::done,
this, &Dialog::slotDone);
122 d->ui.m_autoCorrect->hide();
125void Dialog::initGui()
130 d->ui.setupUi(d->wdg);
132 setGuiEnabled(
false);
140 fillDictionaryComboBox();
143 d->suggestionsModel =
new ReadOnlyStringListModel(
this);
144 d->ui.m_suggestions->setModel(d->suggestionsModel);
147void Dialog::activeAutoCorrect(
bool _active)
150 d->ui.m_autoCorrect->show();
152 d->ui.m_autoCorrect->hide();
156void Dialog::showProgressDialog(
int timeout)
158 d->progressDialogTimeout = timeout;
161void Dialog::showSpellCheckCompletionMessage(
bool b)
163 d->showCompletionMessageBox = b;
166void Dialog::setSpellCheckContinuedAfterReplacement(
bool b)
168 d->spellCheckContinuedAfterReplacement = b;
171void Dialog::slotAutocorrect()
173 setGuiEnabled(
false);
174 setProgressDialogVisible(
true);
175 Q_EMIT autoCorrect(d->currentWord, d->ui.m_replacement->text());
179void Dialog::setGuiEnabled(
bool b)
181 d->wdg->setEnabled(b);
184void Dialog::setProgressDialogVisible(
bool b)
187 d->deleteProgressDialog(
true);
188 }
else if (d->progressDialogTimeout >= 0) {
189 if (d->progressDialog) {
193 d->progressDialog->setLabelText(tr(
"Spell checking in progress…",
"@info:progress"));
194 d->progressDialog->setWindowTitle(tr(
"Check Spelling",
"@title:window"));
195 d->progressDialog->setModal(
true);
196 d->progressDialog->setAutoClose(
false);
197 d->progressDialog->setAutoReset(
false);
200 d->progressDialog->reset();
201 d->progressDialog->setRange(0, 0);
202 d->progressDialog->setValue(0);
204 d->progressDialog->setMinimumDuration(d->progressDialogTimeout);
208void Dialog::slotFinished()
210 setProgressDialogVisible(
false);
213 Q_EMIT spellCheckDone(d->checker->text());
214 Q_EMIT spellCheckStatus(tr(
"Spell check stopped."));
218void Dialog::slotCancel()
221 d->deleteProgressDialog(
false);
224 Q_EMIT spellCheckStatus(tr(
"Spell check canceled."));
228QString Dialog::originalBuffer()
const
230 return d->originalBuffer;
235 return d->checker->text();
238void Dialog::setBuffer(
const QString &buf)
240 d->originalBuffer = buf;
245void Dialog::fillDictionaryComboBox()
250 Speller speller = d->checker->speller();
251 d->dictsMap = speller.availableDictionaries();
253 updateDictionaryComboBox();
256void Dialog::updateDictionaryComboBox()
258 const Speller &speller = d->checker->speller();
259 d->ui.m_language->setCurrentByDictionary(speller.language());
262void Dialog::updateDialog(
const QString &word)
264 d->ui.m_unknownWord->setText(word);
265 d->ui.m_contextLabel->setText(d->checker->currentContext());
266 const QStringList suggs = d->checker->suggest(word);
269 d->ui.m_replacement->clear();
271 d->ui.m_replacement->setText(suggs.
first());
273 fillSuggestions(suggs);
279 fillDictionaryComboBox();
280 if (d->originalBuffer.isEmpty()) {
283 d->checker->setText(d->originalBuffer);
285 setProgressDialogVisible(
true);
288void Dialog::slotAddWord()
290 setGuiEnabled(
false);
291 setProgressDialogVisible(
true);
292 d->checker->addWordToPersonal(d->currentWord);
293 d->checker->continueChecking();
296void Dialog::slotReplaceWord()
298 setGuiEnabled(
false);
299 setProgressDialogVisible(
true);
300 QString replacementText = d->ui.m_replacement->text();
301 Q_EMIT
replace(d->currentWord, d->currentPosition, replacementText);
303 if (d->spellCheckContinuedAfterReplacement) {
304 d->checker->replace(d->currentPosition, d->currentWord, replacementText);
305 d->checker->continueChecking();
311void Dialog::slotReplaceAll()
313 setGuiEnabled(
false);
314 setProgressDialogVisible(
true);
315 d->replaceAllMap.insert(d->currentWord, d->ui.m_replacement->text());
319void Dialog::slotSkip()
321 setGuiEnabled(
false);
322 setProgressDialogVisible(
true);
323 d->checker->continueChecking();
326void Dialog::slotSkipAll()
328 setGuiEnabled(
false);
329 setProgressDialogVisible(
true);
331 Speller speller = d->checker->speller();
332 speller.addToPersonal(d->currentWord);
333 d->checker->setSpeller(speller);
334 d->checker->continueChecking();
337void Dialog::slotSuggest()
339 const QStringList suggs = d->checker->suggest(d->ui.m_replacement->text());
340 fillSuggestions(suggs);
343void Dialog::slotChangeLanguage(
const QString &lang)
345 const QString languageCode = d->dictsMap[lang];
347 d->checker->changeLanguage(languageCode);
349 Q_EMIT languageChanged(languageCode);
353void Dialog::slotSelectionChanged(
const QModelIndex &item)
358void Dialog::fillSuggestions(
const QStringList &suggs)
360 d->suggestionsModel->setStringList(suggs);
363void Dialog::slotMisspelling(
const QString &word,
int start)
366 setProgressDialogVisible(
false);
367 Q_EMIT misspelling(word,
start);
371 if (!updatesEnabled()) {
375 d->currentWord = word;
376 d->currentPosition =
start;
377 if (d->replaceAllMap.contains(word)) {
378 d->ui.m_replacement->setText(d->replaceAllMap[word]);
386void Dialog::slotDone()
389 Q_EMIT spellCheckDone(d->checker->text());
391 updateDictionaryComboBox();
392 d->checker->setText(d->originalBuffer);
395 setProgressDialogVisible(
false);
396 Q_EMIT spellCheckStatus(tr(
"Spell check complete."));
398 if (!d->canceled && d->showCompletionMessageBox) {
405#include "moc_dialog.cpp"
void stop(Ekos::AlignState mode)
Q_SCRIPTABLE Q_NOREPLY void start()
const QList< QKeySequence > & replace()
void clicked(const QModelIndex &index)
void doubleClicked(const QModelIndex &index)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
bool isEmpty() const const
QVariant data(int role) const const
QObject * parent() const const
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString toString() const const