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"
22 #include "insets/InsetSpace.h"
24 #include "support/gettext.h"
25 #include "support/lstrings.h"
29 #include <QPushButton>
37 GuiHSpace::GuiHSpace(GuiView & lv)
38 : GuiDialog(lv, "space", qt_("Horizontal Space Settings"))
42 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
43 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
44 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
46 connect(spacingCO, SIGNAL(highlighted(QString)),
47 this, SLOT(change_adaptor()));
48 connect(valueLE, SIGNAL(textChanged(QString)),
49 this, SLOT(change_adaptor()));
50 connect(spacingCO, SIGNAL(activated(int)),
51 this, SLOT(enableWidgets(int)));
52 connect(keepCB, SIGNAL(clicked()),
53 this, SLOT(change_adaptor()));
54 connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
55 this, SLOT(change_adaptor()));
56 connect(fillPatternCO, SIGNAL(activated(int)),
57 this, SLOT(patternChanged()));
59 valueLE->setValidator(unsignedLengthValidator(valueLE));
61 // Manage the ok, apply, restore and cancel/close buttons
62 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
64 bc().setApply(applyPB);
65 bc().setCancel(closePB);
67 // disable for read-only documents
68 bc().addReadOnly(spacingCO);
69 bc().addReadOnly(valueLE);
70 bc().addReadOnly(unitCO);
71 bc().addReadOnly(keepCB);
72 bc().addReadOnly(fillPatternCO);
74 // initialize the length validator
75 bc().addCheckedLineEdit(valueLE, valueL);
77 // remove the %-items from the unit choice
82 void GuiHSpace::change_adaptor()
88 void GuiHSpace::enableWidgets(int selection)
90 valueLE->setEnabled(selection == 7);
91 unitCO->setEnabled(selection == 7);
92 fillPatternCO->setEnabled(selection == 6);
93 int pattern = fillPatternCO->currentIndex();
94 bool const enable_keep =
95 selection == 0 || selection == 3 ||
96 (selection == 6 && pattern == 0) || selection == 7;
97 keepCB->setEnabled(enable_keep);
102 void GuiHSpace::patternChanged()
104 enableWidgets(spacingCO->currentIndex());
109 static void setWidgetsFromHSpace(InsetSpaceParams const & params,
114 QComboBox * fillPattern)
118 bool protect = false;
119 switch (params.kind) {
120 case InsetSpaceParams::NORMAL:
123 case InsetSpaceParams::PROTECTED:
127 case InsetSpaceParams::THIN:
130 case InsetSpaceParams::NEGTHIN:
133 case InsetSpaceParams::ENSKIP:
136 case InsetSpaceParams::ENSPACE:
140 case InsetSpaceParams::QUAD:
143 case InsetSpaceParams::QQUAD:
146 case InsetSpaceParams::HFILL:
149 case InsetSpaceParams::HFILL_PROTECTED:
153 case InsetSpaceParams::DOTFILL:
157 case InsetSpaceParams::HRULEFILL:
161 case InsetSpaceParams::CUSTOM:
164 case InsetSpaceParams::CUSTOM_PROTECTED:
169 spacing->setCurrentIndex(item);
170 fillPattern->setCurrentIndex(pattern);
171 keep->setChecked(protect);
173 Length::UNIT default_unit =
174 (lyxrc.default_papersize > 3) ? Length::CM : Length::IN;
176 lengthToWidgets(value, unit, params.length, default_unit);
178 lengthToWidgets(value, unit, "", default_unit);
182 static InsetSpaceParams setHSpaceFromWidgets(int spacing,
183 QLineEdit * value, LengthCombo * unit, bool keep, int fill)
185 InsetSpaceParams params;
189 params.kind = InsetSpaceParams::PROTECTED;
191 params.kind = InsetSpaceParams::NORMAL;
194 params.kind = InsetSpaceParams::THIN;
197 params.kind = InsetSpaceParams::NEGTHIN;
201 params.kind = InsetSpaceParams::ENSPACE;
203 params.kind = InsetSpaceParams::ENSKIP;
206 params.kind = InsetSpaceParams::QUAD;
209 params.kind = InsetSpaceParams::QQUAD;
213 params.kind = InsetSpaceParams::DOTFILL;
215 params.kind = InsetSpaceParams::HRULEFILL;
217 params.kind = InsetSpaceParams::HFILL_PROTECTED;
219 params.kind = InsetSpaceParams::HFILL;
223 params.kind = InsetSpaceParams::CUSTOM_PROTECTED;
225 params.kind = InsetSpaceParams::CUSTOM;
226 params.length = Length(widgetsToLength(value, unit));
233 void GuiHSpace::applyView()
235 params_ = setHSpaceFromWidgets(spacingCO->currentIndex(),
236 valueLE, unitCO, keepCB->isChecked(),
237 fillPatternCO->currentIndex());
241 void GuiHSpace::updateContents()
243 setWidgetsFromHSpace(params_, spacingCO, valueLE, unitCO, keepCB,
245 enableWidgets(spacingCO->currentIndex());
249 bool GuiHSpace::initialiseParams(string const & data)
251 InsetSpaceMailer::string2params(data, params_);
252 setButtonsValid(true);
258 void GuiHSpace::clearParams()
260 params_ = InsetSpaceParams();
264 void GuiHSpace::dispatchParams()
266 dispatch(FuncRequest(getLfun(), InsetSpaceMailer::params2string(params_)));
270 bool GuiHSpace::isValid()
272 return (spacingCO->currentIndex() != 7 || !valueLE->text().isEmpty());
276 Dialog * createGuiHSpace(GuiView & lv) { return new GuiHSpace(lv); }
279 } // namespace frontend
283 #include "GuiHSpace_moc.cpp"