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"
20 #include "ControlVSpace.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 "ControlVSpace.h"
30 #include "frontend_helpers.h"
32 #include "support/lstrings.h"
35 #include <QCloseEvent>
37 #include <QPushButton>
46 GuiVSpaceDialog::GuiVSpaceDialog(LyXView & lv)
47 : GuiDialog(lv, "vspace")
50 setViewTitle(_("Vertical Space Settings"));
51 setController(new ControlVSpace(*this));
53 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
54 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
55 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
57 connect(spacingCO, SIGNAL(highlighted(const QString &)),
58 this, SLOT(change_adaptor()));
59 connect(valueLE, SIGNAL(textChanged(const QString &)),
60 this, SLOT(change_adaptor()));
61 connect(spacingCO, SIGNAL(activated(int)),
62 this, SLOT(enableCustom(int)));
63 connect(keepCB, SIGNAL(clicked()),
64 this, SLOT(change_adaptor()));
65 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
66 this, SLOT(change_adaptor()));
68 valueLE->setValidator(unsignedLengthValidator(valueLE));
70 // Manage the ok, apply, restore and cancel/close buttons
71 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
73 bc().setApply(applyPB);
74 bc().setCancel(closePB);
76 // disable for read-only documents
77 bc().addReadOnly(spacingCO);
78 bc().addReadOnly(valueLE);
79 bc().addReadOnly(unitCO);
80 bc().addReadOnly(keepCB);
82 // initialize the length validator
83 bc().addCheckedLineEdit(valueLE, valueL);
85 // remove the %-items from the unit choice
90 ControlVSpace & GuiVSpaceDialog::controller() const
92 return static_cast<ControlVSpace &>(GuiDialog::controller());
96 void GuiVSpaceDialog::closeEvent(QCloseEvent * e)
103 void GuiVSpaceDialog::change_adaptor()
109 void GuiVSpaceDialog::enableCustom(int selection)
111 bool const enable = selection == 5;
112 valueLE->setEnabled(enable);
113 unitCO->setEnabled(enable);
117 static void setWidgetsFromVSpace(VSpace const & space,
124 switch (space.kind()) {
125 case VSpace::DEFSKIP: item = 0; break;
126 case VSpace::SMALLSKIP: item = 1; break;
127 case VSpace::MEDSKIP: item = 2; break;
128 case VSpace::BIGSKIP: item = 3; break;
129 case VSpace::VFILL: item = 4; break;
130 case VSpace::LENGTH: item = 5; break;
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,
152 QLineEdit * value, LengthCombo * unit, bool keep)
157 case 0: space = VSpace(VSpace::DEFSKIP); break;
158 case 1: space = VSpace(VSpace::SMALLSKIP); break;
159 case 2: space = VSpace(VSpace::MEDSKIP); break;
160 case 3: space = VSpace(VSpace::BIGSKIP); break;
161 case 4: space = VSpace(VSpace::VFILL); break;
162 case 5: space = VSpace(GlueLength(widgetsToLength(value, unit))); break;
170 void GuiVSpaceDialog::applyView()
172 // If a vspace choice is "Length" but there's no text in
173 // the input field, do not insert a vspace at all.
174 if (spacingCO->currentIndex() == 5 && valueLE->text().isEmpty())
177 VSpace const space = setVSpaceFromWidgets(spacingCO->currentIndex(),
178 valueLE, unitCO, keepCB->isChecked());
180 controller().params() = space;
184 void GuiVSpaceDialog::update_contents()
186 setWidgetsFromVSpace(controller().params(),
187 spacingCO, valueLE, unitCO, keepCB);
190 } // namespace frontend
194 #include "GuiVSpace_moc.cpp"