]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QSpellchecker.C
enable Font cache only for MacOSX and inline width() for other platform.
[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, lyx::to_utf8(_("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         if (isVisible()) {
50 //              controller().check();
51         }
52 }
53
54
55 void QSpellchecker::accept()
56 {
57         controller().ignoreAll();
58 }
59
60
61 void QSpellchecker::add()
62 {
63         controller().insert();
64 }
65
66
67 void QSpellchecker::ignore()
68 {
69         controller().check();
70 }
71
72
73 void QSpellchecker::replace()
74 {
75         controller().replace(fromqstr(dialog_->replaceCO->currentText()));
76 }
77
78
79 void QSpellchecker::partialUpdate(int s)
80 {
81         ControlSpellchecker::State const state =
82                 static_cast<ControlSpellchecker::State>(s);
83
84         switch (state) {
85
86         case ControlSpellchecker::SPELL_PROGRESSED:
87                 dialog_->spellcheckPR->setValue(controller().getProgress());
88                 break;
89
90         case ControlSpellchecker::SPELL_FOUND_WORD: {
91                 dialog_->wordED->setText(toqstr(controller().getWord()));
92                 dialog_->suggestionsLW->clear();
93
94                 string w;
95                 while (!(w = controller().getSuggestion()).empty()) {
96                         dialog_->suggestionsLW->addItem(toqstr(w));
97                 }
98
99                 if (dialog_->suggestionsLW->count() == 0) {
100                         dialog_->suggestionChanged(new QListWidgetItem(dialog_->wordED->text()));
101                 } else {
102                         dialog_->suggestionChanged(dialog_->suggestionsLW->item(0));
103                 }
104
105                 dialog_->suggestionsLW->setCurrentRow(0);
106         }
107                 break;
108
109         }
110 }
111
112 } // namespace frontend
113 } // namespace lyx