]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiNomencl.cpp
less functions
[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 &>(GuiDialog::controller());
59 }
60
61
62 void GuiNomenclDialog::change_adaptor()
63 {
64         changed();
65 }
66
67
68 void GuiNomenclDialog::reject()
69 {
70         slotClose();
71 }
72
73
74 void GuiNomenclDialog::closeEvent(QCloseEvent * e)
75 {
76         slotClose();
77         e->accept();
78 }
79
80
81 void GuiNomenclDialog::update_contents()
82 {
83         prefixED->setText(toqstr(controller().params()["prefix"]));
84         symbolED->setText(toqstr(controller().params()["symbol"]));
85         QString description = toqstr(controller().params()["description"]);
86         description.replace("\\\\","\n");
87         descriptionTE->setPlainText(description);
88
89         bc().setValid(isValid());
90 }
91
92
93 void GuiNomenclDialog::applyView()
94 {
95         controller().params()["prefix"] = qstring_to_ucs4(prefixED->text());
96         controller().params()["symbol"] = qstring_to_ucs4(symbolED->text());
97         QString description = descriptionTE->toPlainText();
98         description.replace('\n',"\\\\");
99         controller().params()["description"] = qstring_to_ucs4(description);
100 }
101
102
103 bool GuiNomenclDialog::isValid()
104 {
105         QString const description = descriptionTE->toPlainText();
106         return !symbolED->text().isEmpty() && !description.isEmpty();
107 }
108
109 } // namespace frontend
110 } // namespace lyx
111
112 #include "GuiNomencl_moc.cpp"