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.
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 QVSpaceDialog::QVSpaceDialog(QVSpace * 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 QVSpaceDialog::closeEvent(QCloseEvent * e)
86 void QVSpaceDialog::change_adaptor()
92 void QVSpaceDialog::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 typedef QController<ControlVSpace, QView<QVSpaceDialog> > VSpaceBase;
187 QVSpace::QVSpace(Dialog & parent)
188 : VSpaceBase(parent, _("Vertical Space Settings"))
192 void QVSpace::build_dialog()
195 dialog_.reset(new QVSpaceDialog(this));
197 // Manage the ok, apply, restore and cancel/close buttons
198 bcview().setOK(dialog_->okPB);
199 bcview().setApply(dialog_->applyPB);
200 bcview().setCancel(dialog_->closePB);
202 // disable for read-only documents
203 bcview().addReadOnly(dialog_->spacingCO);
204 bcview().addReadOnly(dialog_->valueLE);
205 bcview().addReadOnly(dialog_->unitCO);
206 bcview().addReadOnly(dialog_->keepCB);
208 // initialize the length validator
209 addCheckedLineEdit(bcview(), dialog_->valueLE, dialog_->valueL);
211 // remove the %-items from the unit choice
212 dialog_->unitCO->noPercents();
216 void QVSpace::apply()
219 // If a vspace choice is "Length" but there's no text in
220 // the input field, do not insert a vspace at all.
221 if (dialog_->spacingCO->currentIndex() == 5
222 && dialog_->valueLE->text().isEmpty())
226 setVSpaceFromWidgets(dialog_->spacingCO->currentIndex(),
229 dialog_->keepCB->isChecked());
231 controller().params() = space;
235 void QVSpace::update_contents()
237 setWidgetsFromVSpace(controller().params(),
244 } // namespace frontend
248 #include "QVSpace_moc.cpp"