]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiPrintNomencl.cpp
Few string fixes from Dan.
[lyx.git] / src / frontends / qt / 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         changed();
59 }
60
61
62 void GuiPrintNomencl::paramsToDialog(InsetCommandParams const & params)
63 {
64         setWidthCO->setCurrentIndex(
65                 setWidthCO->findData(toqstr(params["set_width"])));
66
67         lengthToWidgets(valueLE, unitLC,
68                         params["width"], Length::defaultUnit());
69 }
70
71
72 void GuiPrintNomencl::paramsToDialog(Inset const * inset)
73 {
74         InsetNomencl const * nomencl = static_cast<InsetNomencl const *>(inset);
75         paramsToDialog(nomencl->params());
76 }
77
78
79 docstring GuiPrintNomencl::dialogToParams() const
80 {
81         InsetCommandParams params(insetCode());
82         docstring const set_width = qstring_to_ucs4(setWidthCO->itemData(
83                 setWidthCO->currentIndex()).toString());
84         params["set_width"] = set_width;
85         docstring width;
86         if (set_width == from_ascii("custom"))
87                 width = from_utf8(widgetsToLength(valueLE, unitLC));
88         params["width"] = width;
89         return from_ascii(InsetNomencl::params2string(params));
90 }
91
92
93 bool GuiPrintNomencl::checkWidgets(bool readonly) const
94 {
95         valueLE->setReadOnly(readonly);
96         if (readonly) {
97                 setWidthCO->setEnabled(false);
98                 unitLC->setEnabled(false);
99                 valueLA->setEnabled(false);
100         } else {
101                 bool const custom =
102                         (setWidthCO->itemData(setWidthCO->currentIndex()).toString() == "custom");
103                 valueLE->setEnabled(custom);
104                 unitLC->setEnabled(custom);
105                 valueLA->setEnabled(custom);
106         }
107
108         if (!InsetParamsWidget::checkWidgets())
109                 return false;
110         return setWidthCO->itemData(
111                         setWidthCO->currentIndex()).toString() != "custom"
112                 || !valueLE->text().isEmpty();
113 }
114
115 } // namespace frontend
116 } // namespace lyx
117
118
119 #include "moc_GuiPrintNomencl.cpp"