2 * \file GuiSpellchecker.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 "GuiSpellchecker.h"
15 #include "qt_helpers.h"
17 #include <QProgressBar>
19 #include <QPushButton>
20 #include <QListWidget>
21 #include <QListWidgetItem>
22 #include <QCloseEvent>
23 #include <QSyntaxHighlighter>
24 #include <QTextCharFormat>
25 #include <QTextDocument>
33 /////////////////////////////////////////////////////////////////////
35 // GuiSpellCheckerDialog
37 /////////////////////////////////////////////////////////////////////
40 GuiSpellcheckerDialog::GuiSpellcheckerDialog(GuiSpellchecker * form)
45 connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
47 connect(replaceCO, SIGNAL(highlighted(const QString &)),
48 this, SLOT(replaceChanged(const QString &)));
49 connect(replacePB, SIGNAL(clicked()),
50 this, SLOT(replaceClicked()));
51 connect(ignorePB, SIGNAL(clicked()),
52 this, SLOT(ignoreClicked()));
53 connect(replacePB_3, SIGNAL(clicked()),
54 this, SLOT(acceptClicked()));
55 connect(addPB, SIGNAL(clicked()),
56 this, SLOT(addClicked()));
57 connect(suggestionsLW, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
58 this, SLOT(replaceClicked() ) );
59 connect(suggestionsLW, SIGNAL(itemClicked(QListWidgetItem*)),
60 this, SLOT(suggestionChanged(QListWidgetItem*)));
64 void GuiSpellcheckerDialog::acceptClicked()
69 void GuiSpellcheckerDialog::addClicked()
74 void GuiSpellcheckerDialog::replaceClicked()
79 void GuiSpellcheckerDialog::ignoreClicked()
84 void GuiSpellcheckerDialog::suggestionChanged(QListWidgetItem * item)
86 if (replaceCO->count() != 0)
87 replaceCO->setItemText(0, item->text());
89 replaceCO->addItem(item->text());
91 replaceCO->setCurrentIndex(0);
94 void GuiSpellcheckerDialog::replaceChanged(const QString & str)
96 if (suggestionsLW->currentItem()->text() == str)
99 for (int i = 0; i < suggestionsLW->count(); ++i) {
100 if (suggestionsLW->item(i)->text() == str) {
101 suggestionsLW->setCurrentRow(i);
108 void GuiSpellcheckerDialog::closeEvent(QCloseEvent * e)
115 void GuiSpellcheckerDialog::reject()
123 /////////////////////////////////////////////////////////////////////
127 /////////////////////////////////////////////////////////////////////
130 GuiSpellchecker::GuiSpellchecker(Dialog & parent)
131 : GuiView<GuiSpellcheckerDialog>(parent, _("Spellchecker"))
135 void GuiSpellchecker::build_dialog()
137 dialog_.reset(new GuiSpellcheckerDialog(this));
139 bcview().setCancel(dialog_->closePB);
140 dialog_->wordED->setReadOnly(true);
144 void GuiSpellchecker::update_contents()
146 if (isVisible() || controller().exitEarly())
147 controller().check();
151 void GuiSpellchecker::accept()
153 controller().ignoreAll();
157 void GuiSpellchecker::add()
159 controller().insert();
163 void GuiSpellchecker::ignore()
165 controller().check();
169 void GuiSpellchecker::replace()
171 controller().replace(qstring_to_ucs4(dialog_->replaceCO->currentText()));
175 void GuiSpellchecker::partialUpdate(int s)
177 ControlSpellchecker::State const state =
178 static_cast<ControlSpellchecker::State>(s);
182 case ControlSpellchecker::SPELL_PROGRESSED:
183 dialog_->spellcheckPR->setValue(controller().getProgress());
186 case ControlSpellchecker::SPELL_FOUND_WORD: {
187 dialog_->wordED->setText(toqstr(controller().getWord()));
188 dialog_->suggestionsLW->clear();
191 while (!(w = controller().getSuggestion()).empty()) {
192 dialog_->suggestionsLW->addItem(toqstr(w));
195 if (dialog_->suggestionsLW->count() == 0) {
196 dialog_->suggestionChanged(new QListWidgetItem(dialog_->wordED->text()));
198 dialog_->suggestionChanged(dialog_->suggestionsLW->item(0));
201 dialog_->suggestionsLW->setCurrentRow(0);
208 } // namespace frontend
211 #include "GuiSpellchecker_moc.cpp"