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"));
46 spacingCO->addItem(qt_("Medium Space"));
47 spacingCO->addItem(qt_("Thick Space"));
48 spacingCO->addItem(qt_("Negative Thin Space"));
49 spacingCO->addItem(qt_("Negative Medium Space"));
50 spacingCO->addItem(qt_("Negative Thick Space"));
51 spacingCO->addItem(qt_("Half Quad (0.5 em)"));
52 spacingCO->addItem(qt_("Quad (1 em)"));
53 spacingCO->addItem(qt_("Double Quad (2 em)"));
54 spacingCO->addItem(qt_("Custom"));
56 spacingCO->addItem(qt_("Interword Space"));
57 spacingCO->addItem(qt_("Thin Space"));
58 spacingCO->addItem(qt_("Negative Thin Space"));
59 spacingCO->addItem(qt_("Half Quad (0.5 em)"));
60 spacingCO->addItem(qt_("Quad (1 em)"));
61 spacingCO->addItem(qt_("Double Quad (2 em)"));
62 spacingCO->addItem(qt_("Horizontal Fill"));
63 spacingCO->addItem(qt_("Custom"));
66 connect(spacingCO, SIGNAL(highlighted(QString)),
67 this, SLOT(changedSlot()));
68 connect(valueLE, SIGNAL(textChanged(QString)),
69 this, SLOT(changedSlot()));
70 connect(spacingCO, SIGNAL(activated(int)),
71 this, SLOT(changedSlot()));
72 connect(keepCB, SIGNAL(clicked()),
73 this, SLOT(changedSlot()));
74 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
75 this, SLOT(changedSlot()));
76 connect(fillPatternCO, SIGNAL(activated(int)),
77 this, SLOT(changedSlot()));
80 valueLE->setValidator(unsignedLengthValidator(valueLE));
82 valueLE->setValidator(unsignedGlueLengthValidator(valueLE));
84 // initialize the length validator
85 addCheckedWidget(valueLE, valueL);
89 void GuiHSpace::changedSlot()
96 void GuiHSpace::enableWidgets()
98 int const selection = spacingCO->currentIndex();
99 bool const custom = (selection == spacingCO->count() - 1);
100 valueLE->setEnabled(custom);
101 unitCO->setEnabled(custom);
103 fillPatternCO->setEnabled(false);
104 keepCB->setEnabled(false);
107 fillPatternCO->setEnabled(selection == 6);
108 bool const no_pattern = fillPatternCO->currentIndex() == 0;
109 bool const enable_keep =
110 selection == 0 || selection == 3 ||
111 (selection == 6 && no_pattern) || custom;
112 keepCB->setEnabled(enable_keep);
116 void GuiHSpace::paramsToDialog(Inset const * inset)
118 InsetSpaceParams const params = math_mode_
119 ? static_cast<InsetMathSpace const *>(inset)->params()
120 : static_cast<InsetSpace const *>(inset)->params();
124 bool protect = false;
125 switch (params.kind) {
126 case InsetSpaceParams::NORMAL:
129 case InsetSpaceParams::PROTECTED:
131 protect = !params.math;
133 case InsetSpaceParams::THIN:
134 item = params.math ? 0 : 1;
136 case InsetSpaceParams::MEDIUM:
139 case InsetSpaceParams::THICK:
140 item = params.math ? 2 : 1;
142 case InsetSpaceParams::NEGTHIN:
143 item = params.math ? 3 : 2;
145 case InsetSpaceParams::NEGMEDIUM:
146 item = params.math ? 4 : 2;
148 case InsetSpaceParams::NEGTHICK:
149 item = params.math ? 5 : 2;
151 case InsetSpaceParams::ENSKIP:
152 item = params.math ? 6 : 3;
154 case InsetSpaceParams::ENSPACE:
155 item = params.math ? 6 : 3;
156 protect = !params.math;
158 case InsetSpaceParams::QUAD:
159 item = params.math ? 7 : 4;
161 case InsetSpaceParams::QQUAD:
162 item = params.math ? 8 : 5;
164 case InsetSpaceParams::HFILL:
165 item = params.math ? 3 : 6;
167 case InsetSpaceParams::HFILL_PROTECTED:
168 item = params.math ? 3 : 6;
169 protect = !params.math;
171 case InsetSpaceParams::DOTFILL:
172 item = params.math ? 3 : 6;
175 case InsetSpaceParams::HRULEFILL:
176 item = params.math ? 3 : 6;
179 case InsetSpaceParams::LEFTARROWFILL:
180 item = params.math ? 3 : 6;
183 case InsetSpaceParams::RIGHTARROWFILL:
184 item = params.math ? 3 : 6;
187 case InsetSpaceParams::UPBRACEFILL:
188 item = params.math ? 3 : 6;
191 case InsetSpaceParams::DOWNBRACEFILL:
192 item = params.math ? 3 : 6;
195 case InsetSpaceParams::CUSTOM:
196 item = params.math ? 9 : 7;
198 case InsetSpaceParams::CUSTOM_PROTECTED:
199 item = params.math ? 9 : 7;
200 protect = !params.math;
203 spacingCO->setCurrentIndex(item);
204 fillPatternCO->setCurrentIndex(pattern);
205 keepCB->setChecked(protect);
207 keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
208 } else if (item == 3) {
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 == (params.math ? 9 : 7)) {
217 string length = params.length.asString();
218 lengthToWidgets(valueLE, unitCO, length, default_unit);
220 lengthToWidgets(valueLE, unitCO, "", default_unit);
226 docstring GuiHSpace::dialogToMathParams() const
228 InsetSpaceParams params(true);
229 switch (spacingCO->currentIndex()) {
230 case 0: params.kind = InsetSpaceParams::THIN; break;
231 case 1: params.kind = InsetSpaceParams::MEDIUM; break;
232 case 2: params.kind = InsetSpaceParams::THICK; break;
233 case 3: params.kind = InsetSpaceParams::NEGTHIN; break;
234 case 4: params.kind = InsetSpaceParams::NEGMEDIUM; break;
235 case 5: params.kind = InsetSpaceParams::NEGTHICK; break;
236 case 6: params.kind = InsetSpaceParams::ENSKIP; break;
237 case 7: params.kind = InsetSpaceParams::QUAD; break;
238 case 8: params.kind = InsetSpaceParams::QQUAD; break;
240 params.kind = InsetSpaceParams::CUSTOM;
241 params.length = GlueLength(widgetsToLength(valueLE, unitCO));
244 return from_ascii(InsetSpace::params2string(params));
248 docstring GuiHSpace::dialogToParams() const
251 return dialogToMathParams();
253 InsetSpaceParams params(false);
255 switch (spacingCO->currentIndex()) {
257 if (keepCB->isChecked())
258 params.kind = InsetSpaceParams::PROTECTED;
260 params.kind = InsetSpaceParams::NORMAL;
263 params.kind = InsetSpaceParams::THIN;
266 params.kind = InsetSpaceParams::NEGTHIN;
269 if (keepCB->isChecked())
270 params.kind = InsetSpaceParams::ENSPACE;
272 params.kind = InsetSpaceParams::ENSKIP;
275 params.kind = InsetSpaceParams::QUAD;
278 params.kind = InsetSpaceParams::QQUAD;
281 switch (fillPatternCO->currentIndex()) {
283 params.kind = InsetSpaceParams::DOTFILL;
286 params.kind = InsetSpaceParams::HRULEFILL;
289 params.kind = InsetSpaceParams::LEFTARROWFILL;
292 params.kind = InsetSpaceParams::RIGHTARROWFILL;
295 params.kind = InsetSpaceParams::UPBRACEFILL;
298 params.kind = InsetSpaceParams::DOWNBRACEFILL;
301 if (keepCB->isChecked())
302 params.kind = InsetSpaceParams::HFILL_PROTECTED;
304 params.kind = InsetSpaceParams::HFILL;
309 if (keepCB->isChecked())
310 params.kind = InsetSpaceParams::CUSTOM_PROTECTED;
312 params.kind = InsetSpaceParams::CUSTOM;
313 params.length = GlueLength(widgetsToLength(valueLE, unitCO));
316 return from_ascii(InsetSpace::params2string(params));
320 bool GuiHSpace::checkWidgets() const
322 if (!InsetParamsWidget::checkWidgets())
324 return spacingCO->currentIndex() != (math_mode_ ? 9 : 7)
325 || !valueLE->text().isEmpty();
328 } // namespace frontend
332 #include "moc_GuiHSpace.cpp"