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(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
37 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
38 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
39 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
41 connect(valignCO, SIGNAL(highlighted(QString)),
42 this, SLOT(change_adaptor()));
43 connect(floatCB, SIGNAL(stateChanged(int)),
44 this, SLOT(change_adaptor()));
45 connect(widthED, SIGNAL(textChanged(QString)),
46 this, SLOT(change_adaptor()));
47 connect(widthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
48 this, SLOT(change_adaptor()));
49 connect(overhangCB, SIGNAL(stateChanged(int)),
50 this, SLOT(change_adaptor()));
51 connect(overhangED, SIGNAL(textChanged(QString)),
52 this, SLOT(change_adaptor()));
53 connect(overhangUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
54 this, SLOT(change_adaptor()));
55 connect(linesCB, SIGNAL(stateChanged(int)),
56 this, SLOT(change_adaptor()));
57 connect(linesSB, SIGNAL(valueChanged(int)),
58 this, SLOT(change_adaptor()));
60 widthED->setValidator(unsignedLengthValidator(widthED));
62 // overhang can be negative, but the unsignedLengthValidator allows this
63 overhangED->setValidator(unsignedLengthValidator(overhangED));
65 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
66 bc().setRestore(restorePB);
68 bc().setApply(applyPB);
69 bc().setCancel(closePB);
71 bc().addReadOnly(valignCO);
72 bc().addReadOnly(floatCB);
73 bc().addReadOnly(widthED);
74 bc().addReadOnly(widthUnitLC);
75 bc().addReadOnly(overhangCB);
76 bc().addReadOnly(overhangED);
77 bc().addReadOnly(overhangUnitLC);
78 bc().addReadOnly(linesCB);
79 bc().addReadOnly(linesSB);
81 // initialize the length validator
82 bc().addCheckedLineEdit(widthED, widthLA);
83 bc().addCheckedLineEdit(overhangED, overhangCB);
87 void GuiWrap::change_adaptor()
93 void GuiWrap::applyView()
95 double const width_value = widthED->text().toDouble();
96 Length::UNIT widthUnit = widthUnitLC->currentLengthItem();
97 if (widthED->text().isEmpty())
98 widthUnit = Length::UNIT_NONE;
99 double const overhang_value = overhangED->text().toDouble();
100 Length::UNIT overhangUnit = overhangUnitLC->currentLengthItem();
101 if (overhangED->text().isEmpty())
102 overhangUnit = Length::UNIT_NONE;
104 params_.width = Length(width_value, widthUnit);
106 if (overhangCB->checkState() == Qt::Checked)
107 params_.overhang = Length(overhang_value, overhangUnit);
109 // when value is "0" the option is not set in the LaTeX-output
111 params_.overhang = Length("0in");
113 if (linesCB->checkState() == Qt::Checked)
114 params_.lines = linesSB->value();
116 // when value is "0" the option is not set in the LaTeX-output
120 bool floatOn = false;
121 if (floatCB->checkState() == Qt::Checked)
123 switch (valignCO->currentIndex()) {
126 params_.placement = "O";
128 params_.placement = "o";
132 params_.placement = "I";
134 params_.placement = "i";
138 params_.placement = "L";
140 params_.placement = "l";
144 params_.placement = "R";
146 params_.placement = "r";
152 void GuiWrap::paramsToDialog(InsetWrapParams const & params)
154 // 0pt is a legal width now, it yields a
155 // wrapfloat just wide enough for the contents.
156 Length len_w = params.width;
157 widthED->setText(QString::number(len_w.value()));
158 widthUnitLC->setCurrentItem(len_w.unit());
160 Length len_o(params.overhang);
161 overhangED->setText(QString::number(len_o.value()));
162 overhangUnitLC->setCurrentItem(len_o.unit());
163 if (len_o.value() == 0)
164 overhangCB->setCheckState(Qt::Unchecked);
166 overhangCB->setCheckState(Qt::Checked);
168 linesSB->setValue(params.lines);
169 if (params.lines == 0)
170 linesCB->setCheckState(Qt::Unchecked);
172 linesCB->setCheckState(Qt::Checked);
175 if (params.placement == "i" || params.placement == "I")
177 else if (params.placement == "l" || params.placement == "L")
179 else if (params.placement == "r" || params.placement == "R")
182 valignCO->setCurrentIndex(item);
184 if (params.placement == "O" || params.placement == "I"
185 || params.placement == "L" || params.placement == "R")
186 floatCB->setCheckState(Qt::Checked);
190 bool GuiWrap::initialiseParams(string const & data)
192 InsetWrap::string2params(data, params_);
193 paramsToDialog(params_);
198 void GuiWrap::clearParams()
200 params_ = InsetWrapParams();
204 void GuiWrap::dispatchParams()
206 string const lfun = InsetWrap::params2string(params_);
207 dispatch(FuncRequest(getLfun(), lfun));
211 Dialog * createGuiWrap(GuiView & lv) { return new GuiWrap(lv); }
214 } // namespace frontend
218 #include "moc_GuiWrap.cpp"