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)
45 spacingCO->addItem(qt_("Interword Space"), "normal");
46 spacingCO->addItem(qt_("Thin Space"), "thinspace");
47 spacingCO->addItem(qt_("Medium Space"), "medspace");
48 spacingCO->addItem(qt_("Thick Space"), "thickspace");
49 spacingCO->addItem(qt_("Negative Thin Space"), "negthinspace");
50 spacingCO->addItem(qt_("Negative Medium Space"), "negmedspace");
51 spacingCO->addItem(qt_("Negative Thick Space"), "negthickspace");
52 spacingCO->addItem(qt_("Half Quad (0.5 em)"), "halfquad");
53 spacingCO->addItem(qt_("Quad (1 em)"), "quad");
54 spacingCO->addItem(qt_("Double Quad (2 em)"), "qquad");
55 spacingCO->addItem(qt_("Horizontal Fill"), "hfill");
56 spacingCO->addItem(qt_("Custom"), "custom");
58 spacingCO->addItem(qt_("Interword Space"), "normal");
59 spacingCO->addItem(qt_("Thin Space"), "thinspace");
60 spacingCO->addItem(qt_("Negative Thin Space"), "negthinspace");
61 spacingCO->addItem(qt_("Negative Medium Space"), "negmedspace");
62 spacingCO->addItem(qt_("Negative Thick Space"), "negthickspace");
63 spacingCO->addItem(qt_("Half Quad (0.5 em)"), "halfquad");
64 spacingCO->addItem(qt_("Quad (1 em)"), "quad");
65 spacingCO->addItem(qt_("Double Quad (2 em)"), "qquad");
66 spacingCO->addItem(qt_("Horizontal Fill"), "hfill");
67 spacingCO->addItem(qt_("Custom"), "custom");
68 spacingCO->addItem(qt_("Visible Space"), "visible");
71 connect(spacingCO, SIGNAL(highlighted(QString)),
72 this, SLOT(changedSlot()));
73 connect(valueLE, SIGNAL(textChanged(QString)),
74 this, SLOT(changedSlot()));
75 connect(spacingCO, SIGNAL(activated(int)),
76 this, SLOT(changedSlot()));
77 connect(keepCB, SIGNAL(clicked()),
78 this, SLOT(changedSlot()));
79 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
80 this, SLOT(changedSlot()));
81 connect(fillPatternCO, SIGNAL(activated(int)),
82 this, SLOT(changedSlot()));
85 valueLE->setValidator(unsignedLengthValidator(valueLE));
87 valueLE->setValidator(unsignedGlueLengthValidator(valueLE));
89 // initialize the length validator
90 addCheckedWidget(valueLE, valueL);
95 void GuiHSpace::changedSlot()
102 void GuiHSpace::enableWidgets()
104 QString const selection = spacingCO->itemData(spacingCO->currentIndex()).toString();
105 bool const custom = selection == "custom";
106 valueLE->setEnabled(custom);
107 unitCO->setEnabled(custom);
108 fillPatternCO->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" || (selection == "hfill" && no_pattern) || custom;
112 keepCB->setEnabled(enable_keep);
116 void GuiHSpace::paramsToDialog(Inset const * inset)
118 InsetSpaceParams const params = math_mode_
119 ? static_cast<InsetMathSpace const *>(inset)->params()
120 : static_cast<InsetSpace const *>(inset)->params();
124 bool protect = false;
125 switch (params.kind) {
126 case InsetSpaceParams::NORMAL:
129 case InsetSpaceParams::PROTECTED:
133 case InsetSpaceParams::VISIBLE:
137 case InsetSpaceParams::THIN:
140 case InsetSpaceParams::MEDIUM:
143 case InsetSpaceParams::THICK:
146 case InsetSpaceParams::NEGTHIN:
147 item = "negthinspace";
149 case InsetSpaceParams::NEGMEDIUM:
150 item = "negmedspace";
152 case InsetSpaceParams::NEGTHICK:
153 item = "negthickspace";
155 case InsetSpaceParams::ENSKIP:
158 case InsetSpaceParams::ENSPACE:
162 case InsetSpaceParams::QUAD:
165 case InsetSpaceParams::QQUAD:
168 case InsetSpaceParams::HFILL:
171 case InsetSpaceParams::HFILL_PROTECTED:
175 case InsetSpaceParams::DOTFILL:
179 case InsetSpaceParams::HRULEFILL:
183 case InsetSpaceParams::LEFTARROWFILL:
187 case InsetSpaceParams::RIGHTARROWFILL:
191 case InsetSpaceParams::UPBRACEFILL:
195 case InsetSpaceParams::DOWNBRACEFILL:
199 case InsetSpaceParams::CUSTOM:
202 case InsetSpaceParams::CUSTOM_PROTECTED:
207 spacingCO->setCurrentIndex(spacingCO->findData(item));
208 fillPatternCO->setCurrentIndex(pattern);
209 keepCB->setChecked(protect);
210 if (item == "halfquad") {
211 keepCB->setToolTip(qt_("Insert the spacing even after a line break.\n"
212 "Note that a protected Half Quad will be turned into\n"
213 "a vertical space if used at the beginning of a paragraph!"));
215 keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
217 Length::UNIT const default_unit = Length::defaultUnit();
218 if (item == "custom") {
219 string length = params.length.asString();
220 lengthToWidgets(valueLE, unitCO, length, default_unit);
222 lengthToWidgets(valueLE, unitCO, "", default_unit);
228 docstring GuiHSpace::dialogToParams() const
230 InsetSpaceParams params = math_mode_ ?
231 InsetSpaceParams(true) : InsetSpaceParams(false);
234 spacingCO->itemData(spacingCO->currentIndex()).toString();
236 if (item == "normal")
237 params.kind = keepCB->isChecked() ?
238 InsetSpaceParams::PROTECTED : InsetSpaceParams::NORMAL;
239 else if (item == "thinspace")
240 params.kind = InsetSpaceParams::THIN;
241 else if (item == "medspace")
242 params.kind = InsetSpaceParams::MEDIUM;
243 else if (item == "thickspace")
244 params.kind = InsetSpaceParams::THICK;
245 else if (item == "negthinspace")
246 params.kind = InsetSpaceParams::NEGTHIN;
247 else if (item == "negmedspace")
248 params.kind = InsetSpaceParams::NEGMEDIUM;
249 else if (item == "negthickspace")
250 params.kind = InsetSpaceParams::NEGTHICK;
251 else if (item == "halfquad")
252 params.kind = keepCB->isChecked() ?
253 InsetSpaceParams::ENSPACE : InsetSpaceParams::ENSKIP;
254 else if (item == "quad")
255 params.kind = InsetSpaceParams::QUAD;
256 else if (item == "qquad")
257 params.kind = InsetSpaceParams::QQUAD;
258 else if (item == "hfill") {
259 switch (fillPatternCO->currentIndex()) {
261 params.kind = InsetSpaceParams::DOTFILL;
264 params.kind = InsetSpaceParams::HRULEFILL;
267 params.kind = InsetSpaceParams::LEFTARROWFILL;
270 params.kind = InsetSpaceParams::RIGHTARROWFILL;
273 params.kind = InsetSpaceParams::UPBRACEFILL;
276 params.kind = InsetSpaceParams::DOWNBRACEFILL;
279 if (keepCB->isChecked())
280 params.kind = InsetSpaceParams::HFILL_PROTECTED;
282 params.kind = InsetSpaceParams::HFILL;
285 } else if (item == "custom") {
286 params.kind = keepCB->isChecked() ?
287 InsetSpaceParams::CUSTOM_PROTECTED : InsetSpaceParams::CUSTOM;
288 params.length = GlueLength(widgetsToLength(valueLE, unitCO));
289 } else if (item == "visible")
290 params.kind = InsetSpaceParams::VISIBLE;
292 return from_ascii(InsetSpace::params2string(params));
296 bool GuiHSpace::checkWidgets() const
298 if (!InsetParamsWidget::checkWidgets())
300 return spacingCO->itemData(spacingCO->currentIndex()).toString() != "custom"
301 || !valueLE->text().isEmpty();
304 } // namespace frontend
308 #include "moc_GuiHSpace.cpp"