]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPrintNomencl.cpp
Migrate GuiLine to InsetParamsWidget.
[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 #include <QLineEdit>
29 #include <QPushButton>
30 #include <QValidator>
31
32 using namespace std;
33
34 namespace lyx {
35 namespace frontend {
36
37 GuiPrintNomencl::GuiPrintNomencl(GuiView & lv)
38         : GuiDialog(lv, "nomencl_print", qt_("Nomenclature settings")),
39           params_(insetCode("nomencl_print"))
40 {
41         setupUi(this);
42
43         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
44         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
45         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
46
47         connect(valueLE, SIGNAL(textChanged(QString)),
48                 this, SLOT(change_adaptor()));
49         connect(unitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
50                 this, SLOT(change_adaptor()));
51
52         valueLE->setValidator(unsignedLengthValidator(valueLE));
53
54         // Manage the ok, apply, restore and cancel/close buttons
55         bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
56         bc().setOK(okPB);
57         bc().setApply(applyPB);
58         bc().setCancel(closePB);
59
60         // disable for read-only documents
61         bc().addReadOnly(valueLE);
62         bc().addReadOnly(unitLC);
63
64         // initialize the length validator
65         bc().addCheckedLineEdit(valueLE, valueLA);
66
67         setWidthCO->addItem(qt_("Default"),
68                 QVariant(toqstr("none")));
69         setWidthCO->addItem(qt_("Longest label width"),
70                 QVariant(toqstr("auto")));
71         setWidthCO->addItem(qt_("Custom"),
72                 QVariant(toqstr("custom")));
73 }
74
75
76 void GuiPrintNomencl::change_adaptor()
77 {
78         changed();
79 }
80
81
82 void GuiPrintNomencl::on_setWidthCO_activated(int i)
83 {
84         bool const custom =
85                 (setWidthCO->itemData(i).toString()
86                  == "custom");
87         valueLE->setEnabled(custom);
88         unitLC->setEnabled(custom);
89         valueLA->setEnabled(custom);
90         changed();
91 }
92
93
94 void GuiPrintNomencl::paramsToDialog(InsetCommandParams const & /*icp*/)
95 {
96         setWidthCO->setCurrentIndex(
97                 setWidthCO->findData(toqstr(params_["set_width"])));
98         
99         lengthToWidgets(valueLE,
100                         unitLC,
101                         params_["width"],
102                         Length::defaultUnit());
103
104         bc().setValid(isValid());
105 }
106
107
108 void GuiPrintNomencl::updateContents()
109 {
110         bool const custom = (setWidthCO->itemData(
111                                   setWidthCO->currentIndex()).toString()
112                              == "custom");
113         valueLE->setEnabled(custom);
114         unitLC->setEnabled(custom);
115         valueLA->setEnabled(custom);
116 }
117
118
119 void GuiPrintNomencl::applyView()
120 {
121         docstring const set_width = qstring_to_ucs4(setWidthCO->itemData(
122                 setWidthCO->currentIndex()).toString());
123         params_["set_width"] = set_width;
124         docstring width;
125         if (set_width == from_ascii("custom"))
126                 width = from_utf8(widgetsToLength(valueLE, unitLC));
127         params_["width"] = width;
128 }
129
130
131 bool GuiPrintNomencl::isValid() const
132 {
133         return setWidthCO->itemData(
134                         setWidthCO->currentIndex()).toString() != "custom"
135                 || !valueLE->text().isEmpty();
136 }
137
138
139 bool GuiPrintNomencl::initialiseParams(std::string const & data)
140 {
141         InsetCommand::string2params("nomencl_print", data, params_);
142         paramsToDialog(params_);
143         return true;
144 }
145
146
147 void GuiPrintNomencl::dispatchParams()
148 {
149         std::string const lfun = InsetCommand::params2string("nomencl_print", params_);
150         dispatch(FuncRequest(getLfun(), lfun));
151 }
152
153
154
155 Dialog * createGuiPrintNomencl(GuiView & lv)
156 {
157         return new GuiPrintNomencl(lv);
158 }
159
160
161 } // namespace frontend
162 } // namespace lyx
163
164
165 #include "moc_GuiPrintNomencl.cpp"