]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPrintNomencl.cpp
Support for command argument placement after the workarea argument
[lyx.git] / src / frontends / qt4 / GuiPrintNomencl.cpp
1 /**
2  * \file GuiPrintNomencl.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Spitzmüller
7  * \author Uwe Stöhr
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiPrintNomencl.h"
15
16 #include "LengthCombo.h"
17 #include "qt_helpers.h"
18 #include "Validator.h"
19
20 #include "FuncRequest.h"
21
22 #include "insets/InsetNomencl.h"
23
24 #include "support/debug.h"
25 #include "support/gettext.h"
26 #include "support/lstrings.h"
27
28 using namespace std;
29
30 namespace lyx {
31 namespace frontend {
32
33 GuiPrintNomencl::GuiPrintNomencl(QWidget * parent) : InsetParamsWidget(parent)
34 {
35         setupUi(this);
36
37         connect(valueLE, SIGNAL(textChanged(QString)),
38                 this, SIGNAL(changed()));
39         connect(unitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
40                 this, SIGNAL(changed()));
41
42         valueLE->setValidator(unsignedLengthValidator(valueLE));
43
44         // initialize the length validator
45         addCheckedWidget(valueLE, valueLA);
46
47         setWidthCO->addItem(qt_("Default"),
48                 QVariant(toqstr("none")));
49         setWidthCO->addItem(qt_("Longest label width"),
50                 QVariant(toqstr("auto")));
51         setWidthCO->addItem(qt_("Custom"),
52                 QVariant(toqstr("custom")));
53 }
54
55
56 void GuiPrintNomencl::on_setWidthCO_activated(int i)
57 {
58         bool const custom =
59                 (setWidthCO->itemData(i).toString() == "custom");
60         valueLE->setEnabled(custom);
61         unitLC->setEnabled(custom);
62         valueLA->setEnabled(custom);
63         changed();
64 }
65
66
67 void GuiPrintNomencl::paramsToDialog(InsetCommandParams const & params)
68 {
69         setWidthCO->setCurrentIndex(
70                 setWidthCO->findData(toqstr(params["set_width"])));
71         
72         lengthToWidgets(valueLE, unitLC,
73                         params["width"], Length::defaultUnit());
74
75         bool const custom =
76                 (setWidthCO->itemData(setWidthCO->currentIndex()).toString() == "custom");
77         valueLE->setEnabled(custom);
78         unitLC->setEnabled(custom);
79         valueLA->setEnabled(custom);
80 }
81
82
83 void GuiPrintNomencl::paramsToDialog(Inset const * inset)
84 {
85         InsetNomencl const * nomencl = static_cast<InsetNomencl const *>(inset);
86         paramsToDialog(nomencl->params());
87 }
88
89
90 docstring GuiPrintNomencl::dialogToParams() const
91 {
92         InsetCommandParams params(insetCode());
93         docstring const set_width = qstring_to_ucs4(setWidthCO->itemData(
94                 setWidthCO->currentIndex()).toString());
95         params["set_width"] = set_width;
96         docstring width;
97         if (set_width == from_ascii("custom"))
98                 width = from_utf8(widgetsToLength(valueLE, unitLC));
99         params["width"] = width;
100         return from_ascii(InsetNomencl::params2string(params));
101 }
102
103
104 bool GuiPrintNomencl::checkWidgets() const
105 {
106         if (!InsetParamsWidget::checkWidgets())
107                 return false;
108         return setWidthCO->itemData(
109                         setWidthCO->currentIndex()).toString() != "custom"
110                 || !valueLE->text().isEmpty();
111 }
112
113 } // namespace frontend
114 } // namespace lyx
115
116
117 #include "moc_GuiPrintNomencl.cpp"