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 "LengthCombo.h"
21 #include "qt_helpers.h"
22 #include "Validator.h"
27 #include "insets/InsetVSpace.h"
29 #include "support/gettext.h"
30 #include "support/lstrings.h"
34 #include <QPushButton>
42 GuiVSpace::GuiVSpace(QWidget * parent) : InsetParamsWidget(parent)
46 connect(valueLE, SIGNAL(textChanged(QString)),
47 this, SIGNAL(changed()));
48 connect(keepCB, SIGNAL(clicked()),
49 this, SIGNAL(changed()));
50 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
51 this, SIGNAL(changed()));
53 connect(spacingCO, SIGNAL(activated(int)),
54 this, SLOT(enableCustom(int)));
56 // Set up a signed glue length validator
57 LengthValidator * v = new LengthValidator(valueLE);
58 v->setBottom(GlueLength());
59 valueLE->setValidator(v);
61 // initialize the length validator
62 addCheckedWidget(valueLE, valueL);
63 enableCustom(spacingCO->currentIndex());
67 void GuiVSpace::enableCustom(int selection)
69 bool const enable = selection == 5;
70 valueLE->setEnabled(enable);
73 valueL->setEnabled(enable);
74 unitCO->setEnabled(enable);
79 static void setWidgetsFromVSpace(VSpace const & space,
86 switch (space.kind()) {
90 case VSpace::SMALLSKIP:
105 case VSpace::HALFLINE:
106 case VSpace::FULLLINE:
107 // not supported here yet
110 spacing->setCurrentIndex(item);
111 keep->setChecked(space.keep());
113 Length::UNIT const default_unit = Length::defaultUnit();
114 bool const custom_vspace = space.kind() == VSpace::LENGTH;
116 value->setEnabled(true);
117 unit->setEnabled(true);
118 string length = space.length().asString();
119 lengthToWidgets(value, unit, length, default_unit);
121 lengthToWidgets(value, unit, "", default_unit);
122 value->setEnabled(false);
123 unit->setEnabled(false);
128 static VSpace setVSpaceFromWidgets(int spacing,
129 QLineEdit * value, LengthCombo * unit, bool keep)
134 case 0: space = VSpace(VSpace::DEFSKIP); break;
135 case 1: space = VSpace(VSpace::SMALLSKIP); break;
136 case 2: space = VSpace(VSpace::MEDSKIP); break;
137 case 3: space = VSpace(VSpace::BIGSKIP); break;
138 case 4: space = VSpace(VSpace::VFILL); break;
139 case 5: space = VSpace(GlueLength(widgetsToLength(value, unit))); break;
147 docstring GuiVSpace::dialogToParams() const
149 // If a vspace choice is "Length" but there's no text in
150 // the input field, do not insert a vspace at all.
151 if (spacingCO->currentIndex() == 5 && valueLE->text().isEmpty())
154 VSpace const params = setVSpaceFromWidgets(spacingCO->currentIndex(),
155 valueLE, unitCO, keepCB->isChecked());
156 return from_ascii(InsetVSpace::params2string(params));
160 void GuiVSpace::paramsToDialog(Inset const * inset)
162 InsetVSpace const * vs = static_cast<InsetVSpace const *>(inset);
163 VSpace const & params = vs->space();
164 setWidgetsFromVSpace(params, spacingCO, valueLE, unitCO, keepCB);
165 enableCustom(spacingCO->currentIndex());
169 bool GuiVSpace::checkWidgets(bool readonly) const
171 valueLE->setReadOnly(readonly);
172 keepCB->setEnabled(!readonly);
175 spacingCO->setEnabled(false);
176 unitCO->setEnabled(false);
178 bool const enable = (spacingCO->currentIndex() == 5);
179 valueLE->setEnabled(enable);
180 valueL->setEnabled(enable);
181 unitCO->setEnabled(enable);
184 return InsetParamsWidget::checkWidgets();
187 } // namespace frontend
191 #include "moc_GuiVSpace.cpp"