3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jürgen Spitzmüller
8 * Full author contact details are available in file CREDITS.
13 #include "GuiHSpace.h"
15 #include "LengthCombo.h"
16 #include "qt_helpers.h"
17 #include "Validator.h"
21 #include "insets/InsetSpace.h"
23 #include "mathed/InsetMathSpace.h"
25 #include "support/gettext.h"
26 #include "support/lstrings.h"
30 #include <QPushButton>
38 GuiHSpace::GuiHSpace(bool math_mode, QWidget * parent)
39 : InsetParamsWidget(parent), math_mode_(math_mode)
44 spacingCO->addItem(qt_("Interword Space"), "normal");
45 spacingCO->addItem(qt_("Thin Space"), "thinspace");
46 spacingCO->addItem(qt_("Medium Space"), "medspace");
47 spacingCO->addItem(qt_("Thick Space"), "thickspace");
48 spacingCO->addItem(qt_("Negative Thin Space"), "negthinspace");
49 spacingCO->addItem(qt_("Negative Medium Space"), "negmedspace");
50 spacingCO->addItem(qt_("Negative Thick Space"), "negthickspace");
51 spacingCO->addItem(qt_("Half Quad (0.5 em)"), "halfquad");
52 spacingCO->addItem(qt_("Quad (1 em)"), "quad");
53 spacingCO->addItem(qt_("Double Quad (2 em)"), "qquad");
54 spacingCO->addItem(qt_("Horizontal Fill"), "hfill");
56 spacingCO->addItem(qt_("Visible Space"), "visible");
57 spacingCO->addItem(qt_("Custom"), "custom");
59 connect(spacingCO, SIGNAL(highlighted(QString)),
60 this, SLOT(changedSlot()));
61 connect(valueLE, SIGNAL(textChanged(QString)),
62 this, SLOT(changedSlot()));
63 connect(spacingCO, SIGNAL(activated(int)),
64 this, SLOT(changedSlot()));
65 connect(keepCB, SIGNAL(clicked()),
66 this, SLOT(changedSlot()));
67 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
68 this, SLOT(changedSlot()));
69 connect(fillPatternCO, SIGNAL(activated(int)),
70 this, SLOT(changedSlot()));
72 // Set up a signed (glue) length validator
73 LengthValidator * v = new LengthValidator(valueLE);
75 v->setBottom(Length());
77 v->setBottom(GlueLength());
78 valueLE->setValidator(v);
80 // initialize the length validator
81 addCheckedWidget(valueLE, valueL);
86 void GuiHSpace::changedSlot()
93 void GuiHSpace::enableWidgets() const
95 QString const selection = spacingCO->itemData(spacingCO->currentIndex()).toString();
96 bool const custom = selection == "custom";
97 valueLE->setEnabled(custom);
100 valueL->setEnabled(custom);
101 unitCO->setEnabled(custom);
102 fillPatternCO->setEnabled(!math_mode_ && selection == "hfill");
103 fillPatternL->setEnabled(!math_mode_ && selection == "hfill");
104 bool const no_pattern = fillPatternCO->currentIndex() == 0 || math_mode_;
105 bool const enable_keep =
106 selection == "normal" || selection == "halfquad"
107 || (selection == "hfill" && no_pattern) || custom;
108 keepCB->setEnabled(enable_keep);
109 keepL->setEnabled(enable_keep);
113 void GuiHSpace::paramsToDialog(Inset const * inset)
115 InsetSpaceParams const params = math_mode_
116 ? static_cast<InsetMathSpace const *>(inset)->params()
117 : static_cast<InsetSpace const *>(inset)->params();
121 bool protect = false;
122 switch (params.kind) {
123 case InsetSpaceParams::NORMAL:
126 case InsetSpaceParams::PROTECTED:
130 case InsetSpaceParams::VISIBLE:
134 case InsetSpaceParams::THIN:
137 case InsetSpaceParams::MEDIUM:
140 case InsetSpaceParams::THICK:
143 case InsetSpaceParams::NEGTHIN:
144 item = "negthinspace";
146 case InsetSpaceParams::NEGMEDIUM:
147 item = "negmedspace";
149 case InsetSpaceParams::NEGTHICK:
150 item = "negthickspace";
152 case InsetSpaceParams::ENSKIP:
155 case InsetSpaceParams::ENSPACE:
159 case InsetSpaceParams::QUAD:
162 case InsetSpaceParams::QQUAD:
165 case InsetSpaceParams::HFILL:
168 case InsetSpaceParams::HFILL_PROTECTED:
172 case InsetSpaceParams::DOTFILL:
176 case InsetSpaceParams::HRULEFILL:
180 case InsetSpaceParams::LEFTARROWFILL:
184 case InsetSpaceParams::RIGHTARROWFILL:
188 case InsetSpaceParams::UPBRACEFILL:
192 case InsetSpaceParams::DOWNBRACEFILL:
196 case InsetSpaceParams::CUSTOM:
199 case InsetSpaceParams::CUSTOM_PROTECTED:
204 spacingCO->setCurrentIndex(spacingCO->findData(item));
205 fillPatternCO->setCurrentIndex(pattern);
206 keepCB->setChecked(protect);
207 if (item == "halfquad") {
208 keepCB->setToolTip(qt_("Insert the spacing even after a line break.\n"
209 "Note that a protected Half Quad will be turned into\n"
210 "a vertical space if used at the beginning of a paragraph!"));
212 keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
214 Length::UNIT const default_unit = Length::defaultUnit();
215 if (item == "custom") {
216 string length = params.length.asString();
217 lengthToWidgets(valueLE, unitCO, length, default_unit);
219 lengthToWidgets(valueLE, unitCO, "", default_unit);
225 docstring GuiHSpace::dialogToParams() const
227 InsetSpaceParams params = math_mode_ ?
228 InsetSpaceParams(true) : InsetSpaceParams(false);
231 spacingCO->itemData(spacingCO->currentIndex()).toString();
233 if (item == "normal")
234 params.kind = keepCB->isChecked() ?
235 InsetSpaceParams::PROTECTED : InsetSpaceParams::NORMAL;
236 else if (item == "thinspace")
237 params.kind = InsetSpaceParams::THIN;
238 else if (item == "medspace")
239 params.kind = InsetSpaceParams::MEDIUM;
240 else if (item == "thickspace")
241 params.kind = InsetSpaceParams::THICK;
242 else if (item == "negthinspace")
243 params.kind = InsetSpaceParams::NEGTHIN;
244 else if (item == "negmedspace")
245 params.kind = InsetSpaceParams::NEGMEDIUM;
246 else if (item == "negthickspace")
247 params.kind = InsetSpaceParams::NEGTHICK;
248 else if (item == "halfquad")
249 params.kind = keepCB->isChecked() ?
250 InsetSpaceParams::ENSPACE : InsetSpaceParams::ENSKIP;
251 else if (item == "quad")
252 params.kind = InsetSpaceParams::QUAD;
253 else if (item == "qquad")
254 params.kind = InsetSpaceParams::QQUAD;
255 else if (item == "hfill") {
256 switch (fillPatternCO->currentIndex()) {
258 params.kind = InsetSpaceParams::DOTFILL;
261 params.kind = InsetSpaceParams::HRULEFILL;
264 params.kind = InsetSpaceParams::LEFTARROWFILL;
267 params.kind = InsetSpaceParams::RIGHTARROWFILL;
270 params.kind = InsetSpaceParams::UPBRACEFILL;
273 params.kind = InsetSpaceParams::DOWNBRACEFILL;
276 if (keepCB->isChecked())
277 params.kind = InsetSpaceParams::HFILL_PROTECTED;
279 params.kind = InsetSpaceParams::HFILL;
282 } else if (item == "custom") {
283 params.kind = keepCB->isChecked() ?
284 InsetSpaceParams::CUSTOM_PROTECTED : InsetSpaceParams::CUSTOM;
285 params.length = GlueLength(widgetsToLength(valueLE, unitCO));
286 } else if (item == "visible")
287 params.kind = InsetSpaceParams::VISIBLE;
289 return from_ascii(InsetSpace::params2string(params));
293 bool GuiHSpace::checkWidgets(bool readonly) const
295 valueLE->setReadOnly(readonly);
296 spacingCO->setEnabled(!readonly);
297 spacingL->setEnabled(!readonly);
300 fillPatternCO->setEnabled(false);
301 fillPatternL->setEnabled(false);
302 keepCB->setEnabled(false);
303 keepL->setEnabled(false);
304 valueLE->setEnabled(false);
305 valueL->setEnabled(false);
306 unitCO->setEnabled(false);
310 if (!InsetParamsWidget::checkWidgets())
312 return spacingCO->itemData(spacingCO->currentIndex()).toString() != "custom"
313 || !valueLE->text().isEmpty();
316 } // namespace frontend
320 #include "moc_GuiHSpace.cpp"