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);
109 valueL->setEnabled(custom);
110 unitCO->setEnabled(custom);
111 fillPatternCO->setEnabled(!math_mode_ && selection == "hfill");
112 fillPatternL->setEnabled(!math_mode_ && selection == "hfill");
113 bool const no_pattern = fillPatternCO->currentIndex() == 0 || math_mode_;
114 bool const enable_keep =
115 selection == "normal" || selection == "halfquad"
116 || (selection == "hfill" && no_pattern) || custom;
117 keepCB->setEnabled(enable_keep);
118 keepL->setEnabled(enable_keep);
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() const
304 if (!InsetParamsWidget::checkWidgets())
306 return spacingCO->itemData(spacingCO->currentIndex()).toString() != "custom"
307 || !valueLE->text().isEmpty();
310 } // namespace frontend
314 #include "moc_GuiHSpace.cpp"