]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QSpellchecker.C
some tabular fixes for the problems reported by Helge
[lyx.git] / src / frontends / qt2 / 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, _("LyX: Spell-check Document"))
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         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(fromqstr(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->setProgress(controller().getProgress());
87                 break;
88
89         case ControlSpellchecker::SPELL_FOUND_WORD: {
90                 dialog_->wordED->setText(toqstr(controller().getWord()));
91                 dialog_->suggestionsLB->clear();
92
93                 string w;
94                 while (!(w = controller().getSuggestion()).empty()) {
95                         dialog_->suggestionsLB->insertItem(toqstr(w));
96                 }
97
98                 if (dialog_->suggestionsLB->count() == 0) {
99                         dialog_->suggestionChanged(dialog_->wordED->text());
100                 } else {
101                         dialog_->suggestionChanged(dialog_->suggestionsLB->text(0));
102                 }
103         }
104                 break;
105
106         }
107 }
108
109 } // namespace frontend
110 } // namespace lyx