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"
21 #include "CheckedLineEdit.h"
22 #include "LengthCombo.h"
23 #include "qt_helpers.h"
24 #include "Validator.h"
26 #include "LyXRC.h" // to set the default length values
30 #include "controllers/ControlVSpace.h"
31 #include "controllers/frontend_helpers.h"
33 #include "support/lstrings.h"
36 #include <QCloseEvent>
38 #include <QPushButton>
48 /////////////////////////////////////////////////////////////////////
52 /////////////////////////////////////////////////////////////////////
55 GuiVSpaceDialog::GuiVSpaceDialog(GuiVSpace * form)
60 connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
61 connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
62 connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
64 connect(spacingCO, SIGNAL(highlighted(const QString &)),
65 this, SLOT(change_adaptor()));
66 connect(valueLE, SIGNAL(textChanged(const QString &)),
67 this, SLOT(change_adaptor()));
68 connect(spacingCO, SIGNAL(activated(int)),
69 this, SLOT(enableCustom(int)));
70 connect(keepCB, SIGNAL(clicked()),
71 this, SLOT(change_adaptor()));
72 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
73 this, SLOT(change_adaptor()));
75 valueLE->setValidator(unsignedLengthValidator(valueLE));
79 void GuiVSpaceDialog::closeEvent(QCloseEvent * e)
86 void GuiVSpaceDialog::change_adaptor()
92 void GuiVSpaceDialog::enableCustom(int selection)
94 bool const enable = selection == 5;
95 valueLE->setEnabled(enable);
96 unitCO->setEnabled(enable);
100 /////////////////////////////////////////////////////////////////////
104 /////////////////////////////////////////////////////////////////////
106 static void setWidgetsFromVSpace(VSpace const & space,
113 switch (space.kind()) {
114 case VSpace::DEFSKIP:
117 case VSpace::SMALLSKIP:
120 case VSpace::MEDSKIP:
123 case VSpace::BIGSKIP:
133 spacing->setCurrentIndex(item);
134 keep->setChecked(space.keep());
136 Length::UNIT default_unit =
137 (lyxrc.default_papersize > 3) ? Length::CM : Length::IN;
138 bool const custom_vspace = space.kind() == VSpace::LENGTH;
140 value->setEnabled(true);
141 unit->setEnabled(true);
142 string length = space.length().asString();
143 lengthToWidgets(value, unit, length, default_unit);
145 lengthToWidgets(value, unit, "", default_unit);
146 value->setEnabled(false);
147 unit->setEnabled(false);
152 static VSpace setVSpaceFromWidgets(int spacing,
161 space = VSpace(VSpace::DEFSKIP);
164 space = VSpace(VSpace::SMALLSKIP);
167 space = VSpace(VSpace::MEDSKIP);
170 space = VSpace(VSpace::BIGSKIP);
173 space = VSpace(VSpace::VFILL);
176 space = VSpace(GlueLength(widgetsToLength(value, unit)));
185 GuiVSpace::GuiVSpace(Dialog & parent)
186 : GuiView<GuiVSpaceDialog>(parent, _("Vertical Space Settings"))
190 void GuiVSpace::build_dialog()
193 dialog_.reset(new GuiVSpaceDialog(this));
195 // Manage the ok, apply, restore and cancel/close buttons
196 bcview().setOK(dialog_->okPB);
197 bcview().setApply(dialog_->applyPB);
198 bcview().setCancel(dialog_->closePB);
200 // disable for read-only documents
201 bcview().addReadOnly(dialog_->spacingCO);
202 bcview().addReadOnly(dialog_->valueLE);
203 bcview().addReadOnly(dialog_->unitCO);
204 bcview().addReadOnly(dialog_->keepCB);
206 // initialize the length validator
207 addCheckedLineEdit(bcview(), dialog_->valueLE, dialog_->valueL);
209 // remove the %-items from the unit choice
210 dialog_->unitCO->noPercents();
214 void GuiVSpace::apply()
217 // If a vspace choice is "Length" but there's no text in
218 // the input field, do not insert a vspace at all.
219 if (dialog_->spacingCO->currentIndex() == 5
220 && dialog_->valueLE->text().isEmpty())
224 setVSpaceFromWidgets(dialog_->spacingCO->currentIndex(),
227 dialog_->keepCB->isChecked());
229 controller().params() = space;
233 void GuiVSpace::update_contents()
235 setWidgetsFromVSpace(controller().params(),
242 } // namespace frontend
246 #include "GuiVSpace_moc.cpp"