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