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 "support/lstrings.h"
32 #include <QCloseEvent>
34 #include <QPushButton>
43 GuiVSpaceDialog::GuiVSpaceDialog(LyXView & lv)
44 : GuiDialog(lv, "vspace")
47 setViewTitle(_("Vertical Space Settings"));
48 setController(new ControlVSpace(*this));
50 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
51 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
52 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
54 connect(spacingCO, SIGNAL(highlighted(const QString &)),
55 this, SLOT(change_adaptor()));
56 connect(valueLE, SIGNAL(textChanged(const QString &)),
57 this, SLOT(change_adaptor()));
58 connect(spacingCO, SIGNAL(activated(int)),
59 this, SLOT(enableCustom(int)));
60 connect(keepCB, SIGNAL(clicked()),
61 this, SLOT(change_adaptor()));
62 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
63 this, SLOT(change_adaptor()));
65 valueLE->setValidator(unsignedLengthValidator(valueLE));
67 // Manage the ok, apply, restore and cancel/close buttons
68 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
70 bc().setApply(applyPB);
71 bc().setCancel(closePB);
73 // disable for read-only documents
74 bc().addReadOnly(spacingCO);
75 bc().addReadOnly(valueLE);
76 bc().addReadOnly(unitCO);
77 bc().addReadOnly(keepCB);
79 // initialize the length validator
80 bc().addCheckedLineEdit(valueLE, valueL);
82 // remove the %-items from the unit choice
87 ControlVSpace & GuiVSpaceDialog::controller()
89 return static_cast<ControlVSpace &>(GuiDialog::controller());
93 void GuiVSpaceDialog::closeEvent(QCloseEvent * e)
100 void GuiVSpaceDialog::change_adaptor()
106 void GuiVSpaceDialog::enableCustom(int selection)
108 bool const enable = selection == 5;
109 valueLE->setEnabled(enable);
110 unitCO->setEnabled(enable);
114 static void setWidgetsFromVSpace(VSpace const & space,
121 switch (space.kind()) {
122 case VSpace::DEFSKIP: item = 0; break;
123 case VSpace::SMALLSKIP: item = 1; break;
124 case VSpace::MEDSKIP: item = 2; break;
125 case VSpace::BIGSKIP: item = 3; break;
126 case VSpace::VFILL: item = 4; break;
127 case VSpace::LENGTH: item = 5; break;
129 spacing->setCurrentIndex(item);
130 keep->setChecked(space.keep());
132 Length::UNIT default_unit =
133 (lyxrc.default_papersize > 3) ? Length::CM : Length::IN;
134 bool const custom_vspace = space.kind() == VSpace::LENGTH;
136 value->setEnabled(true);
137 unit->setEnabled(true);
138 string length = space.length().asString();
139 lengthToWidgets(value, unit, length, default_unit);
141 lengthToWidgets(value, unit, "", default_unit);
142 value->setEnabled(false);
143 unit->setEnabled(false);
148 static VSpace setVSpaceFromWidgets(int spacing,
149 QLineEdit * value, LengthCombo * unit, bool keep)
154 case 0: space = VSpace(VSpace::DEFSKIP); break;
155 case 1: space = VSpace(VSpace::SMALLSKIP); break;
156 case 2: space = VSpace(VSpace::MEDSKIP); break;
157 case 3: space = VSpace(VSpace::BIGSKIP); break;
158 case 4: space = VSpace(VSpace::VFILL); break;
159 case 5: space = VSpace(GlueLength(widgetsToLength(value, unit))); break;
167 void GuiVSpaceDialog::applyView()
169 // If a vspace choice is "Length" but there's no text in
170 // the input field, do not insert a vspace at all.
171 if (spacingCO->currentIndex() == 5 && valueLE->text().isEmpty())
174 VSpace const space = setVSpaceFromWidgets(spacingCO->currentIndex(),
175 valueLE, unitCO, keepCB->isChecked());
177 controller().params() = space;
181 void GuiVSpaceDialog::updateContents()
183 setWidgetsFromVSpace(controller().params(),
184 spacingCO, valueLE, unitCO, keepCB);
187 } // namespace frontend
191 #include "GuiVSpace_moc.cpp"