]> git.lyx.org Git - lyx.git/blob - src/frontends/qt3/QSpellchecker.C
Extracted from r14281
[lyx.git] / src / frontends / qt3 / 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.h>
21 #include <qlineedit.h>
22 #include <qpushbutton.h>
23 #include <qlistbox.h>
24 #include <qcombobox.h>
25
26 using std::string;
27
28 namespace lyx {
29 namespace frontend {
30
31 typedef QController<ControlSpellchecker, QView<QSpellcheckerDialog> > base_class;
32
33
34 QSpellchecker::QSpellchecker(Dialog & parent)
35         : base_class(parent, _("Spellchecker"))
36 {}
37
38
39 void QSpellchecker::build_dialog()
40 {
41         dialog_.reset(new QSpellcheckerDialog(this));
42
43         bcview().setCancel(dialog_->closePB);
44         dialog_->wordED->setReadOnly(true);
45 }
46
47
48 void QSpellchecker::update_contents()
49 {
50         if (isVisible() || controller().exitEarly()) {
51                 controller().check();
52         }
53 }
54
55
56 void QSpellchecker::accept()
57 {
58         controller().ignoreAll();
59 }
60
61
62 void QSpellchecker::add()
63 {
64         controller().insert();
65 }
66
67
68 void QSpellchecker::ignore()
69 {
70         controller().check();
71 }
72
73
74 void QSpellchecker::replace()
75 {
76         controller().replace(fromqstr(dialog_->replaceCO->currentText()));
77 }
78
79
80 void QSpellchecker::partialUpdate(int s)
81 {
82         ControlSpellchecker::State const state =
83                 static_cast<ControlSpellchecker::State>(s);
84
85         switch (state) {
86
87         case ControlSpellchecker::SPELL_PROGRESSED:
88                 dialog_->spellcheckPR->setProgress(controller().getProgress());
89                 break;
90
91         case ControlSpellchecker::SPELL_FOUND_WORD: {
92                 dialog_->wordED->setText(toqstr(controller().getWord()));
93                 dialog_->suggestionsLB->clear();
94
95                 string w;
96                 while (!(w = controller().getSuggestion()).empty()) {
97                         dialog_->suggestionsLB->insertItem(toqstr(w));
98                 }
99
100                 if (dialog_->suggestionsLB->count() == 0) {
101                         dialog_->suggestionChanged(dialog_->wordED->text());
102                 } else {
103                         dialog_->suggestionChanged(dialog_->suggestionsLB->text(0));
104                 }
105         }
106                 break;
107
108         }
109 }
110
111 } // namespace frontend
112 } // namespace lyx