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.
19 #include "QVSpaceDialog.h"
22 #include "checkedwidgets.h"
23 #include "lengthcombo.h"
24 #include "qt_helpers.h"
26 #include "lyxrc.h" // to set the default length values
30 #include "controllers/ControlVSpace.h"
31 #include "controllers/helper_funcs.h"
33 #include "support/lstrings.h"
37 #include <QPushButton>
47 void setWidgetsFromVSpace(VSpace const & space,
54 switch (space.kind()) {
58 case VSpace::SMALLSKIP:
74 spacing->setCurrentIndex(item);
75 keep->setChecked(space.keep());
77 LyXLength::UNIT default_unit =
78 (lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN;
79 bool const custom_vspace = space.kind() == VSpace::LENGTH;
81 value->setEnabled(true);
82 unit->setEnabled(true);
83 string length = space.length().asString();
84 lengthToWidgets(value, unit, length, default_unit);
86 lengthToWidgets(value, unit, "", default_unit);
87 value->setEnabled(false);
88 unit->setEnabled(false);
93 VSpace setVSpaceFromWidgets(int spacing,
102 space = VSpace(VSpace::DEFSKIP);
105 space = VSpace(VSpace::SMALLSKIP);
108 space = VSpace(VSpace::MEDSKIP);
111 space = VSpace(VSpace::BIGSKIP);
114 space = VSpace(VSpace::VFILL);
117 space = VSpace(LyXGlueLength(
118 widgetsToLength(value, unit)));
129 typedef QController<ControlVSpace, QView<QVSpaceDialog> > base_class;
131 QVSpace::QVSpace(Dialog & parent)
132 : base_class(parent, _("Vertical Space Settings"))
136 void QVSpace::build_dialog()
139 dialog_.reset(new QVSpaceDialog(this));
141 // Manage the ok, apply, restore and cancel/close buttons
142 bcview().setOK(dialog_->okPB);
143 bcview().setApply(dialog_->applyPB);
144 bcview().setCancel(dialog_->closePB);
146 // disable for read-only documents
147 bcview().addReadOnly(dialog_->spacingCO);
148 bcview().addReadOnly(dialog_->valueLE);
149 bcview().addReadOnly(dialog_->unitCO);
150 bcview().addReadOnly(dialog_->keepCB);
152 // initialize the length validator
153 addCheckedLineEdit(bcview(), dialog_->valueLE, dialog_->valueL);
155 // remove the %-items from the unit choice
156 dialog_->unitCO->noPercents();
160 void QVSpace::apply()
163 // If a vspace choice is "Length" but there's no text in
164 // the input field, do not insert a vspace at all.
165 if (dialog_->spacingCO->currentIndex() == 5
166 && dialog_->valueLE->text().isEmpty())
170 setVSpaceFromWidgets(dialog_->spacingCO->currentIndex(),
173 dialog_->keepCB->isChecked());
175 controller().params() = space;
179 void QVSpace::update_contents()
181 setWidgetsFromVSpace(controller().params(),
188 } // namespace frontend