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