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 "insets/InsetWrap.h"
22 #include "support/gettext.h"
23 #include "support/lstrings.h"
26 #include <QCloseEvent>
27 #include <QPushButton>
34 GuiWrap::GuiWrap(GuiView & lv)
35 : GuiDialog(lv, "wrap", qt_("Wrap Float Settings"))
39 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
40 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
41 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
42 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
44 connect(widthED, SIGNAL(textChanged(QString)),
45 this, SLOT(change_adaptor()));
46 connect(widthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
47 this, SLOT(change_adaptor()));
48 connect(valignCO, SIGNAL(highlighted(QString)),
49 this, SLOT(change_adaptor()));
50 connect(overhangCB, SIGNAL(stateChanged(int)),
51 this, SLOT(change_adaptor()));
52 connect(overhangED, SIGNAL(textChanged(QString)),
53 this, SLOT(change_adaptor()));
54 connect(overhangUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
55 this, SLOT(change_adaptor()));
56 connect(linesCB, SIGNAL(stateChanged(int)),
57 this, SLOT(change_adaptor()));
58 connect(linesSB, SIGNAL(valueChanged(int)),
59 this, SLOT(change_adaptor()));
61 widthED->setValidator(unsignedLengthValidator(widthED));
63 // overhang can be negative, but the unsignedLengthValidator allows this
64 overhangED->setValidator(unsignedLengthValidator(overhangED));
66 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
67 bc().setRestore(restorePB);
69 bc().setApply(applyPB);
70 bc().setCancel(closePB);
72 bc().addReadOnly(widthED);
73 bc().addReadOnly(widthUnitLC);
74 bc().addReadOnly(valignCO);
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 switch (valignCO->currentIndex()) {
122 params_.placement = "o";
125 params_.placement = "i";
128 params_.placement = "l";
131 params_.placement = "r";
137 void GuiWrap::updateContents()
139 // 0pt is a legal width now, it yields a
140 // wrapfloat just wide enough for the contents.
141 Length len_w = params_.width;
142 widthED->setText(QString::number(len_w.value()));
143 widthUnitLC->setCurrentItem(len_w.unit());
145 Length len_o(params_.overhang);
146 overhangED->setText(QString::number(len_o.value()));
147 overhangUnitLC->setCurrentItem(len_o.unit());
148 if (len_o.value() == 0)
149 overhangCB->setCheckState(Qt::Unchecked);
151 overhangCB->setCheckState(Qt::Checked);
153 linesSB->setValue(params_.lines);
154 if (params_.lines == 0)
155 linesCB->setCheckState(Qt::Unchecked);
157 linesCB->setCheckState(Qt::Checked);
160 if (params_.placement == "i")
162 else if (params_.placement == "l")
164 else if (params_.placement == "r")
167 valignCO->setCurrentIndex(item);
171 bool GuiWrap::initialiseParams(string const & data)
173 InsetWrapMailer::string2params(data, params_);
178 void GuiWrap::clearParams()
180 params_ = InsetWrapParams();
184 void GuiWrap::dispatchParams()
186 string const lfun = InsetWrapMailer::params2string(params_);
187 dispatch(FuncRequest(getLfun(), lfun));
191 Dialog * createGuiWrap(GuiView & lv) { return new GuiWrap(lv); }
194 } // namespace frontend
198 #include "GuiWrap_moc.cpp"