]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiNomencl.cpp
merge ButtonController and its view (Qt2BC in this case)
[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 /////////////////////////////////////////////////////////////////////
33 //
34 // GuiNomenclDialog
35 //
36 /////////////////////////////////////////////////////////////////////
37
38 GuiNomenclDialog::GuiNomenclDialog(GuiNomencl * form)
39         : form_(form)
40 {
41         setupUi(this);
42
43         connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
44         connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
45         connect(symbolED, SIGNAL(textChanged(const QString&)),
46                 this, SLOT(change_adaptor()));
47         connect(descriptionTE, SIGNAL(textChanged()),
48                 this, SLOT(change_adaptor()));
49
50         setFocusProxy(descriptionTE);
51 }
52
53
54 void GuiNomenclDialog::show()
55 {
56         QDialog::show();
57 }
58
59
60 void GuiNomenclDialog::change_adaptor()
61 {
62         form_->changed();
63 }
64
65
66 void GuiNomenclDialog::reject()
67 {
68         form_->slotClose();
69 }
70
71
72 void GuiNomenclDialog::closeEvent(QCloseEvent * e)
73 {
74         form_->slotWMHide();
75         e->accept();
76 }
77
78
79 /////////////////////////////////////////////////////////////////////
80 //
81 // GuiNomencl
82 //
83 /////////////////////////////////////////////////////////////////////
84
85
86 GuiNomencl::GuiNomencl(GuiDialog & parent, docstring const & title)
87         : GuiView<GuiNomenclDialog>(parent, title)
88 {
89 }
90
91
92 void GuiNomencl::build_dialog()
93 {
94         dialog_.reset(new GuiNomenclDialog(this));
95
96         bc().setOK(dialog_->okPB);
97         bc().setCancel(dialog_->closePB);
98         bc().addReadOnly(dialog_->symbolED);
99         bc().addReadOnly(dialog_->descriptionTE);
100         bc().addReadOnly(dialog_->prefixED);
101 }
102
103
104 void GuiNomencl::update_contents()
105 {
106         dialog_->prefixED->setText(toqstr(controller().params()["prefix"]));
107         dialog_->symbolED->setText(toqstr(controller().params()["symbol"]));
108         QString description = toqstr(controller().params()["description"]);
109         description.replace("\\\\","\n");
110         dialog_->descriptionTE->setPlainText(description);
111
112         bc().setValid(isValid());
113 }
114
115
116 void GuiNomencl::apply()
117 {
118         controller().params()["prefix"] = qstring_to_ucs4(dialog_->prefixED->text());
119         controller().params()["symbol"] = qstring_to_ucs4(dialog_->symbolED->text());
120         QString description = dialog_->descriptionTE->toPlainText();
121         description.replace('\n',"\\\\");
122         controller().params()["description"] = qstring_to_ucs4(description);
123 }
124
125
126 bool GuiNomencl::isValid()
127 {
128         QString const description = dialog_->descriptionTE->toPlainText();
129         return !dialog_->symbolED->text().isEmpty() && !description.isEmpty();
130 }
131
132 } // namespace frontend
133 } // namespace lyx
134
135 #include "GuiNomencl_moc.cpp"