23 #include "ui_sonnetui.h"
37 #include <QtGui/QListView>
38 #include <QtGui/QStringListModel>
39 #include <QtGui/QPushButton>
40 #include <QtGui/QComboBox>
41 #include <QtGui/QLabel>
42 #include <QtCore/QTimer>
49 #define NONSORTINGCOLUMN 2
55 Qt::ItemFlags flags(
const QModelIndex& index)
const {Q_UNUSED(index);
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;}
62 ReadOnlyStringListModel *suggestionsModel;
66 BackgroundChecker *checker;
74 int progressDialogTimeout;
75 bool showCompletionMessageBox;
76 bool spellCheckContinuedAfterReplacement;
79 void deleteProgressDialog(
bool directly)
83 progressDialog->hide();
86 delete progressDialog;
90 progressDialog->deleteLater();
92 progressDialog = NULL;
108 d->checker = checker;
111 d->showCompletionMessageBox =
false;
112 d->spellCheckContinuedAfterReplacement =
true;
113 d->progressDialogTimeout = -1;
114 d->progressDialog = NULL;
127 void Dialog::initConnections()
129 connect( d->ui.m_addBtn, SIGNAL(clicked()),
130 SLOT(slotAddWord()) );
131 connect( d->ui.m_replaceBtn, SIGNAL(clicked()),
132 SLOT(slotReplaceWord()) );
133 connect( d->ui.m_replaceAllBtn, SIGNAL(clicked()),
134 SLOT(slotReplaceAll()) );
135 connect( d->ui.m_skipBtn, SIGNAL(clicked()),
137 connect( d->ui.m_skipAllBtn, SIGNAL(clicked()),
138 SLOT(slotSkipAll()) );
139 connect( d->ui.m_suggestBtn, SIGNAL(clicked()),
140 SLOT(slotSuggest()) );
142 SLOT(slotChangeLanguage(
QString)) );
146 SLOT(slotMisspelling(
QString,
int)) );
150 SLOT(slotReplaceWord()) );
153 connect( d->ui.m_replacement, SIGNAL(returnPressed()),
this, SLOT(slotReplaceWord()) );
154 connect( d->ui.m_autoCorrect, SIGNAL(clicked()),
155 SLOT(slotAutocorrect()) );
158 d->ui.m_autoCorrect->hide();
161 void Dialog::initGui()
164 d->ui.setupUi(d->wdg);
165 setGuiEnabled(
false);
168 fillDictionaryComboBox();
171 d->suggestionsModel=
new ReadOnlyStringListModel(
this);
172 d->ui.m_suggestions->setModel(d->suggestionsModel);
178 d->ui.m_autoCorrect->show();
180 d->ui.m_autoCorrect->hide();
185 d->progressDialogTimeout = timeout;
190 d->showCompletionMessageBox = b;
195 d->spellCheckContinuedAfterReplacement = b;
198 void Dialog::slotAutocorrect()
200 setGuiEnabled(
false);
201 setProgressDialogVisible(
true);
203 emit
autoCorrect(d->currentWord.word, d->ui.m_replacement->text() );
207 void Dialog::setGuiEnabled(
bool b)
209 d->wdg->setEnabled(b);
212 void Dialog::setProgressDialogVisible(
bool b)
216 d->deleteProgressDialog(
true);
218 else if(d->progressDialogTimeout >= 0)
220 if (d->progressDialog)
225 i18nc(
"progress label",
"Spell checking in progress..."));
226 d->progressDialog->setModal(
true);
227 d->progressDialog->setAutoClose(
false);
228 d->progressDialog->setAutoReset(
false);
231 d->progressDialog->progressBar()->reset();
232 d->progressDialog->progressBar()->setRange(0, 0);
233 d->progressDialog->progressBar()->setValue(0);
235 d->progressDialog->setMinimumDuration(d->progressDialogTimeout);
239 void Dialog::slotFinished()
242 setProgressDialogVisible(
false);
245 emit
done(d->checker->text());
250 void Dialog::slotCancel()
254 d->deleteProgressDialog(
false);
263 return d->originalBuffer;
268 return d->checker->text();
273 d->originalBuffer = buf;
278 void Dialog::fillDictionaryComboBox()
280 Speller speller = d->checker->speller();
283 d->ui.m_language->clear();
284 d->ui.m_language->addItems(langs);
285 updateDictionaryComboBox();
288 void Dialog::updateDictionaryComboBox()
290 Speller speller = d->checker->speller();
291 d->ui.m_language->setCurrentIndex(d->dictsMap.values().indexOf(speller.language()));
294 void Dialog::updateDialog(
const QString& word )
296 d->ui.m_unknownWord->setText( word );
297 d->ui.m_contextLabel->setText( d->checker->currentContext() );
298 const QStringList suggs = d->checker->suggest( word );
301 d->ui.m_replacement->clear();
303 d->ui.m_replacement->setText( suggs.
first() );
304 fillSuggestions( suggs );
309 kDebug()<<
"Showing dialog";
311 fillDictionaryComboBox();
312 updateDictionaryComboBox();
313 if (d->originalBuffer.isEmpty())
319 d->checker->setText(d->originalBuffer);
321 setProgressDialogVisible(
true);
324 void Dialog::slotAddWord()
326 setGuiEnabled(
false);
327 setProgressDialogVisible(
true);
328 d->checker->addWordToPersonal(d->currentWord.word);
329 d->checker->continueChecking();
332 void Dialog::slotReplaceWord()
334 setGuiEnabled(
false);
335 setProgressDialogVisible(
true);
336 QString replacementText = d->ui.m_replacement->text();
337 emit
replace( d->currentWord.word, d->currentWord.start,
340 if( d->spellCheckContinuedAfterReplacement ) {
341 d->checker->replace(d->currentWord.start,
344 d->checker->continueChecking();
351 void Dialog::slotReplaceAll()
353 setGuiEnabled(
false);
354 setProgressDialogVisible(
true);
355 d->replaceAllMap.insert( d->currentWord.word,
356 d->ui.m_replacement->text() );
360 void Dialog::slotSkip()
362 setGuiEnabled(
false);
363 setProgressDialogVisible(
true);
364 d->checker->continueChecking();
367 void Dialog::slotSkipAll()
369 setGuiEnabled(
false);
370 setProgressDialogVisible(
true);
372 Speller speller = d->checker->speller();
373 speller.addToPersonal(d->currentWord.word);
374 d->checker->setSpeller(speller);
375 d->checker->continueChecking();
378 void Dialog::slotSuggest()
380 QStringList suggs = d->checker->suggest( d->ui.m_replacement->text() );
381 fillSuggestions( suggs );
384 void Dialog::slotChangeLanguage(
const QString &lang)
386 Speller speller = d->checker->speller();
387 QString languageCode = d->dictsMap[lang];
389 d->checker->changeLanguage(languageCode);
395 void Dialog::slotSelectionChanged(
const QModelIndex &item)
400 void Dialog::fillSuggestions(
const QStringList& suggs )
402 d->suggestionsModel->setStringList(suggs);
405 void Dialog::slotMisspelling(
const QString& word,
int start)
408 setProgressDialogVisible(
false);
416 kDebug()<<
"Dialog misspelling!!";
417 d->currentWord = Word( word, start );
418 if ( d->replaceAllMap.contains( word ) ) {
419 d->ui.m_replacement->setText( d->replaceAllMap[ word ] );
422 updateDialog( word );
427 void Dialog::slotDone()
430 emit
done(d->checker->text());
433 updateDictionaryComboBox();
434 d->checker->setText(d->originalBuffer);
439 setProgressDialogVisible(
false);
443 if(!d->canceled && d->showCompletionMessageBox)
452 #include "dialog.moc"
QString i18n(const char *text)
void setButtonGuiItem(ButtonCode id, const KGuiItem &item)
Sets the KGuiItem directly for the button instead of using 3 methods to set the text, tooltip and whatsthis strings.
void setModal(bool modal)
void languageChanged(const QString &language)
Emitted when the user changes the language used for spellchecking, which is shown in a combobox of th...
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected) ...
static void information(QWidget *parent, const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
Display an "Information" dialog.
void setSpellCheckContinuedAfterReplacement(bool b)
Controls whether the spell checking is continued after the replacement of a misspelled word has been ...
void setHelp(const QString &anchor, const QString &appname=QString())
Sets the help path and topic.
void replace(const QString &oldWord, int start, const QString &newWord)
void setBuffer(const QString &)
A dialog base class with standard buttons and predefined layouts.
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
virtual void setCaption(const QString &caption)
Make a KDE compliant caption.
QString i18nc(const char *ctxt, const char *text)
void setMainWidget(QWidget *widget)
Sets the main widget of the dialog.
void showSpellCheckCompletionMessage(bool b=true)
Controls whether a message box indicating the completion of the spell checking is shown or not...
void showProgressDialog(int timeout=500)
Controls whether an (indefinite) progress dialog is shown when the spell checking takes longer than t...
void cancelClicked()
The Cancel button was pressed.
An abstract class for GUI data such as ToolTip and Icon.
void spellCheckStatus(const QString &)
Signal sends when spell checking is finished/stopped/completed.
Dialog(BackgroundChecker *checker, QWidget *parent)
void setButtons(ButtonCodes buttonMask)
Creates (or recreates) the button box and all the buttons in it.
Show Help button. (this button will run the help set with setHelp)
void activeAutoCorrect(bool _active)
void misspelling(const QString &word, int start)
void setDefaultButton(ButtonCode id)
Sets the button that will be activated when the Enter key is pressed.
QMap< QString, QString > availableDictionaries() const
A dialog with a progress bar.
QVariant data(int role) const
void done(const QString &newBuffer)
The dialog won't be closed if you setBuffer() in slot connected to this signal.
QString originalBuffer() const
void autoCorrect(const QString ¤tWord, const QString &replaceWord)
void user1Clicked()
The User1 button was pressed.
Show User defined button 1.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)