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_("Thin Space"), toqstr("thinspace"));
46 spacingCO->addItem(qt_("Medium Space"), toqstr("medspace"));
47 spacingCO->addItem(qt_("Thick Space"), toqstr("thickspace"));
48 spacingCO->addItem(qt_("Negative Thin Space"), toqstr("negthinspace"));
49 spacingCO->addItem(qt_("Negative Medium Space"), toqstr("negmedspace"));
50 spacingCO->addItem(qt_("Negative Thick Space"), toqstr("negthickspace"));
51 spacingCO->addItem(qt_("Half Quad (0.5 em)"), toqstr("halfquad"));
52 spacingCO->addItem(qt_("Quad (1 em)"), toqstr("quad"));
53 spacingCO->addItem(qt_("Double Quad (2 em)"), toqstr("qquad"));
54 spacingCO->addItem(qt_("Horizontal Fill"), toqstr("hfill"));
55 spacingCO->addItem(qt_("Custom"), toqstr("custom"));
57 spacingCO->addItem(qt_("Interword Space"), toqstr("normal"));
58 spacingCO->addItem(qt_("Thin Space"), toqstr("thinspace"));
59 spacingCO->addItem(qt_("Negative Thin Space"), toqstr("negthinspace"));
60 spacingCO->addItem(qt_("Negative Medium Space"), toqstr("negmedspace"));
61 spacingCO->addItem(qt_("Negative Thick Space"), toqstr("negthickspace"));
62 spacingCO->addItem(qt_("Half Quad (0.5 em)"), toqstr("halfquad"));
63 spacingCO->addItem(qt_("Quad (1 em)"), toqstr("quad"));
64 spacingCO->addItem(qt_("Double Quad (2 em)"), toqstr("qquad"));
65 spacingCO->addItem(qt_("Horizontal Fill"), toqstr("hfill"));
66 spacingCO->addItem(qt_("Custom"), toqstr("custom"));
67 spacingCO->addItem(qt_("Visible Space"), toqstr("visible"));
70 connect(spacingCO, SIGNAL(highlighted(QString)),
71 this, SLOT(changedSlot()));
72 connect(valueLE, SIGNAL(textChanged(QString)),
73 this, SLOT(changedSlot()));
74 connect(spacingCO, SIGNAL(activated(int)),
75 this, SLOT(changedSlot()));
76 connect(keepCB, SIGNAL(clicked()),
77 this, SLOT(changedSlot()));
78 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
79 this, SLOT(changedSlot()));
80 connect(fillPatternCO, SIGNAL(activated(int)),
81 this, SLOT(changedSlot()));
84 valueLE->setValidator(unsignedLengthValidator(valueLE));
86 valueLE->setValidator(unsignedGlueLengthValidator(valueLE));
88 // initialize the length validator
89 addCheckedWidget(valueLE, valueL);
93 void GuiHSpace::changedSlot()
100 void GuiHSpace::enableWidgets()
102 QString const selection = spacingCO->itemData(spacingCO->currentIndex()).toString();
103 bool const custom = selection == "custom";
104 valueLE->setEnabled(custom);
105 unitCO->setEnabled(custom);
106 fillPatternCO->setEnabled(!math_mode_ && selection == "hfill");
107 bool const no_pattern = fillPatternCO->currentIndex() == 0 || math_mode_;
108 bool const enable_keep =
109 selection == "normal" || selection == "halfquad" || (selection == "hfill" && no_pattern) || custom;
110 keepCB->setEnabled(enable_keep);
114 void GuiHSpace::paramsToDialog(Inset const * inset)
116 InsetSpaceParams const params = math_mode_
117 ? static_cast<InsetMathSpace const *>(inset)->params()
118 : static_cast<InsetSpace const *>(inset)->params();
122 bool protect = false;
123 switch (params.kind) {
124 case InsetSpaceParams::NORMAL:
127 case InsetSpaceParams::PROTECTED:
131 case InsetSpaceParams::VISIBLE:
135 case InsetSpaceParams::THIN:
138 case InsetSpaceParams::MEDIUM:
141 case InsetSpaceParams::THICK:
144 case InsetSpaceParams::NEGTHIN:
145 item = "negthinspace";
147 case InsetSpaceParams::NEGMEDIUM:
148 item = "negmedspace";
150 case InsetSpaceParams::NEGTHICK:
151 item = "negthickspace";
153 case InsetSpaceParams::ENSKIP:
156 case InsetSpaceParams::ENSPACE:
160 case InsetSpaceParams::QUAD:
163 case InsetSpaceParams::QQUAD:
166 case InsetSpaceParams::HFILL:
169 case InsetSpaceParams::HFILL_PROTECTED:
173 case InsetSpaceParams::DOTFILL:
177 case InsetSpaceParams::HRULEFILL:
181 case InsetSpaceParams::LEFTARROWFILL:
185 case InsetSpaceParams::RIGHTARROWFILL:
189 case InsetSpaceParams::UPBRACEFILL:
193 case InsetSpaceParams::DOWNBRACEFILL:
197 case InsetSpaceParams::CUSTOM:
200 case InsetSpaceParams::CUSTOM_PROTECTED:
205 spacingCO->setCurrentIndex(spacingCO->findData(item));
206 fillPatternCO->setCurrentIndex(pattern);
207 keepCB->setChecked(protect);
208 if (item == "halfquad") {
209 keepCB->setToolTip(qt_("Insert the spacing even after a line break.\n"
210 "Note that a protected Half Quad will be turned into\n"
211 "a vertical space if used at the beginning of a paragraph!"));
213 keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
215 Length::UNIT const default_unit = Length::defaultUnit();
216 if (item == "custom") {
217 string length = params.length.asString();
218 lengthToWidgets(valueLE, unitCO, length, default_unit);
220 lengthToWidgets(valueLE, unitCO, "", default_unit);
226 docstring GuiHSpace::dialogToParams() const
228 InsetSpaceParams params = math_mode_ ?
229 InsetSpaceParams(true) : InsetSpaceParams(false);
232 spacingCO->itemData(spacingCO->currentIndex()).toString();
234 if (item == "normal")
235 params.kind = keepCB->isChecked() ?
236 InsetSpaceParams::PROTECTED : InsetSpaceParams::NORMAL;
237 else if (item == "thinspace")
238 params.kind = InsetSpaceParams::THIN;
239 else if (item == "medspace")
240 params.kind = InsetSpaceParams::MEDIUM;
241 else if (item == "thickspace")
242 params.kind = InsetSpaceParams::THICK;
243 else if (item == "negthinspace")
244 params.kind = InsetSpaceParams::NEGTHIN;
245 else if (item == "negmedspace")
246 params.kind = InsetSpaceParams::NEGMEDIUM;
247 else if (item == "negthickspace")
248 params.kind = InsetSpaceParams::NEGTHICK;
249 else if (item == "halfquad")
250 params.kind = keepCB->isChecked() ?
251 InsetSpaceParams::ENSPACE : InsetSpaceParams::ENSKIP;
252 else if (item == "quad")
253 params.kind = InsetSpaceParams::QUAD;
254 else if (item == "qquad")
255 params.kind = InsetSpaceParams::QQUAD;
256 else if (item == "hfill") {
257 switch (fillPatternCO->currentIndex()) {
259 params.kind = InsetSpaceParams::DOTFILL;
262 params.kind = InsetSpaceParams::HRULEFILL;
265 params.kind = InsetSpaceParams::LEFTARROWFILL;
268 params.kind = InsetSpaceParams::RIGHTARROWFILL;
271 params.kind = InsetSpaceParams::UPBRACEFILL;
274 params.kind = InsetSpaceParams::DOWNBRACEFILL;
277 if (keepCB->isChecked())
278 params.kind = InsetSpaceParams::HFILL_PROTECTED;
280 params.kind = InsetSpaceParams::HFILL;
283 } else if (item == "custom") {
284 params.kind = keepCB->isChecked() ?
285 InsetSpaceParams::CUSTOM_PROTECTED : InsetSpaceParams::CUSTOM;
286 params.length = GlueLength(widgetsToLength(valueLE, unitCO));
287 } else if (item == "visible")
288 params.kind = InsetSpaceParams::VISIBLE;
290 return from_ascii(InsetSpace::params2string(params));
294 bool GuiHSpace::checkWidgets() const
296 if (!InsetParamsWidget::checkWidgets())
298 return spacingCO->itemData(spacingCO->currentIndex()).toString() != "custom"
299 || !valueLE->text().isEmpty();
302 } // namespace frontend
306 #include "moc_GuiHSpace.cpp"