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 "QThesaurus.h"
15 #include "qt_helpers.h"
18 #include "controllers/ControlThesaurus.h"
20 #include <QHeaderView>
22 #include <QPushButton>
23 #include <QTreeWidget>
24 #include <QTreeWidgetItem>
31 /////////////////////////////////////////////////////////////////////
35 /////////////////////////////////////////////////////////////////////
37 QThesaurusDialog::QThesaurusDialog(QThesaurus * form)
42 meaningsTV->setColumnCount(1);
43 meaningsTV->header()->hide();
45 connect(closePB, SIGNAL(clicked()),
46 form, SLOT(slotClose()));
47 connect(replaceED, SIGNAL(returnPressed()),
48 this, SLOT(replaceClicked()));
49 connect(replaceED, SIGNAL(textChanged(const QString &)),
50 this, SLOT(change_adaptor() ) );
51 connect(entryED, SIGNAL(returnPressed()),
52 this, SLOT(entryChanged()));
53 connect(replacePB, SIGNAL(clicked()),
54 this, SLOT(replaceClicked()));
55 connect(meaningsTV, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
56 this, SLOT(itemClicked(QTreeWidgetItem *, int)));
57 connect(meaningsTV, SIGNAL(itemSelectionChanged()),
58 this, SLOT(selectionChanged()));
59 connect(meaningsTV, SIGNAL(itemActivated(QTreeWidgetItem *, int)),
60 this, SLOT(selectionClicked(QTreeWidgetItem *, int)));
64 void QThesaurusDialog::change_adaptor()
70 void QThesaurusDialog::closeEvent(QCloseEvent * e)
77 void QThesaurusDialog::entryChanged()
83 void QThesaurusDialog::replaceClicked()
89 void QThesaurusDialog::selectionChanged()
91 int const col = meaningsTV->currentColumn();
92 if (col<0 || form_->readOnly())
95 replaceED->setText(meaningsTV->currentItem()->text(col));
96 replacePB->setEnabled(true);
101 void QThesaurusDialog::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
107 void QThesaurusDialog::selectionClicked(QTreeWidgetItem * item, int col)
109 entryED->setText(item->text(col));
115 void QThesaurusDialog::updateLists()
118 meaningsTV->setUpdatesEnabled(false);
120 Thesaurus::Meanings meanings = form_->controller().getMeanings(qstring_to_ucs4(entryED->text()));
122 for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
123 cit != meanings.end(); ++cit) {
124 QTreeWidgetItem * i = new QTreeWidgetItem(meaningsTV);
125 i->setText(0, toqstr(cit->first));
126 meaningsTV->expandItem(i);
127 for (std::vector<docstring>::const_iterator cit2 = cit->second.begin();
128 cit2 != cit->second.end(); ++cit2) {
129 QTreeWidgetItem * i2 = new QTreeWidgetItem(i);
130 i2->setText(0, toqstr(*cit2));
134 meaningsTV->setUpdatesEnabled(true);
135 meaningsTV->update();
139 /////////////////////////////////////////////////////////////////////
143 /////////////////////////////////////////////////////////////////////
145 typedef QController<ControlThesaurus, QView<QThesaurusDialog> > ThesaurusBase;
147 QThesaurus::QThesaurus(Dialog & parent)
148 : ThesaurusBase(parent, _("Thesaurus"))
153 void QThesaurus::build_dialog()
155 dialog_.reset(new QThesaurusDialog(this));
157 bcview().setCancel(dialog_->closePB);
158 bcview().setApply(dialog_->replacePB);
159 bcview().addReadOnly(dialog_->replaceED);
160 bcview().addReadOnly(dialog_->replacePB);
164 void QThesaurus::update_contents()
166 dialog_->entryED->setText(toqstr(controller().text()));
167 dialog_->replaceED->setText("");
168 dialog_->updateLists();
172 void QThesaurus::replace()
174 controller().replace(qstring_to_ucs4(dialog_->replaceED->text()));
177 } // namespace frontend
181 #include "QThesaurus_moc.cpp"