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