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"
20 #include "FuncRequest.h"
22 #include "insets/InsetSpace.h"
24 #include "mathed/InsetMathSpace.h"
26 #include "support/gettext.h"
27 #include "support/lstrings.h"
31 #include <QPushButton>
39 GuiHSpace::GuiHSpace(bool math_mode, QWidget * parent)
40 : InsetParamsWidget(parent), math_mode_(math_mode)
46 spacingCO->addItem(qt_("Thin Space"));
47 spacingCO->addItem(qt_("Medium Space"));
48 spacingCO->addItem(qt_("Thick Space"));
49 spacingCO->addItem(qt_("Negative Thin Space"));
50 spacingCO->addItem(qt_("Negative Medium Space"));
51 spacingCO->addItem(qt_("Negative Thick Space"));
52 spacingCO->addItem(qt_("Half Quad (0.5 em)"));
53 spacingCO->addItem(qt_("Quad (1 em)"));
54 spacingCO->addItem(qt_("Double Quad (2 em)"));
55 spacingCO->addItem(qt_("Custom"));
57 spacingCO->addItem(qt_("Interword Space"));
58 spacingCO->addItem(qt_("Thin Space"));
59 spacingCO->addItem(qt_("Negative Thin Space"));
60 spacingCO->addItem(qt_("Half Quad (0.5 em)"));
61 spacingCO->addItem(qt_("Quad (1 em)"));
62 spacingCO->addItem(qt_("Double Quad (2 em)"));
63 spacingCO->addItem(qt_("Horizontal Fill"));
64 spacingCO->addItem(qt_("Custom"));
67 connect(spacingCO, SIGNAL(highlighted(QString)),
68 this, SLOT(changedSlot()));
69 connect(valueLE, SIGNAL(textChanged(QString)),
70 this, SLOT(changedSlot()));
71 connect(spacingCO, SIGNAL(activated(int)),
72 this, SLOT(changedSlot()));
73 connect(keepCB, SIGNAL(clicked()),
74 this, SLOT(changedSlot()));
75 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
76 this, SLOT(changedSlot()));
77 connect(fillPatternCO, SIGNAL(activated(int)),
78 this, SLOT(changedSlot()));
81 valueLE->setValidator(unsignedLengthValidator(valueLE));
83 valueLE->setValidator(unsignedGlueLengthValidator(valueLE));
85 // initialize the length validator
86 addCheckedWidget(valueLE, valueL);
90 void GuiHSpace::changedSlot()
97 void GuiHSpace::enableWidgets()
99 int const selection = spacingCO->currentIndex();
100 bool const custom = (selection == spacingCO->count() - 1);
101 valueLE->setEnabled(custom);
102 unitCO->setEnabled(custom);
104 fillPatternCO->setEnabled(false);
105 keepCB->setEnabled(false);
108 fillPatternCO->setEnabled(selection == 6);
109 bool const no_pattern = fillPatternCO->currentIndex() == 0;
110 bool const enable_keep =
111 selection == 0 || selection == 3 ||
112 (selection == 6 && no_pattern) || custom;
113 keepCB->setEnabled(enable_keep);
117 void GuiHSpace::paramsToDialog(Inset const * inset)
119 InsetSpaceParams const params = math_mode_
120 ? static_cast<InsetMathSpace const *>(inset)->params()
121 : static_cast<InsetSpace const *>(inset)->params();
125 bool protect = false;
126 switch (params.kind) {
127 case InsetSpaceParams::NORMAL:
130 case InsetSpaceParams::PROTECTED:
132 protect = !params.math;
134 case InsetSpaceParams::THIN:
135 item = params.math ? 0 : 1;
137 case InsetSpaceParams::MEDIUM:
140 case InsetSpaceParams::THICK:
141 item = params.math ? 2 : 1;
143 case InsetSpaceParams::NEGTHIN:
144 item = params.math ? 3 : 2;
146 case InsetSpaceParams::NEGMEDIUM:
147 item = params.math ? 4 : 2;
149 case InsetSpaceParams::NEGTHICK:
150 item = params.math ? 5 : 2;
152 case InsetSpaceParams::ENSKIP:
153 item = params.math ? 6 : 3;
155 case InsetSpaceParams::ENSPACE:
156 item = params.math ? 6 : 3;
157 protect = !params.math;
159 case InsetSpaceParams::QUAD:
160 item = params.math ? 7 : 4;
162 case InsetSpaceParams::QQUAD:
163 item = params.math ? 8 : 5;
165 case InsetSpaceParams::HFILL:
166 item = params.math ? 3 : 6;
168 case InsetSpaceParams::HFILL_PROTECTED:
169 item = params.math ? 3 : 6;
170 protect = !params.math;
172 case InsetSpaceParams::DOTFILL:
173 item = params.math ? 3 : 6;
176 case InsetSpaceParams::HRULEFILL:
177 item = params.math ? 3 : 6;
180 case InsetSpaceParams::LEFTARROWFILL:
181 item = params.math ? 3 : 6;
184 case InsetSpaceParams::RIGHTARROWFILL:
185 item = params.math ? 3 : 6;
188 case InsetSpaceParams::UPBRACEFILL:
189 item = params.math ? 3 : 6;
192 case InsetSpaceParams::DOWNBRACEFILL:
193 item = params.math ? 3 : 6;
196 case InsetSpaceParams::CUSTOM:
197 item = params.math ? 9 : 7;
199 case InsetSpaceParams::CUSTOM_PROTECTED:
200 item = params.math ? 9 : 7;
201 protect = !params.math;
204 spacingCO->setCurrentIndex(item);
205 fillPatternCO->setCurrentIndex(pattern);
206 keepCB->setChecked(protect);
208 keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
209 } else if (item == 3) {
210 keepCB->setToolTip(qt_("Insert the spacing even after a line break.\n"
211 "Note that a protected Half Quad will be turned into\n"
212 "a vertical space if used at the beginning of a paragraph!"));
214 keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
216 Length::UNIT const default_unit = Length::defaultUnit();
217 if (item == (params.math ? 9 : 7)) {
218 string length = params.length.asString();
219 lengthToWidgets(valueLE, unitCO, length, default_unit);
221 lengthToWidgets(valueLE, unitCO, "", default_unit);
227 docstring GuiHSpace::dialogToMathParams() const
229 InsetSpaceParams params(true);
230 switch (spacingCO->currentIndex()) {
231 case 0: params.kind = InsetSpaceParams::THIN; break;
232 case 1: params.kind = InsetSpaceParams::MEDIUM; break;
233 case 2: params.kind = InsetSpaceParams::THICK; break;
234 case 3: params.kind = InsetSpaceParams::NEGTHIN; break;
235 case 4: params.kind = InsetSpaceParams::NEGMEDIUM; break;
236 case 5: params.kind = InsetSpaceParams::NEGTHICK; break;
237 case 6: params.kind = InsetSpaceParams::ENSKIP; break;
238 case 7: params.kind = InsetSpaceParams::QUAD; break;
239 case 8: params.kind = InsetSpaceParams::QQUAD; break;
241 params.kind = InsetSpaceParams::CUSTOM;
242 params.length = GlueLength(widgetsToLength(valueLE, unitCO));
245 return from_ascii(InsetSpace::params2string(params));
249 docstring GuiHSpace::dialogToParams() const
252 return dialogToMathParams();
254 InsetSpaceParams params(false);
256 switch (spacingCO->currentIndex()) {
258 if (keepCB->isChecked())
259 params.kind = InsetSpaceParams::PROTECTED;
261 params.kind = InsetSpaceParams::NORMAL;
264 params.kind = InsetSpaceParams::THIN;
267 params.kind = InsetSpaceParams::NEGTHIN;
270 if (keepCB->isChecked())
271 params.kind = InsetSpaceParams::ENSPACE;
273 params.kind = InsetSpaceParams::ENSKIP;
276 params.kind = InsetSpaceParams::QUAD;
279 params.kind = InsetSpaceParams::QQUAD;
282 switch (fillPatternCO->currentIndex()) {
284 params.kind = InsetSpaceParams::DOTFILL;
287 params.kind = InsetSpaceParams::HRULEFILL;
290 params.kind = InsetSpaceParams::LEFTARROWFILL;
293 params.kind = InsetSpaceParams::RIGHTARROWFILL;
296 params.kind = InsetSpaceParams::UPBRACEFILL;
299 params.kind = InsetSpaceParams::DOWNBRACEFILL;
302 if (keepCB->isChecked())
303 params.kind = InsetSpaceParams::HFILL_PROTECTED;
305 params.kind = InsetSpaceParams::HFILL;
310 if (keepCB->isChecked())
311 params.kind = InsetSpaceParams::CUSTOM_PROTECTED;
313 params.kind = InsetSpaceParams::CUSTOM;
314 params.length = GlueLength(widgetsToLength(valueLE, unitCO));
317 return from_ascii(InsetSpace::params2string(params));
321 bool GuiHSpace::checkWidgets() const
323 if (!InsetParamsWidget::checkWidgets())
325 return spacingCO->currentIndex() != (math_mode_ ? 9 : 7)
326 || !valueLE->text().isEmpty();
329 } // namespace frontend
333 #include "moc_GuiHSpace.cpp"