GuiPrintNomencl.{cpp,h}:
[lyx.git] / src / frontends / qt4 / GuiPrintNomencl.cpp
bloba63866b703f329f44d7b230968ee888b149a4fcd
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.
6 * \author Jürgen Spitzmüller
7 * \author Uwe Stöhr
9 * Full author contact details are available in file CREDITS.
12 #include <config.h>
14 #include "GuiPrintNomencl.h"
16 #include "LengthCombo.h"
17 #include "qt_helpers.h"
18 #include "Validator.h"
20 #include "Spacing.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"
29 #include <QLineEdit>
30 #include <QPushButton>
31 #include <QValidator>
33 using namespace std;
35 namespace lyx {
36 namespace frontend {
38 GuiPrintNomencl::GuiPrintNomencl(GuiView & lv)
39 : GuiDialog(lv, "nomencl_print", qt_("Nomenclature settings")),
40 params_(insetCode("nomencl_print"))
42 setupUi(this);
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);
57 bc().setOK(okPB);
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()
79 changed();
83 void GuiPrintNomencl::on_setWidthCO_activated(int i)
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();
95 void GuiPrintNomencl::paramsToDialog(InsetCommandParams const & /*icp*/)
97 setWidthCO->setCurrentIndex(
98 setWidthCO->findData(toqstr(params_["set_width"])));
100 lengthToWidgets(valueLE,
101 unitLC,
102 params_["width"],
103 Length::defaultUnit());
105 bc().setValid(isValid());
109 void GuiPrintNomencl::updateContents()
111 bool const custom = (setWidthCO->itemData(
112 setWidthCO->currentIndex()).toString()
113 == "custom");
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;
125 docstring 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_);
144 return true;
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
163 } // namespace lyx
166 #include "moc_GuiPrintNomencl.cpp"