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.
15 #include "LengthCombo.h"
16 #include "qt_helpers.h"
17 #include "Validator.h"
18 #include "FuncRequest.h"
20 #include "support/gettext.h"
21 #include "support/lstrings.h"
24 #include <QPushButton>
31 GuiWrap::GuiWrap(GuiView & lv)
32 : GuiDialog(lv, "wrap", qt_("Wrap Float Settings"))
36 connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
37 this, SLOT(slotButtonBox(QAbstractButton *)));
39 connect(valignCO, SIGNAL(highlighted(QString)),
40 this, SLOT(change_adaptor()));
41 connect(floatCB, SIGNAL(stateChanged(int)),
42 this, SLOT(change_adaptor()));
43 connect(widthED, SIGNAL(textChanged(QString)),
44 this, SLOT(change_adaptor()));
45 connect(widthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
46 this, SLOT(change_adaptor()));
47 connect(overhangCB, SIGNAL(stateChanged(int)),
48 this, SLOT(change_adaptor()));
49 connect(overhangED, SIGNAL(textChanged(QString)),
50 this, SLOT(change_adaptor()));
51 connect(overhangUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
52 this, SLOT(change_adaptor()));
53 connect(linesCB, SIGNAL(stateChanged(int)),
54 this, SLOT(change_adaptor()));
55 connect(linesSB, SIGNAL(valueChanged(int)),
56 this, SLOT(change_adaptor()));
58 widthED->setValidator(unsignedLengthValidator(widthED));
60 // overhang can be negative, but the unsignedLengthValidator allows this
61 overhangED->setValidator(unsignedLengthValidator(overhangED));
63 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
64 bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
65 bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
66 bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
67 bc().setRestore(buttonBox->button(QDialogButtonBox::Reset));
69 bc().addReadOnly(valignCO);
70 bc().addReadOnly(floatCB);
71 bc().addReadOnly(widthED);
72 bc().addReadOnly(widthUnitLC);
73 bc().addReadOnly(overhangCB);
74 bc().addReadOnly(overhangED);
75 bc().addReadOnly(overhangUnitLC);
76 bc().addReadOnly(linesCB);
77 bc().addReadOnly(linesSB);
79 // initialize the length validator
80 bc().addCheckedLineEdit(widthED, widthLA);
81 bc().addCheckedLineEdit(overhangED, overhangCB);
85 void GuiWrap::change_adaptor()
91 void GuiWrap::applyView()
93 double const width_value = widthED->text().toDouble();
94 Length::UNIT widthUnit = widthUnitLC->currentLengthItem();
95 if (widthED->text().isEmpty())
96 widthUnit = Length::UNIT_NONE;
97 double const overhang_value = overhangED->text().toDouble();
98 Length::UNIT overhangUnit = overhangUnitLC->currentLengthItem();
99 if (overhangED->text().isEmpty())
100 overhangUnit = Length::UNIT_NONE;
102 params_.width = Length(width_value, widthUnit);
104 if (overhangCB->checkState() == Qt::Checked)
105 params_.overhang = Length(overhang_value, overhangUnit);
107 // when value is "0" the option is not set in the LaTeX-output
109 params_.overhang = Length("0in");
111 if (linesCB->checkState() == Qt::Checked)
112 params_.lines = linesSB->value();
114 // when value is "0" the option is not set in the LaTeX-output
118 bool floatOn = false;
119 if (floatCB->checkState() == Qt::Checked)
121 switch (valignCO->currentIndex()) {
124 params_.placement = "O";
126 params_.placement = "o";
130 params_.placement = "I";
132 params_.placement = "i";
136 params_.placement = "L";
138 params_.placement = "l";
142 params_.placement = "R";
144 params_.placement = "r";
150 void GuiWrap::paramsToDialog(InsetWrapParams const & params)
152 // 0pt is a legal width now, it yields a
153 // wrapfloat just wide enough for the contents.
154 Length len_w = params.width;
155 widthED->setText(QString::number(len_w.value()));
156 widthUnitLC->setCurrentItem(len_w.unit());
158 Length len_o(params.overhang);
159 overhangED->setText(QString::number(len_o.value()));
160 overhangUnitLC->setCurrentItem(len_o.unit());
161 if (len_o.value() == 0)
162 overhangCB->setCheckState(Qt::Unchecked);
164 overhangCB->setCheckState(Qt::Checked);
166 linesSB->setValue(params.lines);
167 if (params.lines == 0)
168 linesCB->setCheckState(Qt::Unchecked);
170 linesCB->setCheckState(Qt::Checked);
173 if (params.placement == "i" || params.placement == "I")
175 else if (params.placement == "l" || params.placement == "L")
177 else if (params.placement == "r" || params.placement == "R")
180 valignCO->setCurrentIndex(item);
182 if (params.placement == "O" || params.placement == "I"
183 || params.placement == "L" || params.placement == "R")
184 floatCB->setCheckState(Qt::Checked);
188 bool GuiWrap::initialiseParams(string const & sdata)
190 InsetWrap::string2params(sdata, params_);
191 paramsToDialog(params_);
196 void GuiWrap::clearParams()
198 params_ = InsetWrapParams();
202 void GuiWrap::dispatchParams()
204 string const lfun = InsetWrap::params2string(params_);
205 dispatch(FuncRequest(getLfun(), lfun));
209 Dialog * createGuiWrap(GuiView & lv) { return new GuiWrap(lv); }
212 } // namespace frontend
216 #include "moc_GuiWrap.cpp"