2 * \file GuiThesaurus.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "GuiThesaurus.h"
15 #include "ControlThesaurus.h"
16 #include "qt_helpers.h"
19 #include <QCloseEvent>
20 #include <QHeaderView>
22 #include <QPushButton>
23 #include <QTreeWidget>
24 #include <QTreeWidgetItem>
32 GuiThesaurusDialog::GuiThesaurusDialog(LyXView & lv)
33 : GuiDialog(lv, "thesaurus")
36 setViewTitle(_("Thesaurus"));
37 setController(new ControlThesaurus(*this));
39 meaningsTV->setColumnCount(1);
40 meaningsTV->header()->hide();
42 connect(closePB, SIGNAL(clicked()),
43 this, SLOT(slotClose()));
44 connect(replaceED, SIGNAL(returnPressed()),
45 this, SLOT(replaceClicked()));
46 connect(replaceED, SIGNAL(textChanged(const QString &)),
47 this, SLOT(change_adaptor() ) );
48 connect(entryED, SIGNAL(returnPressed()),
49 this, SLOT(entryChanged()));
50 connect(replacePB, SIGNAL(clicked()),
51 this, SLOT(replaceClicked()));
52 connect(meaningsTV, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
53 this, SLOT(itemClicked(QTreeWidgetItem *, int)));
54 connect(meaningsTV, SIGNAL(itemSelectionChanged()),
55 this, SLOT(selectionChanged()));
56 connect(meaningsTV, SIGNAL(itemActivated(QTreeWidgetItem *, int)),
57 this, SLOT(selectionClicked(QTreeWidgetItem *, int)));
59 bc().setCancel(closePB);
60 bc().setApply(replacePB);
61 bc().addReadOnly(replaceED);
62 bc().addReadOnly(replacePB);
63 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
67 ControlThesaurus & GuiThesaurusDialog::controller()
69 return static_cast<ControlThesaurus &>(GuiDialog::controller());
72 void GuiThesaurusDialog::change_adaptor()
78 void GuiThesaurusDialog::closeEvent(QCloseEvent * e)
81 GuiDialog::closeEvent(e);
85 void GuiThesaurusDialog::entryChanged()
91 void GuiThesaurusDialog::selectionChanged()
93 int const col = meaningsTV->currentColumn();
94 if (col < 0 || controller().isBufferReadonly())
97 replaceED->setText(meaningsTV->currentItem()->text(col));
98 replacePB->setEnabled(true);
103 void GuiThesaurusDialog::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
109 void GuiThesaurusDialog::selectionClicked(QTreeWidgetItem * item, int col)
111 entryED->setText(item->text(col));
117 void GuiThesaurusDialog::updateLists()
120 meaningsTV->setUpdatesEnabled(false);
122 Thesaurus::Meanings meanings = controller().getMeanings(qstring_to_ucs4(entryED->text()));
124 for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
125 cit != meanings.end(); ++cit) {
126 QTreeWidgetItem * i = new QTreeWidgetItem(meaningsTV);
127 i->setText(0, toqstr(cit->first));
128 meaningsTV->expandItem(i);
129 for (std::vector<docstring>::const_iterator cit2 = cit->second.begin();
130 cit2 != cit->second.end(); ++cit2) {
131 QTreeWidgetItem * i2 = new QTreeWidgetItem(i);
132 i2->setText(0, toqstr(*cit2));
136 meaningsTV->setUpdatesEnabled(true);
137 meaningsTV->update();
141 void GuiThesaurusDialog::updateContents()
143 entryED->setText(toqstr(controller().text()));
144 replaceED->setText("");
149 void GuiThesaurusDialog::replaceClicked()
151 controller().replace(qstring_to_ucs4(replaceED->text()));
154 } // namespace frontend
158 #include "GuiThesaurus_moc.cpp"