]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QSpellchecker.C
Joao latest bits
[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 "debug.h"
14 #include "ControlSpellchecker.h"
15 #include "QSpellcheckerDialog.h"
16 #include "QSpellchecker.h"
17 #include "Qt2BC.h"
18 #include "qt_helpers.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 typedef Qt2CB<ControlSpellchecker, Qt2DB<QSpellcheckerDialog> > base_class;
29
30
31 QSpellchecker::QSpellchecker()
32         : base_class(_("LyX: Spell-check Document"))
33 {
34 }
35
36
37 void QSpellchecker::build_dialog()
38 {
39         dialog_.reset(new QSpellcheckerDialog(this));
40
41         bcview().setCancel(dialog_->closePB);
42         dialog_->wordED->setReadOnly(true);
43 }
44
45
46 void QSpellchecker::accept()
47 {
48         controller().ignoreAll();
49 }
50
51
52 void QSpellchecker::add()
53 {
54         controller().insert();
55 }
56
57
58 void QSpellchecker::ignore()
59 {
60         controller().check();
61 }
62
63
64 void QSpellchecker::replace()
65 {
66         controller().replace(fromqstr(dialog_->replaceCO->currentText()));
67 }
68
69
70 void QSpellchecker::partialUpdate(int s)
71 {
72         ControlSpellchecker::State const state =
73                 static_cast<ControlSpellchecker::State>(s);
74
75         switch (state) {
76
77         case ControlSpellchecker::SPELL_PROGRESSED:
78                 dialog_->spellcheckPR->setProgress(controller().getProgress());
79                 break;
80
81         case ControlSpellchecker::SPELL_FOUND_WORD: {
82                 dialog_->wordED->setText(toqstr(controller().getWord()));
83                 dialog_->suggestionsLB->clear();
84
85                 string w;
86                 while (!(w = controller().getSuggestion()).empty()) {
87                         dialog_->suggestionsLB->insertItem(toqstr(w));
88                 }
89
90                 if (dialog_->suggestionsLB->count() == 0) {
91                         dialog_->suggestionChanged(dialog_->wordED->text());
92                 } else {
93                         dialog_->suggestionChanged(dialog_->suggestionsLB->text(0));
94                 }
95         }
96                 break;
97
98         }
99 }