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 valueL->setEnabled(custom);
108 unitCO->setEnabled(custom);
109 fillPatternCO->setEnabled(!math_mode_ && selection == "hfill");
110 fillPatternL->setEnabled(!math_mode_ && selection == "hfill");
111 bool const no_pattern = fillPatternCO->currentIndex() == 0 || math_mode_;
112 bool const enable_keep =
113 selection == "normal" || selection == "halfquad"
114 || (selection == "hfill" && no_pattern) || custom;
115 keepCB->setEnabled(enable_keep);
116 keepL->setEnabled(enable_keep);
120 void GuiHSpace::paramsToDialog(Inset const * inset)
122 InsetSpaceParams const params = math_mode_
123 ? static_cast<InsetMathSpace const *>(inset)->params()
124 : static_cast<InsetSpace const *>(inset)->params();
128 bool protect = false;
129 switch (params.kind) {
130 case InsetSpaceParams::NORMAL:
133 case InsetSpaceParams::PROTECTED:
137 case InsetSpaceParams::VISIBLE:
141 case InsetSpaceParams::THIN:
144 case InsetSpaceParams::MEDIUM:
147 case InsetSpaceParams::THICK:
150 case InsetSpaceParams::NEGTHIN:
151 item = "negthinspace";
153 case InsetSpaceParams::NEGMEDIUM:
154 item = "negmedspace";
156 case InsetSpaceParams::NEGTHICK:
157 item = "negthickspace";
159 case InsetSpaceParams::ENSKIP:
162 case InsetSpaceParams::ENSPACE:
166 case InsetSpaceParams::QUAD:
169 case InsetSpaceParams::QQUAD:
172 case InsetSpaceParams::HFILL:
175 case InsetSpaceParams::HFILL_PROTECTED:
179 case InsetSpaceParams::DOTFILL:
183 case InsetSpaceParams::HRULEFILL:
187 case InsetSpaceParams::LEFTARROWFILL:
191 case InsetSpaceParams::RIGHTARROWFILL:
195 case InsetSpaceParams::UPBRACEFILL:
199 case InsetSpaceParams::DOWNBRACEFILL:
203 case InsetSpaceParams::CUSTOM:
206 case InsetSpaceParams::CUSTOM_PROTECTED:
211 spacingCO->setCurrentIndex(spacingCO->findData(item));
212 fillPatternCO->setCurrentIndex(pattern);
213 keepCB->setChecked(protect);
214 if (item == "halfquad") {
215 keepCB->setToolTip(qt_("Insert the spacing even after a line break.\n"
216 "Note that a protected Half Quad will be turned into\n"
217 "a vertical space if used at the beginning of a paragraph!"));
219 keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
221 Length::UNIT const default_unit = Length::defaultUnit();
222 if (item == "custom") {
223 string length = params.length.asString();
224 lengthToWidgets(valueLE, unitCO, length, default_unit);
226 lengthToWidgets(valueLE, unitCO, "", default_unit);
232 docstring GuiHSpace::dialogToParams() const
234 InsetSpaceParams params = math_mode_ ?
235 InsetSpaceParams(true) : InsetSpaceParams(false);
238 spacingCO->itemData(spacingCO->currentIndex()).toString();
240 if (item == "normal")
241 params.kind = keepCB->isChecked() ?
242 InsetSpaceParams::PROTECTED : InsetSpaceParams::NORMAL;
243 else if (item == "thinspace")
244 params.kind = InsetSpaceParams::THIN;
245 else if (item == "medspace")
246 params.kind = InsetSpaceParams::MEDIUM;
247 else if (item == "thickspace")
248 params.kind = InsetSpaceParams::THICK;
249 else if (item == "negthinspace")
250 params.kind = InsetSpaceParams::NEGTHIN;
251 else if (item == "negmedspace")
252 params.kind = InsetSpaceParams::NEGMEDIUM;
253 else if (item == "negthickspace")
254 params.kind = InsetSpaceParams::NEGTHICK;
255 else if (item == "halfquad")
256 params.kind = keepCB->isChecked() ?
257 InsetSpaceParams::ENSPACE : InsetSpaceParams::ENSKIP;
258 else if (item == "quad")
259 params.kind = InsetSpaceParams::QUAD;
260 else if (item == "qquad")
261 params.kind = InsetSpaceParams::QQUAD;
262 else if (item == "hfill") {
263 switch (fillPatternCO->currentIndex()) {
265 params.kind = InsetSpaceParams::DOTFILL;
268 params.kind = InsetSpaceParams::HRULEFILL;
271 params.kind = InsetSpaceParams::LEFTARROWFILL;
274 params.kind = InsetSpaceParams::RIGHTARROWFILL;
277 params.kind = InsetSpaceParams::UPBRACEFILL;
280 params.kind = InsetSpaceParams::DOWNBRACEFILL;
283 if (keepCB->isChecked())
284 params.kind = InsetSpaceParams::HFILL_PROTECTED;
286 params.kind = InsetSpaceParams::HFILL;
289 } else if (item == "custom") {
290 params.kind = keepCB->isChecked() ?
291 InsetSpaceParams::CUSTOM_PROTECTED : InsetSpaceParams::CUSTOM;
292 params.length = GlueLength(widgetsToLength(valueLE, unitCO));
293 } else if (item == "visible")
294 params.kind = InsetSpaceParams::VISIBLE;
296 return from_ascii(InsetSpace::params2string(params));
300 bool GuiHSpace::checkWidgets() const
302 if (!InsetParamsWidget::checkWidgets())
304 return spacingCO->itemData(spacingCO->currentIndex()).toString() != "custom"
305 || !valueLE->text().isEmpty();
308 } // namespace frontend
312 #include "moc_GuiHSpace.cpp"