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 "FuncRequest.h"
23 #include "insets/InsetSpace.h"
25 #include "support/gettext.h"
26 #include "support/lstrings.h"
30 #include <QPushButton>
38 GuiHSpace::GuiHSpace(GuiView & lv)
39 : GuiDialog(lv, "space", qt_("Horizontal Space Settings"))
43 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
44 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
45 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
47 connect(spacingCO, SIGNAL(highlighted(QString)),
48 this, SLOT(change_adaptor()));
49 connect(valueLE, SIGNAL(textChanged(QString)),
50 this, SLOT(change_adaptor()));
51 connect(spacingCO, SIGNAL(activated(int)),
52 this, SLOT(enableWidgets(int)));
53 connect(keepCB, SIGNAL(clicked()),
54 this, SLOT(change_adaptor()));
55 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
56 this, SLOT(change_adaptor()));
57 connect(fillPatternCO, SIGNAL(activated(int)),
58 this, SLOT(patternChanged()));
60 valueLE->setValidator(unsignedLengthValidator(valueLE));
62 // Manage the ok, apply, restore and cancel/close buttons
63 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
65 bc().setApply(applyPB);
66 bc().setCancel(closePB);
68 // disable for read-only documents
69 bc().addReadOnly(spacingCO);
70 bc().addReadOnly(valueLE);
71 bc().addReadOnly(unitCO);
72 bc().addReadOnly(keepCB);
73 bc().addReadOnly(fillPatternCO);
75 // initialize the length validator
76 bc().addCheckedLineEdit(valueLE, valueL);
78 // remove the %-items from the unit choice
83 void GuiHSpace::change_adaptor()
89 void GuiHSpace::enableWidgets(int selection)
91 valueLE->setEnabled(selection == 7);
92 unitCO->setEnabled(selection == 7);
93 fillPatternCO->setEnabled(selection == 6);
94 int pattern = fillPatternCO->currentIndex();
95 bool const enable_keep =
96 selection == 0 || selection == 3 ||
97 (selection == 6 && pattern == 0) || selection == 7;
98 keepCB->setEnabled(enable_keep);
100 keepCB->setToolTip(qt_("Insert the spacing even after a line break.\n"
101 "Note that a protected Half Quad will be turned into\n"
102 "a vertical space if used at the beginning of a paragraph!"));
104 keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
109 void GuiHSpace::patternChanged()
111 enableWidgets(spacingCO->currentIndex());
116 static void setWidgetsFromHSpace(InsetSpaceParams const & params,
121 QComboBox * fillPattern)
125 bool protect = false;
126 switch (params.kind) {
127 case InsetSpaceParams::NORMAL:
130 case InsetSpaceParams::PROTECTED:
134 case InsetSpaceParams::THIN:
137 case InsetSpaceParams::NEGTHIN:
140 case InsetSpaceParams::ENSKIP:
143 case InsetSpaceParams::ENSPACE:
147 case InsetSpaceParams::QUAD:
150 case InsetSpaceParams::QQUAD:
153 case InsetSpaceParams::HFILL:
156 case InsetSpaceParams::HFILL_PROTECTED:
160 case InsetSpaceParams::DOTFILL:
164 case InsetSpaceParams::HRULEFILL:
168 case InsetSpaceParams::LEFTARROWFILL:
172 case InsetSpaceParams::RIGHTARROWFILL:
176 case InsetSpaceParams::UPBRACEFILL:
180 case InsetSpaceParams::DOWNBRACEFILL:
184 case InsetSpaceParams::CUSTOM:
187 case InsetSpaceParams::CUSTOM_PROTECTED:
192 spacing->setCurrentIndex(item);
193 fillPattern->setCurrentIndex(pattern);
194 keep->setChecked(protect);
196 Length::UNIT default_unit =
197 (lyxrc.default_papersize > 3) ? Length::CM : Length::IN;
199 lengthToWidgets(value, unit, params.length, default_unit);
201 lengthToWidgets(value, unit, "", default_unit);
205 static InsetSpaceParams setHSpaceFromWidgets(int spacing,
206 QLineEdit * value, LengthCombo * unit, bool keep, int fill)
208 InsetSpaceParams params;
212 params.kind = InsetSpaceParams::PROTECTED;
214 params.kind = InsetSpaceParams::NORMAL;
217 params.kind = InsetSpaceParams::THIN;
220 params.kind = InsetSpaceParams::NEGTHIN;
224 params.kind = InsetSpaceParams::ENSPACE;
226 params.kind = InsetSpaceParams::ENSKIP;
229 params.kind = InsetSpaceParams::QUAD;
232 params.kind = InsetSpaceParams::QQUAD;
236 params.kind = InsetSpaceParams::DOTFILL;
238 params.kind = InsetSpaceParams::HRULEFILL;
240 params.kind = InsetSpaceParams::LEFTARROWFILL;
242 params.kind = InsetSpaceParams::RIGHTARROWFILL;
244 params.kind = InsetSpaceParams::UPBRACEFILL;
246 params.kind = InsetSpaceParams::DOWNBRACEFILL;
248 params.kind = InsetSpaceParams::HFILL_PROTECTED;
250 params.kind = InsetSpaceParams::HFILL;
254 params.kind = InsetSpaceParams::CUSTOM_PROTECTED;
256 params.kind = InsetSpaceParams::CUSTOM;
257 params.length = Length(widgetsToLength(value, unit));
264 void GuiHSpace::applyView()
266 params_ = setHSpaceFromWidgets(spacingCO->currentIndex(),
267 valueLE, unitCO, keepCB->isChecked(),
268 fillPatternCO->currentIndex());
272 void GuiHSpace::updateContents()
274 setWidgetsFromHSpace(params_, spacingCO, valueLE, unitCO, keepCB,
276 enableWidgets(spacingCO->currentIndex());
280 bool GuiHSpace::initialiseParams(string const & data)
282 InsetSpace::string2params(data, params_);
283 setButtonsValid(true);
288 void GuiHSpace::clearParams()
290 params_ = InsetSpaceParams();
294 void GuiHSpace::dispatchParams()
296 dispatch(FuncRequest(getLfun(), InsetSpace::params2string(params_)));
300 bool GuiHSpace::isValid()
302 return spacingCO->currentIndex() != 7 || !valueLE->text().isEmpty();
306 Dialog * createGuiHSpace(GuiView & lv) { return new GuiHSpace(lv); }
309 } // namespace frontend
313 #include "GuiHSpace_moc.cpp"