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 "ControlWrap.h"
16 #include "LengthCombo.h"
17 #include "qt_helpers.h"
18 #include "Validator.h"
20 #include "insets/InsetWrap.h"
22 #include "support/lstrings.h"
25 #include <QCloseEvent>
26 #include <QPushButton>
34 GuiWrapDialog::GuiWrapDialog(LyXView & lv)
35 : GuiDialog(lv, "wrap")
38 setViewTitle(_("Wrap Float Settings"));
39 setController(new ControlWrap(*this));
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(const QString &)),
47 this, SLOT(change_adaptor()));
48 connect(widthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
49 this, SLOT(change_adaptor()));
50 connect(valignCO, SIGNAL(highlighted(const QString &)),
51 this, SLOT(change_adaptor()));
52 connect(overhangCB, SIGNAL(stateChanged(int)),
53 this, SLOT(change_adaptor()));
54 connect(overhangED, SIGNAL(textChanged(const 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 ControlWrap & GuiWrapDialog::controller()
91 return static_cast<ControlWrap &>(GuiDialog::controller());
95 void GuiWrapDialog::closeEvent(QCloseEvent * e)
102 void GuiWrapDialog::change_adaptor()
108 void GuiWrapDialog::applyView()
110 double const width_value = widthED->text().toDouble();
111 Length::UNIT widthUnit = widthUnitLC->currentLengthItem();
112 if (widthED->text().isEmpty())
113 widthUnit = Length::UNIT_NONE;
114 double const overhang_value = overhangED->text().toDouble();
115 Length::UNIT overhangUnit = overhangUnitLC->currentLengthItem();
116 if (overhangED->text().isEmpty())
117 overhangUnit = Length::UNIT_NONE;
119 InsetWrapParams & params = controller().params();
121 params.width = Length(width_value, widthUnit);
123 if (overhangCB->checkState() == Qt::Checked)
124 params.overhang = Length(overhang_value, overhangUnit);
126 // when value is "0" the option is not set in the LaTeX-output
128 params.overhang = Length("0in");
130 if (linesCB->checkState() == Qt::Checked)
131 params.lines = linesSB->value();
133 // when value is "0" the option is not set in the LaTeX-output
137 switch (valignCO->currentIndex()) {
139 params.placement = "o";
142 params.placement = "i";
145 params.placement = "l";
148 params.placement = "r";
154 void GuiWrapDialog::updateContents()
156 InsetWrapParams & params = controller().params();
158 //0pt is a legal width now, it yields a
159 //wrapfloat just wide enough for the contents.
160 Length len_w(params.width);
161 widthED->setText(QString::number(len_w.value()));
162 widthUnitLC->setCurrentItem(len_w.unit());
164 Length len_o(params.overhang);
165 overhangED->setText(QString::number(len_o.value()));
166 overhangUnitLC->setCurrentItem(len_o.unit());
167 if (len_o.value() == 0)
168 overhangCB->setCheckState(Qt::Unchecked);
170 overhangCB->setCheckState(Qt::Checked);
172 linesSB->setValue(params.lines);
173 if (params.lines == 0)
174 linesCB->setCheckState(Qt::Unchecked);
176 linesCB->setCheckState(Qt::Checked);
179 if (params.placement == "i")
181 else if (params.placement == "l")
183 else if (params.placement == "r")
186 valignCO->setCurrentIndex(item);
189 } // namespace frontend
193 #include "GuiWrap_moc.cpp"