3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * \author Angus Leeming
10 * \author Edwin Leuven
11 * \author Jürgen Spitzmüller
13 * Full author contact details are available in file CREDITS.
18 #include "GuiVSpace.h"
20 #include "LengthCombo.h"
21 #include "qt_helpers.h"
22 #include "Validator.h"
25 #include "FuncRequest.h"
27 #include "insets/InsetVSpace.h"
29 #include "support/gettext.h"
30 #include "support/lstrings.h"
34 #include <QPushButton>
42 GuiVSpace::GuiVSpace(GuiView & lv)
43 : GuiDialog(lv, "vspace", qt_("Vertical Space Settings"))
47 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
48 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
49 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
51 connect(spacingCO, SIGNAL(highlighted(QString)),
52 this, SLOT(change_adaptor()));
53 connect(valueLE, SIGNAL(textChanged(QString)),
54 this, SLOT(change_adaptor()));
55 connect(spacingCO, SIGNAL(activated(int)),
56 this, SLOT(enableCustom(int)));
57 connect(keepCB, SIGNAL(clicked()),
58 this, SLOT(change_adaptor()));
59 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
60 this, SLOT(change_adaptor()));
62 valueLE->setValidator(unsignedGlueLengthValidator(valueLE));
64 // Manage the ok, apply, restore and cancel/close buttons
65 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
67 bc().setApply(applyPB);
68 bc().setCancel(closePB);
70 // disable for read-only documents
71 bc().addReadOnly(spacingCO);
72 bc().addReadOnly(valueLE);
73 bc().addReadOnly(unitCO);
74 bc().addReadOnly(keepCB);
76 // initialize the length validator
77 bc().addCheckedLineEdit(valueLE, valueL);
81 void GuiVSpace::change_adaptor()
87 void GuiVSpace::enableCustom(int selection)
89 bool const enable = selection == 5;
90 valueLE->setEnabled(enable);
91 unitCO->setEnabled(enable);
95 static void setWidgetsFromVSpace(VSpace const & space,
102 switch (space.kind()) {
103 case VSpace::DEFSKIP: item = 0; break;
104 case VSpace::SMALLSKIP: item = 1; break;
105 case VSpace::MEDSKIP: item = 2; break;
106 case VSpace::BIGSKIP: item = 3; break;
107 case VSpace::VFILL: item = 4; break;
108 case VSpace::LENGTH: item = 5; break;
110 spacing->setCurrentIndex(item);
111 keep->setChecked(space.keep());
113 Length::UNIT const default_unit = Length::defaultUnit();
114 bool const custom_vspace = space.kind() == VSpace::LENGTH;
116 value->setEnabled(true);
117 unit->setEnabled(true);
118 string length = space.length().asString();
119 lengthToWidgets(value, unit, length, default_unit);
121 lengthToWidgets(value, unit, "", default_unit);
122 value->setEnabled(false);
123 unit->setEnabled(false);
128 static VSpace setVSpaceFromWidgets(int spacing,
129 QLineEdit * value, LengthCombo * unit, bool keep)
134 case 0: space = VSpace(VSpace::DEFSKIP); break;
135 case 1: space = VSpace(VSpace::SMALLSKIP); break;
136 case 2: space = VSpace(VSpace::MEDSKIP); break;
137 case 3: space = VSpace(VSpace::BIGSKIP); break;
138 case 4: space = VSpace(VSpace::VFILL); break;
139 case 5: space = VSpace(GlueLength(widgetsToLength(value, unit))); break;
147 void GuiVSpace::applyView()
149 // If a vspace choice is "Length" but there's no text in
150 // the input field, do not insert a vspace at all.
151 if (spacingCO->currentIndex() == 5 && valueLE->text().isEmpty())
154 params_ = setVSpaceFromWidgets(spacingCO->currentIndex(),
155 valueLE, unitCO, keepCB->isChecked());
159 void GuiVSpace::updateContents()
161 setWidgetsFromVSpace(params_, spacingCO, valueLE, unitCO, keepCB);
165 bool GuiVSpace::initialiseParams(string const & data)
167 InsetVSpace::string2params(data, params_);
168 setButtonsValid(true);
173 void GuiVSpace::clearParams()
179 void GuiVSpace::dispatchParams()
181 dispatch(FuncRequest(getLfun(), InsetVSpace::params2string(params_)));
185 Dialog * createGuiVSpace(GuiView & lv) { return new GuiVSpace(lv); }
188 } // namespace frontend
192 #include "moc_GuiVSpace.cpp"