]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiThesaurus.cpp
renaming of some methods that hurt the eyes + removal of:
[lyx.git] / src / frontends / qt4 / GuiThesaurus.cpp
1 /**
2  * \file GuiThesaurus.cpp
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 "GuiThesaurus.h"
14 #include "qt_helpers.h"
15 #include "debug.h"
16
17 #include <QCloseEvent>
18 #include <QHeaderView>
19 #include <QLineEdit>
20 #include <QPushButton>
21 #include <QTreeWidget>
22 #include <QTreeWidgetItem>
23
24 using std::string;
25
26 namespace lyx {
27 namespace frontend {
28
29 /////////////////////////////////////////////////////////////////////
30 //
31 // QTheasurusDialog
32 //
33 /////////////////////////////////////////////////////////////////////
34
35 GuiThesaurusDialog::GuiThesaurusDialog(GuiThesaurus * form)
36         : form_(form)
37 {
38         setupUi(this);
39
40         meaningsTV->setColumnCount(1);
41         meaningsTV->header()->hide();
42
43         connect(closePB, SIGNAL(clicked()),
44                 form, SLOT(slotClose()));
45         connect(replaceED, SIGNAL(returnPressed()),
46                 this, SLOT(replaceClicked()));
47         connect(replaceED, SIGNAL(textChanged(const QString &)),
48                 this, SLOT(change_adaptor() ) );
49         connect(entryED, SIGNAL(returnPressed()),
50                 this, SLOT(entryChanged()));
51         connect(replacePB, SIGNAL(clicked()),
52                 this, SLOT(replaceClicked()));
53         connect(meaningsTV, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
54                 this, SLOT(itemClicked(QTreeWidgetItem *, int)));
55         connect(meaningsTV, SIGNAL(itemSelectionChanged()),
56                 this, SLOT(selectionChanged()));
57         connect(meaningsTV, SIGNAL(itemActivated(QTreeWidgetItem *, int)),
58                 this, SLOT(selectionClicked(QTreeWidgetItem *, int)));
59 }
60
61
62 void GuiThesaurusDialog::change_adaptor()
63 {
64         form_->changed();
65 }
66
67
68 void GuiThesaurusDialog::closeEvent(QCloseEvent * e)
69 {
70         form_->slotWMHide();
71         e->accept();
72 }
73
74
75 void GuiThesaurusDialog::entryChanged()
76 {
77         updateLists();
78 }
79
80
81 void GuiThesaurusDialog::replaceClicked()
82 {
83         form_->replace();
84 }
85
86
87 void GuiThesaurusDialog::selectionChanged()
88 {
89         int const col = meaningsTV->currentColumn();
90         if (col<0 || form_->readOnly())
91                 return;
92
93         replaceED->setText(meaningsTV->currentItem()->text(col));
94         replacePB->setEnabled(true);
95         form_->changed();
96 }
97
98
99 void GuiThesaurusDialog::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
100 {
101         selectionChanged();
102 }
103
104
105 void GuiThesaurusDialog::selectionClicked(QTreeWidgetItem * item, int col)
106 {
107         entryED->setText(item->text(col));
108         selectionChanged();
109         updateLists();
110 }
111
112
113 void GuiThesaurusDialog::updateLists()
114 {
115         meaningsTV->clear();
116         meaningsTV->setUpdatesEnabled(false);
117
118         Thesaurus::Meanings meanings = form_->controller().getMeanings(qstring_to_ucs4(entryED->text()));
119
120         for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
121                 cit != meanings.end(); ++cit) {
122                 QTreeWidgetItem * i = new QTreeWidgetItem(meaningsTV);
123                 i->setText(0, toqstr(cit->first));
124                 meaningsTV->expandItem(i);
125                 for (std::vector<docstring>::const_iterator cit2 = cit->second.begin();
126                         cit2 != cit->second.end(); ++cit2) {
127                                 QTreeWidgetItem * i2 = new QTreeWidgetItem(i);
128                                 i2->setText(0, toqstr(*cit2));
129                         }
130         }
131
132         meaningsTV->setUpdatesEnabled(true);
133         meaningsTV->update();
134 }
135
136
137 /////////////////////////////////////////////////////////////////////
138 //
139 // GuiThesaurus
140 //
141 /////////////////////////////////////////////////////////////////////
142
143 GuiThesaurus::GuiThesaurus(GuiDialog & parent)
144         : GuiView<GuiThesaurusDialog>(parent, _("Thesaurus"))
145 {
146 }
147
148
149 void GuiThesaurus::build_dialog()
150 {
151         dialog_.reset(new GuiThesaurusDialog(this));
152
153         bc().setCancel(dialog_->closePB);
154         bc().setApply(dialog_->replacePB);
155         bc().addReadOnly(dialog_->replaceED);
156         bc().addReadOnly(dialog_->replacePB);
157 }
158
159
160 void GuiThesaurus::update_contents()
161 {
162         dialog_->entryED->setText(toqstr(controller().text()));
163         dialog_->replaceED->setText("");
164         dialog_->updateLists();
165 }
166
167
168 void GuiThesaurus::replace()
169 {
170         controller().replace(qstring_to_ucs4(dialog_->replaceED->text()));
171 }
172
173 } // namespace frontend
174 } // namespace lyx
175
176
177 #include "GuiThesaurus_moc.cpp"