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"
34 #include "support/tostr.h"
36 #include <qcombobox.h>
37 #include <qlineedit.h>
38 #include <qcheckbox.h>
39 #include <qpushbutton.h>
49 void setWidgetsFromVSpace(VSpace const & space,
56 switch (space.kind()) {
60 case VSpace::SMALLSKIP:
76 spacing->setCurrentItem(item);
77 keep->setChecked(space.keep());
79 LyXLength::UNIT default_unit =
80 (lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN;
81 bool const custom_vspace = space.kind() == VSpace::LENGTH;
83 value->setEnabled(true);
84 unit->setEnabled(true);
85 string length = space.length().asString();
86 lengthToWidgets(value, unit, length, default_unit);
88 lengthToWidgets(value, unit, "", default_unit);
89 value->setEnabled(false);
90 unit->setEnabled(false);
95 VSpace setVSpaceFromWidgets(int spacing,
104 space = VSpace(VSpace::DEFSKIP);
107 space = VSpace(VSpace::SMALLSKIP);
110 space = VSpace(VSpace::MEDSKIP);
113 space = VSpace(VSpace::BIGSKIP);
116 space = VSpace(VSpace::VFILL);
119 space = VSpace(LyXGlueLength(
120 widgetsToLength(value, unit)));
131 typedef QController<ControlVSpace, QView<QVSpaceDialog> > base_class;
133 QVSpace::QVSpace(Dialog & parent)
134 : base_class(parent, _("LyX: Vertical Space Settings"))
138 void QVSpace::build_dialog()
141 dialog_.reset(new QVSpaceDialog(this));
143 // Manage the ok, apply, restore and cancel/close buttons
144 bcview().setOK(dialog_->okPB);
145 bcview().setApply(dialog_->applyPB);
146 bcview().setCancel(dialog_->closePB);
148 // disable for read-only documents
149 bcview().addReadOnly(dialog_->spacingCO);
150 bcview().addReadOnly(dialog_->valueLE);
151 bcview().addReadOnly(dialog_->unitCO);
152 bcview().addReadOnly(dialog_->keepCB);
154 // initialize the length validator
155 addCheckedLineEdit(bcview(), dialog_->valueLE, dialog_->valueL);
157 // remove the %-items from the unit choice
158 dialog_->unitCO->noPercents();
162 void QVSpace::apply()
165 // If a vspace choice is "Length" but there's no text in
166 // the input field, do not insert a vspace at all.
167 if (dialog_->spacingCO->currentItem() == 5
168 && dialog_->valueLE->text().isEmpty())
172 setVSpaceFromWidgets(dialog_->spacingCO->currentItem(),
175 dialog_->keepCB->isChecked());
177 controller().params() = space;
181 void QVSpace::update_contents()
183 setWidgetsFromVSpace(controller().params(),
190 } // namespace frontend