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::CUSTOM:
171 case InsetSpaceParams::CUSTOM_PROTECTED:
176 spacing->setCurrentIndex(item);
177 fillPattern->setCurrentIndex(pattern);
178 keep->setChecked(protect);
180 Length::UNIT default_unit =
181 (lyxrc.default_papersize > 3) ? Length::CM : Length::IN;
183 lengthToWidgets(value, unit, params.length, default_unit);
185 lengthToWidgets(value, unit, "", default_unit);
189 static InsetSpaceParams setHSpaceFromWidgets(int spacing,
190 QLineEdit * value, LengthCombo * unit, bool keep, int fill)
192 InsetSpaceParams params;
196 params.kind = InsetSpaceParams::PROTECTED;
198 params.kind = InsetSpaceParams::NORMAL;
201 params.kind = InsetSpaceParams::THIN;
204 params.kind = InsetSpaceParams::NEGTHIN;
208 params.kind = InsetSpaceParams::ENSPACE;
210 params.kind = InsetSpaceParams::ENSKIP;
213 params.kind = InsetSpaceParams::QUAD;
216 params.kind = InsetSpaceParams::QQUAD;
220 params.kind = InsetSpaceParams::DOTFILL;
222 params.kind = InsetSpaceParams::HRULEFILL;
224 params.kind = InsetSpaceParams::HFILL_PROTECTED;
226 params.kind = InsetSpaceParams::HFILL;
230 params.kind = InsetSpaceParams::CUSTOM_PROTECTED;
232 params.kind = InsetSpaceParams::CUSTOM;
233 params.length = Length(widgetsToLength(value, unit));
240 void GuiHSpace::applyView()
242 params_ = setHSpaceFromWidgets(spacingCO->currentIndex(),
243 valueLE, unitCO, keepCB->isChecked(),
244 fillPatternCO->currentIndex());
248 void GuiHSpace::updateContents()
250 setWidgetsFromHSpace(params_, spacingCO, valueLE, unitCO, keepCB,
252 enableWidgets(spacingCO->currentIndex());
256 bool GuiHSpace::initialiseParams(string const & data)
258 InsetSpace::string2params(data, params_);
259 setButtonsValid(true);
264 void GuiHSpace::clearParams()
266 params_ = InsetSpaceParams();
270 void GuiHSpace::dispatchParams()
272 dispatch(FuncRequest(getLfun(), InsetSpace::params2string(params_)));
276 bool GuiHSpace::isValid()
278 return spacingCO->currentIndex() != 7 || !valueLE->text().isEmpty();
282 Dialog * createGuiHSpace(GuiView & lv) { return new GuiHSpace(lv); }
285 } // namespace frontend
289 #include "GuiHSpace_moc.cpp"