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>
33 GuiWrap::GuiWrap(GuiView & lv)
34 : GuiDialog(lv, "wrap")
37 setViewTitle(_("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::closeEvent(QCloseEvent * e)
94 void GuiWrap::change_adaptor()
100 void GuiWrap::applyView()
102 double const width_value = widthED->text().toDouble();
103 Length::UNIT widthUnit = widthUnitLC->currentLengthItem();
104 if (widthED->text().isEmpty())
105 widthUnit = Length::UNIT_NONE;
106 double const overhang_value = overhangED->text().toDouble();
107 Length::UNIT overhangUnit = overhangUnitLC->currentLengthItem();
108 if (overhangED->text().isEmpty())
109 overhangUnit = Length::UNIT_NONE;
111 params_.width = Length(width_value, widthUnit);
113 if (overhangCB->checkState() == Qt::Checked)
114 params_.overhang = Length(overhang_value, overhangUnit);
116 // when value is "0" the option is not set in the LaTeX-output
118 params_.overhang = Length("0in");
120 if (linesCB->checkState() == Qt::Checked)
121 params_.lines = linesSB->value();
123 // when value is "0" the option is not set in the LaTeX-output
127 switch (valignCO->currentIndex()) {
129 params_.placement = "o";
132 params_.placement = "i";
135 params_.placement = "l";
138 params_.placement = "r";
144 void GuiWrap::updateContents()
146 // 0pt is a legal width now, it yields a
147 // wrapfloat just wide enough for the contents.
148 Length len_w = params_.width;
149 widthED->setText(QString::number(len_w.value()));
150 widthUnitLC->setCurrentItem(len_w.unit());
152 Length len_o(params_.overhang);
153 overhangED->setText(QString::number(len_o.value()));
154 overhangUnitLC->setCurrentItem(len_o.unit());
155 if (len_o.value() == 0)
156 overhangCB->setCheckState(Qt::Unchecked);
158 overhangCB->setCheckState(Qt::Checked);
160 linesSB->setValue(params_.lines);
161 if (params_.lines == 0)
162 linesCB->setCheckState(Qt::Unchecked);
164 linesCB->setCheckState(Qt::Checked);
167 if (params_.placement == "i")
169 else if (params_.placement == "l")
171 else if (params_.placement == "r")
174 valignCO->setCurrentIndex(item);
178 bool GuiWrap::initialiseParams(string const & data)
180 InsetWrapMailer::string2params(data, params_);
185 void GuiWrap::clearParams()
187 params_ = InsetWrapParams();
191 void GuiWrap::dispatchParams()
193 string const lfun = InsetWrapMailer::params2string(params_);
194 dispatch(FuncRequest(getLfun(), lfun));
198 Dialog * createGuiWrap(GuiView & lv) { return new GuiWrap(lv); }
201 } // namespace frontend
205 #include "GuiWrap_moc.cpp"