]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QSpellchecker.C
adeb9f643a4cd276022439b1ea86595e96b13511
[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 "gettext.h"
22
23 #include <qprogressbar.h>
24 #include <qmessagebox.h>
25 #include <qlineedit.h>
26 #include <qpushbutton.h>
27 #include <qlistbox.h>
28 #include <qcombobox.h>
29
30 typedef Qt2CB<ControlSpellchecker, Qt2DB<QSpellcheckerDialog> > base_class;
31
32
33 QSpellchecker::QSpellchecker()
34         : base_class(_("Spellchecker"))
35 {
36 }
37
38
39 void QSpellchecker::build_dialog()
40 {
41         dialog_.reset(new QSpellcheckerDialog(this));
42
43         bc().setCancel(dialog_->closePB);
44         dialog_->wordED->setReadOnly(true);
45 }
46
47
48 void QSpellchecker::update_contents()
49 {
50         dialog_->wordED->setText("");
51         dialog_->replaceCO->clear();
52         dialog_->suggestionsLB->clear();
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(dialog_->replaceCO->currentText().latin1());
77 }
78
79
80 void QSpellchecker::spellcheck()
81 {
82         controller().check();
83         dialog_->spellcheckPB->setEnabled(false);
84 }
85
86
87 void QSpellchecker::stop()
88 {
89         controller().stop();
90         dialog_->spellcheckPB->setEnabled(true);
91         hide();
92 }
93
94
95 void QSpellchecker::partialUpdate(int id)
96 {
97         switch (id) {
98         case 0:
99                 dialog_->spellcheckPR->setProgress(controller().getProgress());
100                 break;
101         case 1:
102         {
103                 dialog_->wordED->setText(controller().getWord().c_str());
104                 dialog_->suggestionsLB->clear();
105
106                 string w;
107                 while (!(w = controller().getSuggestion()).empty()) {
108                         dialog_->suggestionsLB->insertItem(w.c_str());
109                 }
110         }
111                 break;
112         case 2:
113                 dialog_->spellcheckPB->setEnabled(true);
114                 hide();
115                 QMessageBox::information(0, _("Spellcheck complete"),
116                                          controller().getMessage().c_str(),
117                                          _("OK"));
118                 break;
119         }
120 }