]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiNomencl.cpp
c244354e8c1b6a848798d741b505efc64aa7bb42
[lyx.git] / src / frontends / qt4 / GuiNomencl.cpp
1 /**
2  * \file GuiNomencl.cpp
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  * \author O. U. Baran
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiNomencl.h"
15
16 #include "debug.h"
17 #include "ControlCommand.h"
18 #include "qt_helpers.h"
19
20 #include <QLabel>
21 #include <QLineEdit>
22 #include <QPushButton>
23 #include <QTextEdit>
24 #include <QWhatsThis>
25 #include <QCloseEvent>
26
27 using std::string;
28
29 namespace lyx {
30 namespace frontend {
31
32 GuiNomenclDialog::GuiNomenclDialog(LyXView & lv)
33         : GuiDialog(lv, "nomenclature")
34 {
35         setupUi(this);
36         setController(new ControlCommand(*this, "nomenclature", "nomenclature"));
37
38         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
39         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
40         connect(symbolED, SIGNAL(textChanged(const QString&)),
41                 this, SLOT(change_adaptor()));
42         connect(descriptionTE, SIGNAL(textChanged()),
43                 this, SLOT(change_adaptor()));
44
45         setFocusProxy(descriptionTE);
46
47         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
48         bc().setOK(okPB);
49         bc().setCancel(closePB);
50         bc().addReadOnly(symbolED);
51         bc().addReadOnly(descriptionTE);
52         bc().addReadOnly(prefixED);
53 }
54
55
56 ControlCommand & GuiNomenclDialog::controller() const
57 {
58         return static_cast<ControlCommand &>(Dialog::controller());
59 }
60
61
62 void GuiNomenclDialog::showView()
63 {
64         QDialog::show();
65 }
66
67
68 void GuiNomenclDialog::change_adaptor()
69 {
70         changed();
71 }
72
73
74 void GuiNomenclDialog::reject()
75 {
76         slotClose();
77 }
78
79
80 void GuiNomenclDialog::closeEvent(QCloseEvent * e)
81 {
82         slotWMHide();
83         e->accept();
84 }
85
86
87 void GuiNomenclDialog::update_contents()
88 {
89         prefixED->setText(toqstr(controller().params()["prefix"]));
90         symbolED->setText(toqstr(controller().params()["symbol"]));
91         QString description = toqstr(controller().params()["description"]);
92         description.replace("\\\\","\n");
93         descriptionTE->setPlainText(description);
94
95         bc().setValid(isValid());
96 }
97
98
99 void GuiNomenclDialog::applyView()
100 {
101         controller().params()["prefix"] = qstring_to_ucs4(prefixED->text());
102         controller().params()["symbol"] = qstring_to_ucs4(symbolED->text());
103         QString description = descriptionTE->toPlainText();
104         description.replace('\n',"\\\\");
105         controller().params()["description"] = qstring_to_ucs4(description);
106 }
107
108
109 bool GuiNomenclDialog::isValid()
110 {
111         QString const description = descriptionTE->toPlainText();
112         return !symbolED->text().isEmpty() && !description.isEmpty();
113 }
114
115 } // namespace frontend
116 } // namespace lyx
117
118 #include "GuiNomencl_moc.cpp"