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