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(unsignedLengthValidator(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);
79 // remove the %-items from the unit choice
84 void GuiVSpace::change_adaptor()
90 void GuiVSpace::enableCustom(int selection)
92 bool const enable = selection == 5;
93 valueLE->setEnabled(enable);
94 unitCO->setEnabled(enable);
98 static void setWidgetsFromVSpace(VSpace const & space,
105 switch (space.kind()) {
106 case VSpace::DEFSKIP: item = 0; break;
107 case VSpace::SMALLSKIP: item = 1; break;
108 case VSpace::MEDSKIP: item = 2; break;
109 case VSpace::BIGSKIP: item = 3; break;
110 case VSpace::VFILL: item = 4; break;
111 case VSpace::LENGTH: item = 5; break;
113 spacing->setCurrentIndex(item);
114 keep->setChecked(space.keep());
116 Length::UNIT const default_unit = Length::defaultUnit();
117 bool const custom_vspace = space.kind() == VSpace::LENGTH;
119 value->setEnabled(true);
120 unit->setEnabled(true);
121 string length = space.length().asString();
122 lengthToWidgets(value, unit, length, default_unit);
124 lengthToWidgets(value, unit, "", default_unit);
125 value->setEnabled(false);
126 unit->setEnabled(false);
131 static VSpace setVSpaceFromWidgets(int spacing,
132 QLineEdit * value, LengthCombo * unit, bool keep)
137 case 0: space = VSpace(VSpace::DEFSKIP); break;
138 case 1: space = VSpace(VSpace::SMALLSKIP); break;
139 case 2: space = VSpace(VSpace::MEDSKIP); break;
140 case 3: space = VSpace(VSpace::BIGSKIP); break;
141 case 4: space = VSpace(VSpace::VFILL); break;
142 case 5: space = VSpace(GlueLength(widgetsToLength(value, unit))); break;
150 void GuiVSpace::applyView()
152 // If a vspace choice is "Length" but there's no text in
153 // the input field, do not insert a vspace at all.
154 if (spacingCO->currentIndex() == 5 && valueLE->text().isEmpty())
157 params_ = setVSpaceFromWidgets(spacingCO->currentIndex(),
158 valueLE, unitCO, keepCB->isChecked());
162 void GuiVSpace::updateContents()
164 setWidgetsFromVSpace(params_, spacingCO, valueLE, unitCO, keepCB);
168 bool GuiVSpace::initialiseParams(string const & data)
170 InsetVSpace::string2params(data, params_);
171 setButtonsValid(true);
176 void GuiVSpace::clearParams()
182 void GuiVSpace::dispatchParams()
184 dispatch(FuncRequest(getLfun(), InsetVSpace::params2string(params_)));
188 Dialog * createGuiVSpace(GuiView & lv) { return new GuiVSpace(lv); }
191 } // namespace frontend
195 #include "moc_GuiVSpace.cpp"