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_("Interword 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);
118 void GuiHSpace::paramsToDialog(Inset const * inset)
120 InsetSpaceParams const params = math_mode_
121 ? static_cast<InsetMathSpace const *>(inset)->params()
122 : static_cast<InsetSpace const *>(inset)->params();
126 bool protect = false;
127 switch (params.kind) {
128 case InsetSpaceParams::NORMAL:
131 case InsetSpaceParams::PROTECTED:
135 case InsetSpaceParams::VISIBLE:
139 case InsetSpaceParams::THIN:
142 case InsetSpaceParams::MEDIUM:
145 case InsetSpaceParams::THICK:
148 case InsetSpaceParams::NEGTHIN:
149 item = "negthinspace";
151 case InsetSpaceParams::NEGMEDIUM:
152 item = "negmedspace";
154 case InsetSpaceParams::NEGTHICK:
155 item = "negthickspace";
157 case InsetSpaceParams::ENSKIP:
160 case InsetSpaceParams::ENSPACE:
164 case InsetSpaceParams::QUAD:
167 case InsetSpaceParams::QQUAD:
170 case InsetSpaceParams::HFILL:
173 case InsetSpaceParams::HFILL_PROTECTED:
177 case InsetSpaceParams::DOTFILL:
181 case InsetSpaceParams::HRULEFILL:
185 case InsetSpaceParams::LEFTARROWFILL:
189 case InsetSpaceParams::RIGHTARROWFILL:
193 case InsetSpaceParams::UPBRACEFILL:
197 case InsetSpaceParams::DOWNBRACEFILL:
201 case InsetSpaceParams::CUSTOM:
204 case InsetSpaceParams::CUSTOM_PROTECTED:
209 spacingCO->setCurrentIndex(spacingCO->findData(item));
210 fillPatternCO->setCurrentIndex(pattern);
211 keepCB->setChecked(protect);
212 if (item == "halfquad") {
213 keepCB->setToolTip(qt_("Insert the spacing even after a line break.\n"
214 "Note that a protected Half Quad will be turned into\n"
215 "a vertical space if used at the beginning of a paragraph!"));
217 keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
219 Length::UNIT const default_unit = Length::defaultUnit();
220 if (item == "custom") {
221 string length = params.length.asString();
222 lengthToWidgets(valueLE, unitCO, length, default_unit);
224 lengthToWidgets(valueLE, unitCO, "", default_unit);
230 docstring GuiHSpace::dialogToParams() const
232 InsetSpaceParams params = math_mode_ ?
233 InsetSpaceParams(true) : InsetSpaceParams(false);
236 spacingCO->itemData(spacingCO->currentIndex()).toString();
238 if (item == "normal")
239 params.kind = keepCB->isChecked() ?
240 InsetSpaceParams::PROTECTED : InsetSpaceParams::NORMAL;
241 else if (item == "thinspace")
242 params.kind = InsetSpaceParams::THIN;
243 else if (item == "medspace")
244 params.kind = InsetSpaceParams::MEDIUM;
245 else if (item == "thickspace")
246 params.kind = InsetSpaceParams::THICK;
247 else if (item == "negthinspace")
248 params.kind = InsetSpaceParams::NEGTHIN;
249 else if (item == "negmedspace")
250 params.kind = InsetSpaceParams::NEGMEDIUM;
251 else if (item == "negthickspace")
252 params.kind = InsetSpaceParams::NEGTHICK;
253 else if (item == "halfquad")
254 params.kind = keepCB->isChecked() ?
255 InsetSpaceParams::ENSPACE : InsetSpaceParams::ENSKIP;
256 else if (item == "quad")
257 params.kind = InsetSpaceParams::QUAD;
258 else if (item == "qquad")
259 params.kind = InsetSpaceParams::QQUAD;
260 else if (item == "hfill") {
261 switch (fillPatternCO->currentIndex()) {
263 params.kind = InsetSpaceParams::DOTFILL;
266 params.kind = InsetSpaceParams::HRULEFILL;
269 params.kind = InsetSpaceParams::LEFTARROWFILL;
272 params.kind = InsetSpaceParams::RIGHTARROWFILL;
275 params.kind = InsetSpaceParams::UPBRACEFILL;
278 params.kind = InsetSpaceParams::DOWNBRACEFILL;
281 if (keepCB->isChecked())
282 params.kind = InsetSpaceParams::HFILL_PROTECTED;
284 params.kind = InsetSpaceParams::HFILL;
287 } else if (item == "custom") {
288 params.kind = keepCB->isChecked() ?
289 InsetSpaceParams::CUSTOM_PROTECTED : InsetSpaceParams::CUSTOM;
290 params.length = GlueLength(widgetsToLength(valueLE, unitCO));
291 } else if (item == "visible")
292 params.kind = InsetSpaceParams::VISIBLE;
294 return from_ascii(InsetSpace::params2string(params));
298 bool GuiHSpace::checkWidgets(bool readonly) const
300 valueLE->setReadOnly(readonly);
301 spacingCO->setEnabled(!readonly);
302 spacingL->setEnabled(!readonly);
305 fillPatternCO->setEnabled(false);
306 fillPatternL->setEnabled(false);
307 keepCB->setEnabled(false);
308 keepL->setEnabled(false);
309 valueLE->setEnabled(false);
310 valueL->setEnabled(false);
311 unitCO->setEnabled(false);
315 if (!InsetParamsWidget::checkWidgets())
317 return spacingCO->itemData(spacingCO->currentIndex()).toString() != "custom"
318 || !valueLE->text().isEmpty();
321 } // namespace frontend
325 #include "moc_GuiHSpace.cpp"