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()));
84 // Set up a signed (glue) length validator
85 LengthValidator * v = new LengthValidator(valueLE);
87 v->setBottom(Length());
89 v->setBottom(GlueLength());
90 valueLE->setValidator(v);
92 // initialize the length validator
93 addCheckedWidget(valueLE, valueL);
98 void GuiHSpace::changedSlot()
105 void GuiHSpace::enableWidgets() const
107 QString const selection = spacingCO->itemData(spacingCO->currentIndex()).toString();
108 bool const custom = selection == "custom";
109 valueLE->setEnabled(custom);
112 valueL->setEnabled(custom);
113 unitCO->setEnabled(custom);
114 fillPatternCO->setEnabled(!math_mode_ && selection == "hfill");
115 fillPatternL->setEnabled(!math_mode_ && selection == "hfill");
116 bool const no_pattern = fillPatternCO->currentIndex() == 0 || math_mode_;
117 bool const enable_keep =
118 selection == "normal" || selection == "halfquad"
119 || (selection == "hfill" && no_pattern) || custom;
120 keepCB->setEnabled(enable_keep);
121 keepL->setEnabled(enable_keep);
125 void GuiHSpace::paramsToDialog(Inset const * inset)
127 InsetSpaceParams const params = math_mode_
128 ? static_cast<InsetMathSpace const *>(inset)->params()
129 : static_cast<InsetSpace const *>(inset)->params();
133 bool protect = false;
134 switch (params.kind) {
135 case InsetSpaceParams::NORMAL:
138 case InsetSpaceParams::PROTECTED:
142 case InsetSpaceParams::VISIBLE:
146 case InsetSpaceParams::THIN:
149 case InsetSpaceParams::MEDIUM:
152 case InsetSpaceParams::THICK:
155 case InsetSpaceParams::NEGTHIN:
156 item = "negthinspace";
158 case InsetSpaceParams::NEGMEDIUM:
159 item = "negmedspace";
161 case InsetSpaceParams::NEGTHICK:
162 item = "negthickspace";
164 case InsetSpaceParams::ENSKIP:
167 case InsetSpaceParams::ENSPACE:
171 case InsetSpaceParams::QUAD:
174 case InsetSpaceParams::QQUAD:
177 case InsetSpaceParams::HFILL:
180 case InsetSpaceParams::HFILL_PROTECTED:
184 case InsetSpaceParams::DOTFILL:
188 case InsetSpaceParams::HRULEFILL:
192 case InsetSpaceParams::LEFTARROWFILL:
196 case InsetSpaceParams::RIGHTARROWFILL:
200 case InsetSpaceParams::UPBRACEFILL:
204 case InsetSpaceParams::DOWNBRACEFILL:
208 case InsetSpaceParams::CUSTOM:
211 case InsetSpaceParams::CUSTOM_PROTECTED:
216 spacingCO->setCurrentIndex(spacingCO->findData(item));
217 fillPatternCO->setCurrentIndex(pattern);
218 keepCB->setChecked(protect);
219 if (item == "halfquad") {
220 keepCB->setToolTip(qt_("Insert the spacing even after a line break.\n"
221 "Note that a protected Half Quad will be turned into\n"
222 "a vertical space if used at the beginning of a paragraph!"));
224 keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
226 Length::UNIT const default_unit = Length::defaultUnit();
227 if (item == "custom") {
228 string length = params.length.asString();
229 lengthToWidgets(valueLE, unitCO, length, default_unit);
231 lengthToWidgets(valueLE, unitCO, "", default_unit);
237 docstring GuiHSpace::dialogToParams() const
239 InsetSpaceParams params = math_mode_ ?
240 InsetSpaceParams(true) : InsetSpaceParams(false);
243 spacingCO->itemData(spacingCO->currentIndex()).toString();
245 if (item == "normal")
246 params.kind = keepCB->isChecked() ?
247 InsetSpaceParams::PROTECTED : InsetSpaceParams::NORMAL;
248 else if (item == "thinspace")
249 params.kind = InsetSpaceParams::THIN;
250 else if (item == "medspace")
251 params.kind = InsetSpaceParams::MEDIUM;
252 else if (item == "thickspace")
253 params.kind = InsetSpaceParams::THICK;
254 else if (item == "negthinspace")
255 params.kind = InsetSpaceParams::NEGTHIN;
256 else if (item == "negmedspace")
257 params.kind = InsetSpaceParams::NEGMEDIUM;
258 else if (item == "negthickspace")
259 params.kind = InsetSpaceParams::NEGTHICK;
260 else if (item == "halfquad")
261 params.kind = keepCB->isChecked() ?
262 InsetSpaceParams::ENSPACE : InsetSpaceParams::ENSKIP;
263 else if (item == "quad")
264 params.kind = InsetSpaceParams::QUAD;
265 else if (item == "qquad")
266 params.kind = InsetSpaceParams::QQUAD;
267 else if (item == "hfill") {
268 switch (fillPatternCO->currentIndex()) {
270 params.kind = InsetSpaceParams::DOTFILL;
273 params.kind = InsetSpaceParams::HRULEFILL;
276 params.kind = InsetSpaceParams::LEFTARROWFILL;
279 params.kind = InsetSpaceParams::RIGHTARROWFILL;
282 params.kind = InsetSpaceParams::UPBRACEFILL;
285 params.kind = InsetSpaceParams::DOWNBRACEFILL;
288 if (keepCB->isChecked())
289 params.kind = InsetSpaceParams::HFILL_PROTECTED;
291 params.kind = InsetSpaceParams::HFILL;
294 } else if (item == "custom") {
295 params.kind = keepCB->isChecked() ?
296 InsetSpaceParams::CUSTOM_PROTECTED : InsetSpaceParams::CUSTOM;
297 params.length = GlueLength(widgetsToLength(valueLE, unitCO));
298 } else if (item == "visible")
299 params.kind = InsetSpaceParams::VISIBLE;
301 return from_ascii(InsetSpace::params2string(params));
305 bool GuiHSpace::checkWidgets(bool readonly) const
307 valueLE->setReadOnly(readonly);
310 spacingCO->setEnabled(false);
311 unitCO->setEnabled(false);
312 fillPatternCO->setEnabled(false);
313 keepCB->setEnabled(false);
314 valueLE->setEnabled(false);
318 if (!InsetParamsWidget::checkWidgets())
320 return spacingCO->itemData(spacingCO->currentIndex()).toString() != "custom"
321 || !valueLE->text().isEmpty();
324 } // namespace frontend
328 #include "moc_GuiHSpace.cpp"