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 "GuiNomenclature.h"
15
16 #include "qt_helpers.h"
17
18 #include "insets/InsetNomencl.h"
19
20 using namespace std;
21
22 namespace lyx {
23 namespace frontend {
24
GuiNomenclature(QWidget * parent)25 GuiNomenclature::GuiNomenclature(QWidget * parent) : InsetParamsWidget(parent)
26 {
27 setupUi(this);
28 connect(symbolED, SIGNAL(textChanged(QString)),
29 this, SIGNAL(changed()));
30 connect(descriptionTE, SIGNAL(textChanged()),
31 this, SIGNAL(changed()));
32 connect(literalCB, SIGNAL(clicked()),
33 this, SIGNAL(changed()));
34
35 setFocusProxy(descriptionTE);
36 }
37
38
paramsToDialog(Inset const * inset)39 void GuiNomenclature::paramsToDialog(Inset const * inset)
40 {
41 InsetNomencl const * nomencl = static_cast<InsetNomencl const *>(inset);
42 InsetCommandParams const & params = nomencl->params();
43
44 prefixED->setText(toqstr(params["prefix"]));
45 symbolED->setText(toqstr(params["symbol"]));
46 literalCB->setChecked(params["literal"] == "true");
47 QString description = toqstr(params["description"]);
48 description.replace("\\\\","\n");
49 descriptionTE->setPlainText(description);
50 descriptionTE->setFocus();
51 }
52
53
dialogToParams() const54 docstring GuiNomenclature::dialogToParams() const
55 {
56 InsetCommandParams params(insetCode());
57 params["prefix"] = qstring_to_ucs4(prefixED->text());
58 params["symbol"] = qstring_to_ucs4(symbolED->text());
59 QString description = descriptionTE->toPlainText();
60 description.replace('\n',"\\\\");
61 params["description"] = qstring_to_ucs4(description);
62 params["literal"] = literalCB->isChecked()
63 ? from_ascii("true") : from_ascii("false");
64 return from_utf8(InsetNomencl::params2string(params));
65 }
66
67
initialiseParams(std::string const & data)68 bool GuiNomenclature::initialiseParams(std::string const & data)
69 {
70 InsetCommandParams p(insetCode());
71 if (!InsetCommand::string2params(data, p))
72 return false;
73 symbolED->setText(toqstr(p["symbol"]));
74 return true;
75 }
76
77
checkWidgets(bool readonly) const78 bool GuiNomenclature::checkWidgets(bool readonly) const
79 {
80 symbolED->setReadOnly(readonly);
81 descriptionTE->setReadOnly(readonly);
82 if (!InsetParamsWidget::checkWidgets())
83 return false;
84 QString const description = descriptionTE->toPlainText();
85 return !symbolED->text().isEmpty() && !description.isEmpty();
86 }
87
88 } // namespace frontend
89 } // namespace lyx
90
91 #include "moc_GuiNomenclature.cpp"
92