]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QSpellchecker.C
Fix unreported bug related to 3246 by Richard Heck:
[lyx.git] / src / frontends / qt4 / QSpellchecker.C
1 /**
2  * \file QSpellchecker.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "QSpellchecker.h"
14 #include "QSpellcheckerDialog.h"
15 #include "Qt2BC.h"
16 #include "qt_helpers.h"
17
18 #include "controllers/ControlSpellchecker.h"
19
20 #include <QProgressBar>
21 #include <QLineEdit>
22 #include <QPushButton>
23 #include <QListWidget>
24 #include <QListWidgetItem>
25
26 using std::string;
27
28 namespace lyx {
29 namespace frontend {
30
31 typedef QController<ControlSpellchecker, QView<QSpellcheckerDialog> > spellchecker_base_class;
32
33 QSpellchecker::QSpellchecker(Dialog & parent)
34         : spellchecker_base_class(parent, _("Spellchecker"))
35 {}
36
37
38 void QSpellchecker::build_dialog()
39 {
40         dialog_.reset(new QSpellcheckerDialog(this));
41
42         bcview().setCancel(dialog_->closePB);
43         dialog_->wordED->setReadOnly(true);
44 }
45
46
47 void QSpellchecker::update_contents()
48 {
49         if (isVisible() || controller().exitEarly())
50                 controller().check();
51 }
52
53
54 void QSpellchecker::accept()
55 {
56         controller().ignoreAll();
57 }
58
59
60 void QSpellchecker::add()
61 {
62         controller().insert();
63 }
64
65
66 void QSpellchecker::ignore()
67 {
68         controller().check();
69 }
70
71
72 void QSpellchecker::replace()
73 {
74         controller().replace(qstring_to_ucs4(dialog_->replaceCO->currentText()));
75 }
76
77
78 void QSpellchecker::partialUpdate(int s)
79 {
80         ControlSpellchecker::State const state =
81                 static_cast<ControlSpellchecker::State>(s);
82
83         switch (state) {
84
85         case ControlSpellchecker::SPELL_PROGRESSED:
86                 dialog_->spellcheckPR->setValue(controller().getProgress());
87                 break;
88
89         case ControlSpellchecker::SPELL_FOUND_WORD: {
90                 dialog_->wordED->setText(toqstr(controller().getWord()));
91                 dialog_->suggestionsLW->clear();
92
93                 docstring w;
94                 while (!(w = controller().getSuggestion()).empty()) {
95                         dialog_->suggestionsLW->addItem(toqstr(w));
96                 }
97
98                 if (dialog_->suggestionsLW->count() == 0) {
99                         dialog_->suggestionChanged(new QListWidgetItem(dialog_->wordED->text()));
100                 } else {
101                         dialog_->suggestionChanged(dialog_->suggestionsLW->item(0));
102                 }
103
104                 dialog_->suggestionsLW->setCurrentRow(0);
105         }
106                 break;
107
108         }
109 }
110
111 } // namespace frontend
112 } // namespace lyx