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