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/lstrings.h"
25 #include <QCloseEvent>
26 #include <QPushButton>
34 GuiWrap::GuiWrap(LyXView & lv)
35 : GuiDialog(lv, "wrap"), Controller(this)
38 setViewTitle(_("Wrap Float Settings"));
39 setController(this, false);
41 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
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(widthED, SIGNAL(textChanged(QString)),
47 this, SLOT(change_adaptor()));
48 connect(widthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
49 this, SLOT(change_adaptor()));
50 connect(valignCO, SIGNAL(highlighted(QString)),
51 this, SLOT(change_adaptor()));
52 connect(overhangCB, SIGNAL(stateChanged(int)),
53 this, SLOT(change_adaptor()));
54 connect(overhangED, SIGNAL(textChanged(QString)),
55 this, SLOT(change_adaptor()));
56 connect(overhangUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
57 this, SLOT(change_adaptor()));
58 connect(linesCB, SIGNAL(stateChanged(int)),
59 this, SLOT(change_adaptor()));
60 connect(linesSB, SIGNAL(valueChanged(int)),
61 this, SLOT(change_adaptor()));
63 widthED->setValidator(unsignedLengthValidator(widthED));
65 // overhang can be negative, but the unsignedLengthValidator allows this
66 overhangED->setValidator(unsignedLengthValidator(overhangED));
68 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
69 bc().setRestore(restorePB);
71 bc().setApply(applyPB);
72 bc().setCancel(closePB);
74 bc().addReadOnly(widthED);
75 bc().addReadOnly(widthUnitLC);
76 bc().addReadOnly(valignCO);
77 bc().addReadOnly(overhangCB);
78 bc().addReadOnly(overhangED);
79 bc().addReadOnly(overhangUnitLC);
80 bc().addReadOnly(linesCB);
81 bc().addReadOnly(linesSB);
83 // initialize the length validator
84 bc().addCheckedLineEdit(widthED, widthLA);
85 bc().addCheckedLineEdit(overhangED, overhangCB);
89 void GuiWrap::closeEvent(QCloseEvent * e)
96 void GuiWrap::change_adaptor()
102 void GuiWrap::applyView()
104 double const width_value = widthED->text().toDouble();
105 Length::UNIT widthUnit = widthUnitLC->currentLengthItem();
106 if (widthED->text().isEmpty())
107 widthUnit = Length::UNIT_NONE;
108 double const overhang_value = overhangED->text().toDouble();
109 Length::UNIT overhangUnit = overhangUnitLC->currentLengthItem();
110 if (overhangED->text().isEmpty())
111 overhangUnit = Length::UNIT_NONE;
113 params_.width = Length(width_value, widthUnit);
115 if (overhangCB->checkState() == Qt::Checked)
116 params_.overhang = Length(overhang_value, overhangUnit);
118 // when value is "0" the option is not set in the LaTeX-output
120 params_.overhang = Length("0in");
122 if (linesCB->checkState() == Qt::Checked)
123 params_.lines = linesSB->value();
125 // when value is "0" the option is not set in the LaTeX-output
129 switch (valignCO->currentIndex()) {
131 params_.placement = "o";
134 params_.placement = "i";
137 params_.placement = "l";
140 params_.placement = "r";
146 void GuiWrap::updateContents()
148 // 0pt is a legal width now, it yields a
149 // wrapfloat just wide enough for the contents.
150 Length len_w = params_.width;
151 widthED->setText(QString::number(len_w.value()));
152 widthUnitLC->setCurrentItem(len_w.unit());
154 Length len_o(params_.overhang);
155 overhangED->setText(QString::number(len_o.value()));
156 overhangUnitLC->setCurrentItem(len_o.unit());
157 if (len_o.value() == 0)
158 overhangCB->setCheckState(Qt::Unchecked);
160 overhangCB->setCheckState(Qt::Checked);
162 linesSB->setValue(params_.lines);
163 if (params_.lines == 0)
164 linesCB->setCheckState(Qt::Unchecked);
166 linesCB->setCheckState(Qt::Checked);
169 if (params_.placement == "i")
171 else if (params_.placement == "l")
173 else if (params_.placement == "r")
176 valignCO->setCurrentIndex(item);
180 bool GuiWrap::initialiseParams(string const & data)
182 InsetWrapMailer::string2params(data, params_);
187 void GuiWrap::clearParams()
189 params_ = InsetWrapParams();
193 void GuiWrap::dispatchParams()
195 string const lfun = InsetWrapMailer::params2string(params_);
196 dispatch(FuncRequest(getLfun(), lfun));
200 Dialog * createGuiWrap(LyXView & lv) { return new GuiWrap(lv); }
203 } // namespace frontend
207 #include "GuiWrap_moc.cpp"