]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QSpellcheckerDialog.C
015103006bc56fc686ad69fe6cb430711f5a957a
[lyx.git] / src / frontends / qt4 / QSpellcheckerDialog.C
1 /**
2  * \file QSpellcheckerDialog.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 "QSpellcheckerDialog.h"
14 #include "QSpellchecker.h"
15
16 #include <QListWidget>
17 #include <QPushButton>
18 #include <QCloseEvent>
19
20 namespace lyx {
21 namespace frontend {
22
23 QSpellcheckerDialog::QSpellcheckerDialog(QSpellchecker * form)
24         : form_(form)
25 {
26         setupUi(this);
27
28         connect(closePB, SIGNAL(clicked()),
29                 form, SLOT(slotClose()));
30
31         connect( replaceCO, SIGNAL( highlighted(const QString&) ), 
32                 this, SLOT( replaceChanged(const QString &) ) );
33         connect( replacePB, SIGNAL( clicked() ), 
34                 this, SLOT( replaceClicked() ) );
35         connect( ignorePB, SIGNAL( clicked() ), 
36                 this, SLOT( ignoreClicked() ) );
37         connect( replacePB_3, SIGNAL( clicked() ), 
38                 this, SLOT( acceptClicked() ) );
39         connect( addPB, SIGNAL( clicked() ), 
40                 this, SLOT( addClicked() ) );
41         connect( suggestionsLW, SIGNAL( itemDoubleClicked(QListWidgetItem*) ), 
42                 this, SLOT( replaceClicked() ) );
43         connect( suggestionsLW, SIGNAL( itemClicked(QListWidgetItem*) ), 
44                 this, SLOT( suggestionChanged(QListWidgetItem*) ) );
45 }
46
47
48 void QSpellcheckerDialog::acceptClicked()
49 {
50         form_->accept();
51 }
52
53 void QSpellcheckerDialog::addClicked()
54 {
55         form_->add();
56 }
57
58 void QSpellcheckerDialog::replaceClicked()
59 {
60         form_->replace();
61 }
62
63 void QSpellcheckerDialog::ignoreClicked()
64 {
65         form_->ignore();
66 }
67
68 void QSpellcheckerDialog::suggestionChanged(QListWidgetItem * item)
69 {
70         if (replaceCO->count() != 0)
71                 replaceCO->changeItem(item->text(), 0);
72         else
73                 replaceCO->insertItem(item->text());
74
75         replaceCO->setCurrentItem(0);
76 }
77
78 void QSpellcheckerDialog::replaceChanged(const QString & str)
79 {
80         if (suggestionsLW->currentItem()->text() == str)
81                 return;
82
83         unsigned int i = 0;
84         for (; i < suggestionsLW->count(); ++i) {
85                 if (suggestionsLW->item(i)->text() == str)
86                         break;
87         }
88
89         if (i != suggestionsLW->count())
90                 suggestionsLW->setCurrentRow(i);
91 }
92
93
94 void QSpellcheckerDialog::closeEvent(QCloseEvent * e)
95 {
96         form_->slotWMHide();
97         e->accept();
98 }
99
100
101 void QSpellcheckerDialog::reject()
102 {
103         form_->slotWMHide();
104         QDialog::reject();
105 }
106
107 } // namespace frontend
108 } // namespace lyx
109
110 #include "QSpellcheckerDialog_moc.cpp"