2 * \file GuiPrintNomencl.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jürgen Spitzmüller
9 * Full author contact details are available in file CREDITS.
14 #include "GuiPrintNomencl.h"
16 #include "LengthCombo.h"
17 #include "qt_helpers.h"
18 #include "Validator.h"
21 #include "FuncRequest.h"
23 #include "insets/InsetNomencl.h"
25 #include "support/debug.h"
26 #include "support/gettext.h"
27 #include "support/lstrings.h"
30 #include <QPushButton>
38 GuiPrintNomencl::GuiPrintNomencl(GuiView
& lv
)
39 : GuiDialog(lv
, "nomencl_print", qt_("Nomenclature settings")),
40 params_(insetCode("nomencl_print"))
44 connect(okPB
, SIGNAL(clicked()), this, SLOT(slotOK()));
45 connect(applyPB
, SIGNAL(clicked()), this, SLOT(slotApply()));
46 connect(closePB
, SIGNAL(clicked()), this, SLOT(slotClose()));
48 connect(valueLE
, SIGNAL(textChanged(QString
)),
49 this, SLOT(change_adaptor()));
50 connect(unitLC
, SIGNAL(selectionChanged(lyx::Length::UNIT
)),
51 this, SLOT(change_adaptor()));
53 valueLE
->setValidator(unsignedLengthValidator(valueLE
));
55 // Manage the ok, apply, restore and cancel/close buttons
56 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy
);
58 bc().setApply(applyPB
);
59 bc().setCancel(closePB
);
61 // disable for read-only documents
62 bc().addReadOnly(valueLE
);
63 bc().addReadOnly(unitLC
);
65 // initialize the length validator
66 bc().addCheckedLineEdit(valueLE
, valueLA
);
68 setWidthCO
->addItem(qt_("Predefined"),
69 QVariant(toqstr("none")));
70 setWidthCO
->addItem(qt_("Auto-determined"),
71 QVariant(toqstr("auto")));
72 setWidthCO
->addItem(qt_("Custom"),
73 QVariant(toqstr("custom")));
77 void GuiPrintNomencl::change_adaptor()
83 void GuiPrintNomencl::on_setWidthCO_activated(int i
)
86 (setWidthCO
->itemData(i
).toString()
88 valueLE
->setEnabled(custom
);
89 unitLC
->setEnabled(custom
);
90 valueLA
->setEnabled(custom
);
95 void GuiPrintNomencl::paramsToDialog(InsetCommandParams
const & /*icp*/)
97 setWidthCO
->setCurrentIndex(
98 setWidthCO
->findData(toqstr(params_
["set_width"])));
100 lengthToWidgets(valueLE
,
103 Length::defaultUnit());
105 bc().setValid(isValid());
109 void GuiPrintNomencl::updateContents()
111 bool const custom
= (setWidthCO
->itemData(
112 setWidthCO
->currentIndex()).toString()
114 valueLE
->setEnabled(custom
);
115 unitLC
->setEnabled(custom
);
116 valueLA
->setEnabled(custom
);
120 void GuiPrintNomencl::applyView()
122 docstring
const set_width
= qstring_to_ucs4(setWidthCO
->itemData(
123 setWidthCO
->currentIndex()).toString());
124 params_
["set_width"] = set_width
;
126 if (set_width
== from_ascii("custom"))
127 width
= from_utf8(widgetsToLength(valueLE
, unitLC
));
128 params_
["width"] = width
;
132 bool GuiPrintNomencl::isValid()
134 return (setWidthCO
->itemData(
135 setWidthCO
->currentIndex()).toString() != "custom"
136 || !valueLE
->text().isEmpty());
140 bool GuiPrintNomencl::initialiseParams(std::string
const & data
)
142 InsetCommand::string2params("nomencl_print", data
, params_
);
143 paramsToDialog(params_
);
148 void GuiPrintNomencl::dispatchParams()
150 std::string
const lfun
= InsetCommand::params2string("nomencl_print", params_
);
151 dispatch(FuncRequest(getLfun(), lfun
));
156 Dialog
* createGuiPrintNomencl(GuiView
& lv
)
158 return new GuiPrintNomencl(lv
);
162 } // namespace frontend
166 #include "moc_GuiPrintNomencl.cpp"