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 "qt_helpers.h"
18 #include <QCloseEvent>
19 #include <QHeaderView>
21 #include <QPushButton>
22 #include <QTreeWidget>
23 #include <QTreeWidgetItem>
26 #include "FuncRequest.h"
34 GuiThesaurus::GuiThesaurus(GuiView & lv)
35 : GuiDialog(lv, "thesaurus")
38 setViewTitle(_("Thesaurus"));
40 meaningsTV->setColumnCount(1);
41 meaningsTV->header()->hide();
43 connect(closePB, SIGNAL(clicked()),
44 this, SLOT(slotClose()));
45 connect(replaceED, SIGNAL(returnPressed()),
46 this, SLOT(replaceClicked()));
47 connect(replaceED, SIGNAL(textChanged(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)));
60 bc().setCancel(closePB);
61 bc().setApply(replacePB);
62 bc().addReadOnly(replaceED);
63 bc().addReadOnly(replacePB);
64 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
68 void GuiThesaurus::change_adaptor()
74 void GuiThesaurus::closeEvent(QCloseEvent * e)
77 GuiDialog::closeEvent(e);
81 void GuiThesaurus::entryChanged()
87 void GuiThesaurus::selectionChanged()
89 int const col = meaningsTV->currentColumn();
90 if (col < 0 || isBufferReadonly())
93 replaceED->setText(meaningsTV->currentItem()->text(col));
94 replacePB->setEnabled(true);
99 void GuiThesaurus::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
105 void GuiThesaurus::selectionClicked(QTreeWidgetItem * item, int col)
107 entryED->setText(item->text(col));
113 void GuiThesaurus::updateLists()
116 meaningsTV->setUpdatesEnabled(false);
118 Thesaurus::Meanings meanings = getMeanings(qstring_to_ucs4(entryED->text()));
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));
132 meaningsTV->setUpdatesEnabled(true);
133 meaningsTV->update();
137 void GuiThesaurus::updateContents()
139 entryED->setText(toqstr(text_));
140 replaceED->setText("");
145 void GuiThesaurus::replaceClicked()
147 replace(qstring_to_ucs4(replaceED->text()));
151 bool GuiThesaurus::initialiseParams(string const & data)
153 text_ = from_utf8(data);
158 void GuiThesaurus::clearParams()
164 void GuiThesaurus::replace(docstring const & newstr)
166 /* FIXME: this is not suitable ! We need to have a "lock"
167 * on a particular charpos in a paragraph that is broken on
170 docstring const data =
171 replace2string(text_, newstr,
172 true, // case sensitive
176 dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
180 Thesaurus::Meanings const & GuiThesaurus::getMeanings(docstring const & str)
183 meanings_ = thesaurus.lookup(str);
188 Dialog * createGuiThesaurus(GuiView & lv) { return new GuiThesaurus(lv); }
191 } // namespace frontend
195 #include "GuiThesaurus_moc.cpp"