2 * \file QSpellchecker.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "QSpellchecker.h"
15 #include "qt_helpers.h"
17 #include "controllers/ControlSpellchecker.h"
19 #include <QProgressBar>
21 #include <QPushButton>
22 #include <QListWidget>
23 #include <QListWidgetItem>
24 #include <QCloseEvent>
25 #include <QSyntaxHighlighter>
26 #include <QTextCharFormat>
27 #include <QTextDocument>
35 /////////////////////////////////////////////////////////////////////
37 // QSpellCheckerDialog
39 /////////////////////////////////////////////////////////////////////
42 QSpellcheckerDialog::QSpellcheckerDialog(QSpellchecker * form)
47 connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
49 connect(replaceCO, SIGNAL(highlighted(const QString &)),
50 this, SLOT(replaceChanged(const QString &)));
51 connect(replacePB, SIGNAL(clicked()),
52 this, SLOT(replaceClicked()));
53 connect(ignorePB, SIGNAL(clicked()),
54 this, SLOT(ignoreClicked()));
55 connect(replacePB_3, SIGNAL(clicked()),
56 this, SLOT(acceptClicked()));
57 connect(addPB, SIGNAL(clicked()),
58 this, SLOT(addClicked()));
59 connect(suggestionsLW, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
60 this, SLOT(replaceClicked() ) );
61 connect(suggestionsLW, SIGNAL(itemClicked(QListWidgetItem*)),
62 this, SLOT(suggestionChanged(QListWidgetItem*)));
66 void QSpellcheckerDialog::acceptClicked()
71 void QSpellcheckerDialog::addClicked()
76 void QSpellcheckerDialog::replaceClicked()
81 void QSpellcheckerDialog::ignoreClicked()
86 void QSpellcheckerDialog::suggestionChanged(QListWidgetItem * item)
88 if (replaceCO->count() != 0)
89 replaceCO->setItemText(0, item->text());
91 replaceCO->addItem(item->text());
93 replaceCO->setCurrentIndex(0);
96 void QSpellcheckerDialog::replaceChanged(const QString & str)
98 if (suggestionsLW->currentItem()->text() == str)
101 for (int i = 0; i < suggestionsLW->count(); ++i) {
102 if (suggestionsLW->item(i)->text() == str) {
103 suggestionsLW->setCurrentRow(i);
110 void QSpellcheckerDialog::closeEvent(QCloseEvent * e)
117 void QSpellcheckerDialog::reject()
125 /////////////////////////////////////////////////////////////////////
129 /////////////////////////////////////////////////////////////////////
131 typedef QController<ControlSpellchecker, QView<QSpellcheckerDialog> >
134 QSpellchecker::QSpellchecker(Dialog & parent)
135 : SpellcheckerBase(parent, _("Spellchecker"))
139 void QSpellchecker::build_dialog()
141 dialog_.reset(new QSpellcheckerDialog(this));
143 bcview().setCancel(dialog_->closePB);
144 dialog_->wordED->setReadOnly(true);
148 void QSpellchecker::update_contents()
150 if (isVisible() || controller().exitEarly())
151 controller().check();
155 void QSpellchecker::accept()
157 controller().ignoreAll();
161 void QSpellchecker::add()
163 controller().insert();
167 void QSpellchecker::ignore()
169 controller().check();
173 void QSpellchecker::replace()
175 controller().replace(qstring_to_ucs4(dialog_->replaceCO->currentText()));
179 void QSpellchecker::partialUpdate(int s)
181 ControlSpellchecker::State const state =
182 static_cast<ControlSpellchecker::State>(s);
186 case ControlSpellchecker::SPELL_PROGRESSED:
187 dialog_->spellcheckPR->setValue(controller().getProgress());
190 case ControlSpellchecker::SPELL_FOUND_WORD: {
191 dialog_->wordED->setText(toqstr(controller().getWord()));
192 dialog_->suggestionsLW->clear();
195 while (!(w = controller().getSuggestion()).empty()) {
196 dialog_->suggestionsLW->addItem(toqstr(w));
199 if (dialog_->suggestionsLW->count() == 0) {
200 dialog_->suggestionChanged(new QListWidgetItem(dialog_->wordED->text()));
202 dialog_->suggestionChanged(dialog_->suggestionsLW->item(0));
205 dialog_->suggestionsLW->setCurrentRow(0);
212 } // namespace frontend
215 #include "QSpellchecker_moc.cpp"