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_("Normal Space"), "normal");
45 spacingCO->addItem(qt_("Thin Space (1/6 em)"), "thinspace");
46 spacingCO->addItem(qt_("Medium Space (2/9 em)"), "medspace");
47 spacingCO->addItem(qt_("Thick Space (5/18 em)"), "thickspace");
48 spacingCO->addItem(qt_("Negative Thin Space (−1/6 em)"), "negthinspace");
49 spacingCO->addItem(qt_("Negative Medium Space (−2/9 em)"), "negmedspace");
50 spacingCO->addItem(qt_("Negative Thick Space (−5/18 em)"), "negthickspace");
51 spacingCO->addItem(qt_("Half Quad (1/2 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 #if QT_VERSION < 0x050e00
60 connect(spacingCO, SIGNAL(highlighted(QString)),
61 this, SLOT(changedSlot()));
63 connect(spacingCO, SIGNAL(textHighlighted(QString)),
64 this, SLOT(changedSlot()));
66 connect(valueLE, SIGNAL(textChanged(QString)),
67 this, SLOT(changedSlot()));
68 connect(spacingCO, SIGNAL(activated(int)),
69 this, SLOT(changedSlot()));
70 connect(keepCB, SIGNAL(clicked()),
71 this, SLOT(changedSlot()));
72 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
73 this, SLOT(changedSlot()));
74 connect(fillPatternCO, SIGNAL(activated(int)),
75 this, SLOT(changedSlot()));
77 // Set up a signed (glue) length validator
78 LengthValidator * v = new LengthValidator(valueLE);
80 v->setBottom(Length());
82 v->setBottom(GlueLength());
83 valueLE->setValidator(v);
85 // initialize the length validator
86 addCheckedWidget(valueLE, valueL);
91 void GuiHSpace::changedSlot()
98 void GuiHSpace::enableWidgets() const
100 QString const selection = spacingCO->itemData(spacingCO->currentIndex()).toString();
101 bool const custom = selection == "custom";
102 valueLE->setEnabled(custom);
105 valueL->setEnabled(custom);
106 unitCO->setEnabled(custom);
107 fillPatternCO->setEnabled(!math_mode_ && selection == "hfill");
108 fillPatternL->setEnabled(!math_mode_ && selection == "hfill");
109 bool const no_pattern = fillPatternCO->currentIndex() == 0 || math_mode_;
110 bool const enable_keep =
111 selection == "normal" || selection == "halfquad"
112 || (selection == "hfill" && no_pattern) || custom;
113 keepCB->setEnabled(enable_keep);
114 keepL->setEnabled(enable_keep);
115 // When Non-Breaking is disabled indicate that this is a non-breaking state
116 // by enabling the check-box
118 keepCB->setCheckState(Qt::Checked);
122 void GuiHSpace::paramsToDialog(Inset const * inset)
124 InsetSpaceParams const params = math_mode_
125 ? static_cast<InsetMathSpace const *>(inset)->params()
126 : static_cast<InsetSpace const *>(inset)->params();
130 bool protect = false;
131 switch (params.kind) {
132 case InsetSpaceParams::NORMAL:
135 case InsetSpaceParams::PROTECTED:
139 case InsetSpaceParams::VISIBLE:
143 case InsetSpaceParams::THIN:
146 case InsetSpaceParams::MEDIUM:
149 case InsetSpaceParams::THICK:
152 case InsetSpaceParams::NEGTHIN:
153 item = "negthinspace";
155 case InsetSpaceParams::NEGMEDIUM:
156 item = "negmedspace";
158 case InsetSpaceParams::NEGTHICK:
159 item = "negthickspace";
161 case InsetSpaceParams::ENSKIP:
164 case InsetSpaceParams::ENSPACE:
168 case InsetSpaceParams::QUAD:
171 case InsetSpaceParams::QQUAD:
174 case InsetSpaceParams::HFILL:
177 case InsetSpaceParams::HFILL_PROTECTED:
181 case InsetSpaceParams::DOTFILL:
185 case InsetSpaceParams::HRULEFILL:
189 case InsetSpaceParams::LEFTARROWFILL:
193 case InsetSpaceParams::RIGHTARROWFILL:
197 case InsetSpaceParams::UPBRACEFILL:
201 case InsetSpaceParams::DOWNBRACEFILL:
205 case InsetSpaceParams::CUSTOM:
208 case InsetSpaceParams::CUSTOM_PROTECTED:
213 spacingCO->setCurrentIndex(spacingCO->findData(item));
214 fillPatternCO->setCurrentIndex(pattern);
215 keepCB->setChecked(protect);
216 if (item == "halfquad") {
217 keepCB->setToolTip(qt_("Insert the spacing even after a line break.\n"
218 "Note that a protected Half Quad will be turned into\n"
219 "a vertical space if used at the beginning of a paragraph!"));
221 keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
223 Length::UNIT const default_unit = Length::defaultUnit();
224 if (item == "custom") {
225 string length = params.length.asString();
226 lengthToWidgets(valueLE, unitCO, length, default_unit);
228 lengthToWidgets(valueLE, unitCO, "", default_unit);
234 docstring GuiHSpace::dialogToParams() const
236 InsetSpaceParams params = math_mode_ ?
237 InsetSpaceParams(true) : InsetSpaceParams(false);
240 spacingCO->itemData(spacingCO->currentIndex()).toString();
242 if (item == "normal")
243 params.kind = keepCB->isChecked() ?
244 InsetSpaceParams::PROTECTED : InsetSpaceParams::NORMAL;
245 else if (item == "thinspace")
246 params.kind = InsetSpaceParams::THIN;
247 else if (item == "medspace")
248 params.kind = InsetSpaceParams::MEDIUM;
249 else if (item == "thickspace")
250 params.kind = InsetSpaceParams::THICK;
251 else if (item == "negthinspace")
252 params.kind = InsetSpaceParams::NEGTHIN;
253 else if (item == "negmedspace")
254 params.kind = InsetSpaceParams::NEGMEDIUM;
255 else if (item == "negthickspace")
256 params.kind = InsetSpaceParams::NEGTHICK;
257 else if (item == "halfquad")
258 params.kind = keepCB->isChecked() ?
259 InsetSpaceParams::ENSPACE : InsetSpaceParams::ENSKIP;
260 else if (item == "quad")
261 params.kind = InsetSpaceParams::QUAD;
262 else if (item == "qquad")
263 params.kind = InsetSpaceParams::QQUAD;
264 else if (item == "hfill") {
265 switch (fillPatternCO->currentIndex()) {
267 params.kind = InsetSpaceParams::DOTFILL;
270 params.kind = InsetSpaceParams::HRULEFILL;
273 params.kind = InsetSpaceParams::LEFTARROWFILL;
276 params.kind = InsetSpaceParams::RIGHTARROWFILL;
279 params.kind = InsetSpaceParams::UPBRACEFILL;
282 params.kind = InsetSpaceParams::DOWNBRACEFILL;
285 if (keepCB->isChecked())
286 params.kind = InsetSpaceParams::HFILL_PROTECTED;
288 params.kind = InsetSpaceParams::HFILL;
291 } else if (item == "custom") {
292 params.kind = keepCB->isChecked() ?
293 InsetSpaceParams::CUSTOM_PROTECTED : InsetSpaceParams::CUSTOM;
294 params.length = GlueLength(widgetsToLength(valueLE, unitCO));
295 } else if (item == "visible")
296 params.kind = InsetSpaceParams::VISIBLE;
298 return from_ascii(InsetSpace::params2string(params));
302 bool GuiHSpace::checkWidgets(bool readonly) const
304 valueLE->setReadOnly(readonly);
305 spacingCO->setEnabled(!readonly);
306 spacingL->setEnabled(!readonly);
309 fillPatternCO->setEnabled(false);
310 fillPatternL->setEnabled(false);
311 keepCB->setEnabled(false);
312 keepL->setEnabled(false);
313 valueLE->setEnabled(false);
314 valueL->setEnabled(false);
315 unitCO->setEnabled(false);
319 if (!InsetParamsWidget::checkWidgets())
321 return spacingCO->itemData(spacingCO->currentIndex()).toString() != "custom"
322 || !valueLE->text().isEmpty();
325 } // namespace frontend
329 #include "moc_GuiHSpace.cpp"