]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QSpellchecker.C
rename LFUN enum values according to their command (as used in th minibuffer/bind...
[lyx.git] / src / frontends / qt4 / 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>
21 #include <QLineEdit>
22 #include <QPushButton>
23 #include <QListWidget>
24 #include <QListWidgetItem>
25
26 using std::string;
27
28 namespace lyx {
29 namespace frontend {
30
31 typedef QController<ControlSpellchecker, QView<QSpellcheckerDialog> > base_class;
32
33 QSpellchecker::QSpellchecker(Dialog & parent)
34         : base_class(parent, _("Spellchecker"))
35 {}
36
37
38 void QSpellchecker::build_dialog()
39 {
40         dialog_.reset(new QSpellcheckerDialog(this));
41
42         bcview().setCancel(dialog_->closePB);
43         dialog_->wordED->setReadOnly(true);
44 }
45
46
47 void QSpellchecker::update_contents()
48 {
49         controller().check();
50 }
51
52
53 void QSpellchecker::accept()
54 {
55         controller().ignoreAll();
56 }
57
58
59 void QSpellchecker::add()
60 {
61         controller().insert();
62 }
63
64
65 void QSpellchecker::ignore()
66 {
67         controller().check();
68 }
69
70
71 void QSpellchecker::replace()
72 {
73         controller().replace(fromqstr(dialog_->replaceCO->currentText()));
74 }
75
76
77 void QSpellchecker::partialUpdate(int s)
78 {
79         ControlSpellchecker::State const state =
80                 static_cast<ControlSpellchecker::State>(s);
81
82         switch (state) {
83
84         case ControlSpellchecker::SPELL_PROGRESSED:
85                 dialog_->spellcheckPR->setValue(controller().getProgress());
86                 break;
87
88         case ControlSpellchecker::SPELL_FOUND_WORD: {
89                 dialog_->wordED->setText(toqstr(controller().getWord()));
90                 dialog_->suggestionsLW->clear();
91
92                 string w;
93                 while (!(w = controller().getSuggestion()).empty()) {
94                         dialog_->suggestionsLW->addItem(toqstr(w));
95                 }
96
97                 if (dialog_->suggestionsLW->count() == 0) {
98                         dialog_->suggestionChanged(new QListWidgetItem(dialog_->wordED->text()));
99                 } else {
100                         dialog_->suggestionChanged(dialog_->suggestionsLW->item(0));
101                 }
102
103                 dialog_->suggestionsLW->setCurrentRow(0);
104         }
105                 break;
106
107         }
108 }
109
110 } // namespace frontend
111 } // namespace lyx