]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QThesaurusDialog.C
reverse last change
[lyx.git] / src / frontends / qt2 / QThesaurusDialog.C
1 /**
2  * \file QThesaurusDialog.C
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 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "LString.h"
18
19 #include "ControlThesaurus.h"
20 #include "QThesaurusDialog.h"
21 #include "QThesaurus.h"
22 #include "qt_helpers.h"
23
24 #include <qpushbutton.h>
25 #include <qlistview.h>
26 #include <qlineedit.h>
27
28 #include <vector>
29
30
31 QThesaurusDialog::QThesaurusDialog(QThesaurus * form)
32         : QThesaurusDialogBase(0, 0, false, 0),
33         form_(form)
34 {
35         connect(closePB, SIGNAL(clicked()),
36                 form, SLOT(slotClose()));
37 }
38
39
40 void QThesaurusDialog::change_adaptor()
41 {
42         form_->changed();
43 }
44
45
46 void QThesaurusDialog::closeEvent(QCloseEvent * e)
47 {
48         form_->slotWMHide();
49         e->accept();
50 }
51
52
53 void QThesaurusDialog::entryChanged()
54 {
55         updateLists();
56 }
57
58
59 void QThesaurusDialog::replaceClicked()
60 {
61         form_->replace();
62 }
63
64
65 void QThesaurusDialog::selectionChanged(QListViewItem * item)
66 {
67         if (form_->readOnly())
68                 return;
69
70         string const entry(fromqstr(item->text(0)));
71         replaceED->setText(toqstr(entry));
72         replacePB->setEnabled(true);
73         form_->changed();
74 }
75
76
77 void QThesaurusDialog::selectionClicked(QListViewItem * item)
78 {
79         entryED->setText(item->text(0));
80         selectionChanged(item);
81         updateLists();
82 }
83
84
85 void QThesaurusDialog::updateLists()
86 {
87         meaningsLV->clear();
88
89         std::vector<string> matches;
90
91         meaningsLV->setUpdatesEnabled(false);
92
93         Thesaurus::Meanings meanings = form_->controller().getMeanings(fromqstr(entryED->text()));
94
95         for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
96                 cit != meanings.end(); ++cit) {
97                 QListViewItem * i = new QListViewItem(meaningsLV);
98                 i->setText(0, toqstr(cit->first));
99                 i->setOpen(true);
100                 for (std::vector<string>::const_iterator cit2 = cit->second.begin();
101                         cit2 != cit->second.end(); ++cit2) {
102                                 QListViewItem * i2 = new QListViewItem(i);
103                                 i2->setText(0, toqstr(*cit2));
104                                 i2->setOpen(true);
105                         }
106         }
107
108         meaningsLV->setUpdatesEnabled(true);
109         meaningsLV->update();
110 }