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"
35 #include <qcombobox.h>
36 #include <qlineedit.h>
37 #include <qcheckbox.h>
38 #include <qpushbutton.h>
48 void setWidgetsFromVSpace(VSpace const & space,
55 switch (space.kind()) {
59 case VSpace::SMALLSKIP:
75 spacing->setCurrentItem(item);
76 keep->setChecked(space.keep());
78 LyXLength::UNIT default_unit =
79 (lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN;
80 bool const custom_vspace = space.kind() == VSpace::LENGTH;
82 value->setEnabled(true);
83 unit->setEnabled(true);
84 string length = space.length().asString();
85 lengthToWidgets(value, unit, length, default_unit);
87 lengthToWidgets(value, unit, "", default_unit);
88 value->setEnabled(false);
89 unit->setEnabled(false);
94 VSpace setVSpaceFromWidgets(int spacing,
103 space = VSpace(VSpace::DEFSKIP);
106 space = VSpace(VSpace::SMALLSKIP);
109 space = VSpace(VSpace::MEDSKIP);
112 space = VSpace(VSpace::BIGSKIP);
115 space = VSpace(VSpace::VFILL);
118 space = VSpace(LyXGlueLength(
119 widgetsToLength(value, unit)));
130 typedef QController<ControlVSpace, QView<QVSpaceDialog> > base_class;
132 QVSpace::QVSpace(Dialog & parent)
133 : base_class(parent, _("Vertical Space Settings"))
137 void QVSpace::build_dialog()
140 dialog_.reset(new QVSpaceDialog(this));
142 // Manage the ok, apply, restore and cancel/close buttons
143 bcview().setOK(dialog_->okPB);
144 bcview().setApply(dialog_->applyPB);
145 bcview().setCancel(dialog_->closePB);
147 // disable for read-only documents
148 bcview().addReadOnly(dialog_->spacingCO);
149 bcview().addReadOnly(dialog_->valueLE);
150 bcview().addReadOnly(dialog_->unitCO);
151 bcview().addReadOnly(dialog_->keepCB);
153 // initialize the length validator
154 addCheckedLineEdit(bcview(), dialog_->valueLE, dialog_->valueL);
156 // remove the %-items from the unit choice
157 dialog_->unitCO->noPercents();
161 void QVSpace::apply()
164 // If a vspace choice is "Length" but there's no text in
165 // the input field, do not insert a vspace at all.
166 if (dialog_->spacingCO->currentItem() == 5
167 && dialog_->valueLE->text().isEmpty())
171 setVSpaceFromWidgets(dialog_->spacingCO->currentItem(),
174 dialog_->keepCB->isChecked());
176 controller().params() = space;
180 void QVSpace::update_contents()
182 setWidgetsFromVSpace(controller().params(),
189 } // namespace frontend