2 * \file QThesaurusDialog.C
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 "QThesaurusDialog.h"
14 #include "QThesaurus.h"
15 #include "qt_helpers.h"
18 #include "controllers/ControlThesaurus.h"
20 #include <QCloseEvent>
21 #include <QPushButton>
22 #include <QTreeWidget>
23 #include <QTreeWidgetItem>
25 #include <QHeaderView>
33 QThesaurusDialog::QThesaurusDialog(QThesaurus * form)
38 meaningsTV->setColumnCount(1);
39 meaningsTV->header()->hide();
41 connect(closePB, SIGNAL(clicked()),
42 form, SLOT(slotClose()));
43 connect( replaceED, SIGNAL( returnPressed() ),
44 this, SLOT( replaceClicked() ) );
45 connect( replaceED, SIGNAL( textChanged(const QString&) ),
46 this, SLOT( change_adaptor() ) );
47 connect( entryED, SIGNAL( returnPressed() ),
48 this, SLOT( entryChanged() ) );
49 connect( replacePB, SIGNAL( clicked() ),
50 this, SLOT( replaceClicked() ) );
51 connect( meaningsTV, SIGNAL( itemClicked(QTreeWidgetItem * , int) ),
52 this, SLOT( itemClicked(QTreeWidgetItem * , int) ) );
53 connect( meaningsTV, SIGNAL( itemSelectionChanged() ),
54 this, SLOT( selectionChanged() ) );
55 connect( meaningsTV, SIGNAL( itemActivated(QTreeWidgetItem * , int) ),
56 this, SLOT( selectionClicked(QTreeWidgetItem *, int) ) );
60 void QThesaurusDialog::change_adaptor()
66 void QThesaurusDialog::closeEvent(QCloseEvent * e)
73 void QThesaurusDialog::entryChanged()
79 void QThesaurusDialog::replaceClicked()
85 void QThesaurusDialog::selectionChanged()
87 int const col = meaningsTV->currentColumn();
88 if (col<0 || form_->readOnly())
91 replaceED->setText(meaningsTV->currentItem()->text(col));
92 replacePB->setEnabled(true);
97 void QThesaurusDialog::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
103 void QThesaurusDialog::selectionClicked(QTreeWidgetItem * item, int col)
105 entryED->setText(item->text(col));
111 void QThesaurusDialog::updateLists()
114 meaningsTV->setUpdatesEnabled(false);
116 Thesaurus::Meanings meanings = form_->controller().getMeanings(fromqstr(entryED->text()));
118 for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
119 cit != meanings.end(); ++cit) {
120 QTreeWidgetItem * i = new QTreeWidgetItem(meaningsTV);
121 i->setText(0, toqstr(cit->first));
122 meaningsTV->expandItem(i);
123 for (std::vector<string>::const_iterator cit2 = cit->second.begin();
124 cit2 != cit->second.end(); ++cit2) {
125 QTreeWidgetItem * i2 = new QTreeWidgetItem(i);
126 i2->setText(0, toqstr(*cit2));
130 meaningsTV->setUpdatesEnabled(true);
131 meaningsTV->update();
134 } // namespace frontend
137 #include "QThesaurusDialog_moc.cpp"