]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QThesaurusDialog.C
Get rid of the static_casts.
[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         // hide the pointless QHeader
33         QWidget * w = static_cast<QWidget*>(meaningsLV->child("list view header"));
34         if (w)
35                 w->hide();
36
37         connect(closePB, SIGNAL(clicked()),
38                 form, SLOT(slotClose()));
39 }
40
41
42 void QThesaurusDialog::change_adaptor()
43 {
44         form_->changed();
45 }
46
47
48 void QThesaurusDialog::closeEvent(QCloseEvent * e)
49 {
50         form_->slotWMHide();
51         e->accept();
52 }
53
54
55 void QThesaurusDialog::entryChanged()
56 {
57         updateLists();
58 }
59
60
61 void QThesaurusDialog::replaceClicked()
62 {
63         form_->replace();
64 }
65
66
67 void QThesaurusDialog::selectionChanged(QListViewItem * item)
68 {
69         if (form_->readOnly())
70                 return;
71
72         string const entry(fromqstr(item->text(0)));
73         replaceED->setText(toqstr(entry));
74         replacePB->setEnabled(true);
75         form_->changed();
76 }
77
78
79 void QThesaurusDialog::selectionClicked(QListViewItem * item)
80 {
81         entryED->setText(item->text(0));
82         selectionChanged(item);
83         updateLists();
84 }
85
86
87 void QThesaurusDialog::updateLists()
88 {
89         meaningsLV->clear();
90
91         std::vector<string> matches;
92
93         meaningsLV->setUpdatesEnabled(false);
94
95         Thesaurus::Meanings meanings = form_->controller().getMeanings(fromqstr(entryED->text()));
96
97         for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
98                 cit != meanings.end(); ++cit) {
99                 QListViewItem * i = new QListViewItem(meaningsLV);
100                 i->setText(0, toqstr(cit->first));
101                 i->setOpen(true);
102                 for (std::vector<string>::const_iterator cit2 = cit->second.begin();
103                         cit2 != cit->second.end(); ++cit2) {
104                                 QListViewItem * i2 = new QListViewItem(i);
105                                 i2->setText(0, toqstr(*cit2));
106                                 i2->setOpen(true);
107                         }
108         }
109
110         meaningsLV->setUpdatesEnabled(true);
111         meaningsLV->update();
112 }