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 "LengthCombo.h"
22 #include "qt_helpers.h"
23 #include "Validator.h"
25 #include "LyXRC.h" // to set the default length values
29 #include "controllers/ControlVSpace.h"
30 #include "controllers/frontend_helpers.h"
32 #include "support/lstrings.h"
35 #include <QCloseEvent>
37 #include <QPushButton>
47 /////////////////////////////////////////////////////////////////////
51 /////////////////////////////////////////////////////////////////////
54 GuiVSpaceDialog::GuiVSpaceDialog(GuiVSpace * form)
59 connect(okPB, SIGNAL(clicked()), form_, SLOT(slotOK()));
60 connect(applyPB, SIGNAL(clicked()), form_, SLOT(slotApply()));
61 connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
63 connect(spacingCO, SIGNAL(highlighted(const QString &)),
64 this, SLOT(change_adaptor()));
65 connect(valueLE, SIGNAL(textChanged(const QString &)),
66 this, SLOT(change_adaptor()));
67 connect(spacingCO, SIGNAL(activated(int)),
68 this, SLOT(enableCustom(int)));
69 connect(keepCB, SIGNAL(clicked()),
70 this, SLOT(change_adaptor()));
71 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
72 this, SLOT(change_adaptor()));
74 valueLE->setValidator(unsignedLengthValidator(valueLE));
78 void GuiVSpaceDialog::closeEvent(QCloseEvent * e)
85 void GuiVSpaceDialog::change_adaptor()
91 void GuiVSpaceDialog::enableCustom(int selection)
93 bool const enable = selection == 5;
94 valueLE->setEnabled(enable);
95 unitCO->setEnabled(enable);
99 /////////////////////////////////////////////////////////////////////
103 /////////////////////////////////////////////////////////////////////
105 static void setWidgetsFromVSpace(VSpace const & space,
112 switch (space.kind()) {
113 case VSpace::DEFSKIP:
116 case VSpace::SMALLSKIP:
119 case VSpace::MEDSKIP:
122 case VSpace::BIGSKIP:
132 spacing->setCurrentIndex(item);
133 keep->setChecked(space.keep());
135 Length::UNIT default_unit =
136 (lyxrc.default_papersize > 3) ? Length::CM : Length::IN;
137 bool const custom_vspace = space.kind() == VSpace::LENGTH;
139 value->setEnabled(true);
140 unit->setEnabled(true);
141 string length = space.length().asString();
142 lengthToWidgets(value, unit, length, default_unit);
144 lengthToWidgets(value, unit, "", default_unit);
145 value->setEnabled(false);
146 unit->setEnabled(false);
151 static VSpace setVSpaceFromWidgets(int spacing,
160 space = VSpace(VSpace::DEFSKIP);
163 space = VSpace(VSpace::SMALLSKIP);
166 space = VSpace(VSpace::MEDSKIP);
169 space = VSpace(VSpace::BIGSKIP);
172 space = VSpace(VSpace::VFILL);
175 space = VSpace(GlueLength(widgetsToLength(value, unit)));
184 GuiVSpace::GuiVSpace(Dialog & parent)
185 : GuiView<GuiVSpaceDialog>(parent, _("Vertical Space Settings"))
189 void GuiVSpace::build_dialog()
192 dialog_.reset(new GuiVSpaceDialog(this));
194 // Manage the ok, apply, restore and cancel/close buttons
195 bcview().setOK(dialog_->okPB);
196 bcview().setApply(dialog_->applyPB);
197 bcview().setCancel(dialog_->closePB);
199 // disable for read-only documents
200 bcview().addReadOnly(dialog_->spacingCO);
201 bcview().addReadOnly(dialog_->valueLE);
202 bcview().addReadOnly(dialog_->unitCO);
203 bcview().addReadOnly(dialog_->keepCB);
205 // initialize the length validator
206 addCheckedLineEdit(bcview(), dialog_->valueLE, dialog_->valueL);
208 // remove the %-items from the unit choice
209 dialog_->unitCO->noPercents();
213 void GuiVSpace::apply()
216 // If a vspace choice is "Length" but there's no text in
217 // the input field, do not insert a vspace at all.
218 if (dialog_->spacingCO->currentIndex() == 5
219 && dialog_->valueLE->text().isEmpty())
223 setVSpaceFromWidgets(dialog_->spacingCO->currentIndex(),
226 dialog_->keepCB->isChecked());
228 controller().params() = space;
232 void GuiVSpace::update_contents()
234 setWidgetsFromVSpace(controller().params(),
241 } // namespace frontend
245 #include "GuiVSpace_moc.cpp"