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