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"
14 #include "qt_helpers.h"
16 #include <QProgressBar>
18 #include <QPushButton>
19 #include <QListWidget>
20 #include <QListWidgetItem>
21 #include <QCloseEvent>
22 #include <QSyntaxHighlighter>
23 #include <QTextCharFormat>
24 #include <QTextDocument>
32 /////////////////////////////////////////////////////////////////////
34 // GuiSpellCheckerDialog
36 /////////////////////////////////////////////////////////////////////
39 GuiSpellcheckerDialog::GuiSpellcheckerDialog(GuiSpellchecker * form)
44 connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
46 connect(replaceCO, SIGNAL(highlighted(const QString &)),
47 this, SLOT(replaceChanged(const QString &)));
48 connect(replacePB, SIGNAL(clicked()),
49 this, SLOT(replaceClicked()));
50 connect(ignorePB, SIGNAL(clicked()),
51 this, SLOT(ignoreClicked()));
52 connect(replacePB_3, SIGNAL(clicked()),
53 this, SLOT(acceptClicked()));
54 connect(addPB, SIGNAL(clicked()),
55 this, SLOT(addClicked()));
56 connect(suggestionsLW, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
57 this, SLOT(replaceClicked() ) );
58 connect(suggestionsLW, SIGNAL(itemClicked(QListWidgetItem*)),
59 this, SLOT(suggestionChanged(QListWidgetItem*)));
63 void GuiSpellcheckerDialog::acceptClicked()
68 void GuiSpellcheckerDialog::addClicked()
73 void GuiSpellcheckerDialog::replaceClicked()
78 void GuiSpellcheckerDialog::ignoreClicked()
83 void GuiSpellcheckerDialog::suggestionChanged(QListWidgetItem * item)
85 if (replaceCO->count() != 0)
86 replaceCO->setItemText(0, item->text());
88 replaceCO->addItem(item->text());
90 replaceCO->setCurrentIndex(0);
93 void GuiSpellcheckerDialog::replaceChanged(const QString & str)
95 if (suggestionsLW->currentItem()->text() == str)
98 for (int i = 0; i < suggestionsLW->count(); ++i) {
99 if (suggestionsLW->item(i)->text() == str) {
100 suggestionsLW->setCurrentRow(i);
107 void GuiSpellcheckerDialog::closeEvent(QCloseEvent * e)
114 void GuiSpellcheckerDialog::reject()
122 /////////////////////////////////////////////////////////////////////
126 /////////////////////////////////////////////////////////////////////
129 GuiSpellchecker::GuiSpellchecker(GuiDialog & parent)
130 : GuiView<GuiSpellcheckerDialog>(parent, _("Spellchecker"))
134 void GuiSpellchecker::build_dialog()
136 dialog_.reset(new GuiSpellcheckerDialog(this));
138 bc().setCancel(dialog_->closePB);
139 dialog_->wordED->setReadOnly(true);
143 void GuiSpellchecker::update_contents()
145 if (isVisible() || controller().exitEarly())
146 controller().check();
150 void GuiSpellchecker::accept()
152 controller().ignoreAll();
156 void GuiSpellchecker::add()
158 controller().insert();
162 void GuiSpellchecker::ignore()
164 controller().check();
168 void GuiSpellchecker::replace()
170 controller().replace(qstring_to_ucs4(dialog_->replaceCO->currentText()));
174 void GuiSpellchecker::partialUpdate(int s)
176 ControlSpellchecker::State const state =
177 static_cast<ControlSpellchecker::State>(s);
181 case ControlSpellchecker::SPELL_PROGRESSED:
182 dialog_->spellcheckPR->setValue(controller().getProgress());
185 case ControlSpellchecker::SPELL_FOUND_WORD: {
186 dialog_->wordED->setText(toqstr(controller().getWord()));
187 dialog_->suggestionsLW->clear();
190 while (!(w = controller().getSuggestion()).empty()) {
191 dialog_->suggestionsLW->addItem(toqstr(w));
194 if (dialog_->suggestionsLW->count() == 0) {
195 dialog_->suggestionChanged(new QListWidgetItem(dialog_->wordED->text()));
197 dialog_->suggestionChanged(dialog_->suggestionsLW->item(0));
200 dialog_->suggestionsLW->setCurrentRow(0);
207 } // namespace frontend
210 #include "GuiSpellchecker_moc.cpp"