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"));
64 spacingCO->addItem(qt_("Visible Space"));
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 = (math_mode_ && selection == 9) ||
101 (!math_mode_ && selection == 7);
102 valueLE->setEnabled(custom);
103 unitCO->setEnabled(custom);
105 fillPatternCO->setEnabled(false);
106 keepCB->setEnabled(false);
109 fillPatternCO->setEnabled(selection == 6);
110 bool const no_pattern = fillPatternCO->currentIndex() == 0;
111 bool const enable_keep =
112 selection == 0 || selection == 3 ||
113 (selection == 6 && no_pattern) || custom;
114 keepCB->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:
133 protect = !params.math;
135 case InsetSpaceParams::VISIBLE:
139 case InsetSpaceParams::THIN:
140 item = params.math ? 0 : 1;
142 case InsetSpaceParams::MEDIUM:
145 case InsetSpaceParams::THICK:
146 item = params.math ? 2 : 1;
148 case InsetSpaceParams::NEGTHIN:
149 item = params.math ? 3 : 2;
151 case InsetSpaceParams::NEGMEDIUM:
152 item = params.math ? 4 : 2;
154 case InsetSpaceParams::NEGTHICK:
155 item = params.math ? 5 : 2;
157 case InsetSpaceParams::ENSKIP:
158 item = params.math ? 6 : 3;
160 case InsetSpaceParams::ENSPACE:
161 item = params.math ? 6 : 3;
162 protect = !params.math;
164 case InsetSpaceParams::QUAD:
165 item = params.math ? 7 : 4;
167 case InsetSpaceParams::QQUAD:
168 item = params.math ? 8 : 5;
170 case InsetSpaceParams::HFILL:
171 item = params.math ? 3 : 6;
173 case InsetSpaceParams::HFILL_PROTECTED:
174 item = params.math ? 3 : 6;
175 protect = !params.math;
177 case InsetSpaceParams::DOTFILL:
178 item = params.math ? 3 : 6;
181 case InsetSpaceParams::HRULEFILL:
182 item = params.math ? 3 : 6;
185 case InsetSpaceParams::LEFTARROWFILL:
186 item = params.math ? 3 : 6;
189 case InsetSpaceParams::RIGHTARROWFILL:
190 item = params.math ? 3 : 6;
193 case InsetSpaceParams::UPBRACEFILL:
194 item = params.math ? 3 : 6;
197 case InsetSpaceParams::DOWNBRACEFILL:
198 item = params.math ? 3 : 6;
201 case InsetSpaceParams::CUSTOM:
202 item = params.math ? 9 : 7;
204 case InsetSpaceParams::CUSTOM_PROTECTED:
205 item = params.math ? 9 : 7;
206 protect = !params.math;
209 spacingCO->setCurrentIndex(item);
210 fillPatternCO->setCurrentIndex(pattern);
211 keepCB->setChecked(protect);
213 keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
214 } else if (item == 3) {
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 == (params.math ? 9 : 7)) {
223 string length = params.length.asString();
224 lengthToWidgets(valueLE, unitCO, length, default_unit);
226 lengthToWidgets(valueLE, unitCO, "", default_unit);
232 docstring GuiHSpace::dialogToMathParams() const
234 InsetSpaceParams params(true);
235 switch (spacingCO->currentIndex()) {
236 case 0: params.kind = InsetSpaceParams::THIN; break;
237 case 1: params.kind = InsetSpaceParams::MEDIUM; break;
238 case 2: params.kind = InsetSpaceParams::THICK; break;
239 case 3: params.kind = InsetSpaceParams::NEGTHIN; break;
240 case 4: params.kind = InsetSpaceParams::NEGMEDIUM; break;
241 case 5: params.kind = InsetSpaceParams::NEGTHICK; break;
242 case 6: params.kind = InsetSpaceParams::ENSKIP; break;
243 case 7: params.kind = InsetSpaceParams::QUAD; break;
244 case 8: params.kind = InsetSpaceParams::QQUAD; break;
246 params.kind = InsetSpaceParams::CUSTOM;
247 params.length = GlueLength(widgetsToLength(valueLE, unitCO));
250 return from_ascii(InsetSpace::params2string(params));
254 docstring GuiHSpace::dialogToParams() const
257 return dialogToMathParams();
259 InsetSpaceParams params(false);
261 switch (spacingCO->currentIndex()) {
263 if (keepCB->isChecked())
264 params.kind = InsetSpaceParams::PROTECTED;
266 params.kind = InsetSpaceParams::NORMAL;
269 params.kind = InsetSpaceParams::THIN;
272 params.kind = InsetSpaceParams::NEGTHIN;
275 if (keepCB->isChecked())
276 params.kind = InsetSpaceParams::ENSPACE;
278 params.kind = InsetSpaceParams::ENSKIP;
281 params.kind = InsetSpaceParams::QUAD;
284 params.kind = InsetSpaceParams::QQUAD;
287 switch (fillPatternCO->currentIndex()) {
289 params.kind = InsetSpaceParams::DOTFILL;
292 params.kind = InsetSpaceParams::HRULEFILL;
295 params.kind = InsetSpaceParams::LEFTARROWFILL;
298 params.kind = InsetSpaceParams::RIGHTARROWFILL;
301 params.kind = InsetSpaceParams::UPBRACEFILL;
304 params.kind = InsetSpaceParams::DOWNBRACEFILL;
307 if (keepCB->isChecked())
308 params.kind = InsetSpaceParams::HFILL_PROTECTED;
310 params.kind = InsetSpaceParams::HFILL;
315 if (keepCB->isChecked())
316 params.kind = InsetSpaceParams::CUSTOM_PROTECTED;
318 params.kind = InsetSpaceParams::CUSTOM;
319 params.length = GlueLength(widgetsToLength(valueLE, unitCO));
322 params.kind = InsetSpaceParams::VISIBLE;
325 return from_ascii(InsetSpace::params2string(params));
329 bool GuiHSpace::checkWidgets() const
331 if (!InsetParamsWidget::checkWidgets())
333 return spacingCO->currentIndex() != (math_mode_ ? 9 : 7)
334 || !valueLE->text().isEmpty();
337 } // namespace frontend
341 #include "moc_GuiHSpace.cpp"