]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QSpellchecker.C
df70dfe9e5be771a7e44ed4e56e7586bb36edd0d
[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 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "ControlSpellchecker.h"
18 #include "QSpellcheckerDialog.h"
19 #include "QSpellchecker.h"
20 #include "Qt2BC.h"
21 #include "qt_helpers.h"
22 #include "debug.h"
23
24 #include <qprogressbar.h>
25 #include <qmessagebox.h>
26 #include <qlineedit.h>
27 #include <qpushbutton.h>
28 #include <qlistbox.h>
29 #include <qcombobox.h>
30
31 typedef Qt2CB<ControlSpellchecker, Qt2DB<QSpellcheckerDialog> > base_class;
32
33
34 QSpellchecker::QSpellchecker()
35         : base_class(qt_("Spellchecker"))
36 {
37 }
38
39
40 void QSpellchecker::build_dialog()
41 {
42         dialog_.reset(new QSpellcheckerDialog(this));
43
44         bc().setCancel(dialog_->closePB);
45         dialog_->wordED->setReadOnly(true);
46 }
47
48
49 void QSpellchecker::update_contents()
50 {
51         dialog_->wordED->setText("");
52         dialog_->replaceCO->clear();
53         dialog_->suggestionsLB->clear();
54         dialog_->spellcheckPR->setProgress(0);
55 }
56
57
58 void QSpellchecker::accept()
59 {
60         controller().ignoreAll();
61 }
62
63
64 void QSpellchecker::add()
65 {
66         controller().insert();
67 }
68
69
70 void QSpellchecker::ignore()
71 {
72         controller().check();
73 }
74
75
76 void QSpellchecker::replace()
77 {
78         controller().replace(fromqstr(dialog_->replaceCO->currentText()));
79 }
80
81
82 void QSpellchecker::spellcheck()
83 {
84         controller().check();
85         dialog_->spellcheckPB->setEnabled(false);
86 }
87
88
89 void QSpellchecker::stop()
90 {
91         controller().stop();
92         dialog_->spellcheckPB->setEnabled(true);
93         hide();
94 }
95
96
97 void QSpellchecker::partialUpdate(int id)
98 {
99         switch (id) {
100         case 0:
101                 dialog_->spellcheckPR->setProgress(controller().getProgress());
102                 break;
103
104         case 1: {
105                 dialog_->wordED->setText(toqstr(controller().getWord()));
106                 dialog_->suggestionsLB->clear();
107
108                 string w;
109                 while (!(w = controller().getSuggestion()).empty()) {
110                         dialog_->suggestionsLB->insertItem(toqstr(w));
111                 }
112
113                 dialog_->suggestionChanged(dialog_->wordED->text());
114         }
115                 break;
116
117         case 2:
118                 dialog_->spellcheckPB->setEnabled(true);
119                 hide();
120                 QMessageBox::information(0, qt_("Spellcheck complete"),
121                                          toqstr(controller().getMessage()),
122                                          qt_("OK"));
123                 break;
124         }
125 }