]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QThesaurusDialog.C
The initial merge of the Qt frontend, and the necessary compile fixes.
[lyx.git] / src / frontends / qt2 / QThesaurusDialog.C
1 /**
2  * \file QThesaurusDialog.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon <moz@compsoc.man.ac.uk>
7  */
8
9 #include <config.h>
10 #include <vector>
11
12 #include "LString.h"
13
14 #include "ControlThesaurus.h"
15 #include "QThesaurusDialog.h"
16 #include "QThesaurus.h"
17
18 #include <qpushbutton.h>
19 #include <qlistview.h>
20 #include <qlineedit.h>
21
22 QThesaurusDialog::QThesaurusDialog(QThesaurus * form)
23         : QThesaurusDialogBase(0, 0, false, 0),
24         form_(form)
25 {
26         connect(closePB, SIGNAL(clicked()),
27                 form, SLOT(slotClose()));
28 }
29
30
31 void QThesaurusDialog::change_adaptor()
32 {
33         form_->changed();
34 }
35
36
37 void QThesaurusDialog::closeEvent(QCloseEvent * e)
38 {
39         form_->slotWMHide();
40         e->accept();
41 }
42
43
44 void QThesaurusDialog::entryChanged()
45 {
46         updateLists();
47 }
48
49
50 void QThesaurusDialog::replaceClicked()
51 {
52         form_->replace();
53 }
54
55
56 void QThesaurusDialog::selectionChanged(QListViewItem * item)
57 {
58         if (form_->readOnly())
59                 return;
60
61         string const entry(item->text(0).latin1());
62         replaceED->setText(entry.c_str());
63         replacePB->setEnabled(true);
64         form_->changed();
65 }
66
67
68 void QThesaurusDialog::selectionClicked(QListViewItem * item)
69 {
70         entryED->setText(item->text(0));
71         selectionChanged(item);
72         updateLists();
73 }
74
75
76 void QThesaurusDialog::updateLists()
77 {
78         meaningsLV->clear();
79
80         std::vector<string> matches;
81
82         meaningsLV->setUpdatesEnabled(false);
83
84         Thesaurus::Meanings meanings = form_->controller().getMeanings(entryED->text().latin1());
85
86         for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
87                 cit != meanings.end(); ++cit) {
88                 QListViewItem * i = new QListViewItem(meaningsLV);
89                 i->setText(0, cit->first.c_str());
90                 i->setOpen(true);
91                 for (std::vector<string>::const_iterator cit2 = cit->second.begin();
92                         cit2 != cit->second.end(); ++cit2) {
93                                 QListViewItem * i2 = new QListViewItem(i);
94                                 i2->setText(0, cit2->c_str());
95                                 i2->setOpen(true);
96                         }
97         }
98
99         meaningsLV->setUpdatesEnabled(true);
100         meaningsLV->update();
101 }