]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiNomencl.cpp
move our stuff off the Q* namespace
[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 "debug.h"
15 #include "ControlCommand.h"
16 #include "qt_helpers.h"
17
18 #include "GuiNomencl.h"
19 #include "Qt2BC.h"
20 #include "ButtonController.h"
21 #include <QLabel>
22 #include <QLineEdit>
23 #include <QPushButton>
24 #include <QTextEdit>
25 #include <QWhatsThis>
26 #include <QCloseEvent>
27
28 using std::string;
29
30 namespace lyx {
31 namespace frontend {
32
33 /////////////////////////////////////////////////////////////////////
34 //
35 // GuiNomenclDialog
36 //
37 /////////////////////////////////////////////////////////////////////
38
39 GuiNomenclDialog::GuiNomenclDialog(GuiNomencl * form)
40         : form_(form)
41 {
42         setupUi(this);
43
44         connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
45         connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
46         connect(symbolED, SIGNAL(textChanged(const QString&)),
47                 this, SLOT(change_adaptor()));
48         connect(descriptionTE, SIGNAL(textChanged()),
49                 this, SLOT(change_adaptor()));
50
51         setFocusProxy(descriptionTE);
52 }
53
54
55 void GuiNomenclDialog::show()
56 {
57         QDialog::show();
58 }
59
60
61 void GuiNomenclDialog::change_adaptor()
62 {
63         form_->changed();
64 }
65
66
67 void GuiNomenclDialog::reject()
68 {
69         form_->slotClose();
70 }
71
72
73 void GuiNomenclDialog::closeEvent(QCloseEvent * e)
74 {
75         form_->slotWMHide();
76         e->accept();
77 }
78
79
80 /////////////////////////////////////////////////////////////////////
81 //
82 // GuiNomencl
83 //
84 /////////////////////////////////////////////////////////////////////
85
86
87 typedef QController<ControlCommand, GuiView<GuiNomenclDialog> > NomenBase;
88
89
90 GuiNomencl::GuiNomencl(Dialog & parent, docstring const & title)
91         : NomenBase(parent, title)
92 {
93 }
94
95
96 void GuiNomencl::build_dialog()
97 {
98         dialog_.reset(new GuiNomenclDialog(this));
99
100         bcview().setOK(dialog_->okPB);
101         bcview().setCancel(dialog_->closePB);
102         bcview().addReadOnly(dialog_->symbolED);
103         bcview().addReadOnly(dialog_->descriptionTE);
104         bcview().addReadOnly(dialog_->prefixED);
105 }
106
107
108 void GuiNomencl::update_contents()
109 {
110         dialog_->prefixED->setText(toqstr(controller().params()["prefix"]));
111         dialog_->symbolED->setText(toqstr(controller().params()["symbol"]));
112         QString description = toqstr(controller().params()["description"]);
113         description.replace("\\\\","\n");
114         dialog_->descriptionTE->setPlainText(description);
115
116         bc().valid(isValid());
117 }
118
119
120 void GuiNomencl::apply()
121 {
122         controller().params()["prefix"] = qstring_to_ucs4(dialog_->prefixED->text());
123         controller().params()["symbol"] = qstring_to_ucs4(dialog_->symbolED->text());
124         QString description = dialog_->descriptionTE->toPlainText();
125         description.replace('\n',"\\\\");
126         controller().params()["description"] = qstring_to_ucs4(description);
127 }
128
129
130 bool GuiNomencl::isValid()
131 {
132         QString const description = dialog_->descriptionTE->toPlainText();
133         return !dialog_->symbolED->text().isEmpty() && !description.isEmpty();
134 }
135
136 } // namespace frontend
137 } // namespace lyx
138
139 #include "GuiNomencl_moc.cpp"