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