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