]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QThesaurusDialog.C
enable Font cache only for MacOSX and inline width() for other platform.
[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 #include "debug.h"
17
18 #include "controllers/ControlThesaurus.h"
19
20 #include <QCloseEvent>
21 #include <QPushButton>
22 #include <QTreeWidget>
23 #include <QTreeWidgetItem>
24 #include <QLineEdit>
25 #include <QHeaderView>
26
27 using std::string;
28
29 namespace lyx {
30 namespace frontend {
31
32
33 QThesaurusDialog::QThesaurusDialog(QThesaurus * form)
34         : form_(form)
35 {
36         setupUi(this);
37
38         meaningsTV->setColumnCount(1);
39         meaningsTV->header()->hide();
40
41         connect(closePB, SIGNAL(clicked()),
42                 form, SLOT(slotClose()));
43         connect( replaceED, SIGNAL( returnPressed() ),
44                 this, SLOT( replaceClicked() ) );
45         connect( replaceED, SIGNAL( textChanged(const QString&) ),
46                 this, SLOT( change_adaptor() ) );
47         connect( entryED, SIGNAL( returnPressed() ),
48                 this, SLOT( entryChanged() ) );
49         connect( replacePB, SIGNAL( clicked() ),
50                 this, SLOT( replaceClicked() ) );
51         connect( meaningsTV, SIGNAL( itemClicked(QTreeWidgetItem * , int) ),
52                 this, SLOT( itemClicked(QTreeWidgetItem * , int) ) );
53         connect( meaningsTV, SIGNAL( itemSelectionChanged() ),
54                 this, SLOT( selectionChanged() ) );
55         connect( meaningsTV, SIGNAL( itemActivated(QTreeWidgetItem * , int) ),
56                 this, SLOT( selectionClicked(QTreeWidgetItem *, int) ) );
57 }
58
59
60 void QThesaurusDialog::change_adaptor()
61 {
62         form_->changed();
63 }
64
65
66 void QThesaurusDialog::closeEvent(QCloseEvent * e)
67 {
68         form_->slotWMHide();
69         e->accept();
70 }
71
72
73 void QThesaurusDialog::entryChanged()
74 {
75         updateLists();
76 }
77
78
79 void QThesaurusDialog::replaceClicked()
80 {
81         form_->replace();
82 }
83
84
85 void QThesaurusDialog::selectionChanged()
86 {
87         int const col = meaningsTV->currentColumn();
88         if (col<0 || form_->readOnly())
89                 return;
90
91         replaceED->setText(meaningsTV->currentItem()->text(col));
92         replacePB->setEnabled(true);
93         form_->changed();
94 }
95
96
97 void QThesaurusDialog::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
98 {
99         selectionChanged();
100 }
101
102
103 void QThesaurusDialog::selectionClicked(QTreeWidgetItem * item, int col)
104 {
105         entryED->setText(item->text(col));
106         selectionChanged();
107         updateLists();
108 }
109
110
111 void QThesaurusDialog::updateLists()
112 {
113         meaningsTV->clear();
114         meaningsTV->setUpdatesEnabled(false);
115
116         Thesaurus::Meanings meanings = form_->controller().getMeanings(fromqstr(entryED->text()));
117
118         for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
119                 cit != meanings.end(); ++cit) {
120                 QTreeWidgetItem * i = new QTreeWidgetItem(meaningsTV);
121                 i->setText(0, toqstr(cit->first));
122                 meaningsTV->expandItem(i);
123                 for (std::vector<string>::const_iterator cit2 = cit->second.begin();
124                         cit2 != cit->second.end(); ++cit2) {
125                                 QTreeWidgetItem * i2 = new QTreeWidgetItem(i);
126                                 i2->setText(0, toqstr(*cit2));
127                         }
128         }
129
130         meaningsTV->setUpdatesEnabled(true);
131         meaningsTV->update();
132 }
133
134 } // namespace frontend
135 } // namespace lyx
136
137 #include "QThesaurusDialog_moc.cpp"