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 connect(overhangCB, SIGNAL(stateChanged(int)), this, SLOT(overhangChecked(int)));
64 connect(linesCB, SIGNAL(stateChanged(int)), this, SLOT(linesChecked(int)));
66 widthED->setValidator(unsignedLengthValidator(widthED));
68 // overhang can be negative, but the unsignedLengthValidator allows this
69 overhangED->setValidator(unsignedLengthValidator(overhangED));
71 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
72 bc().setRestore(restorePB);
74 bc().setApply(applyPB);
75 bc().setCancel(closePB);
77 bc().addReadOnly(widthED);
78 bc().addReadOnly(widthUnitLC);
79 bc().addReadOnly(valignCO);
80 bc().addReadOnly(overhangCB);
81 bc().addReadOnly(linesCB);
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::overhangChecked(int checkState)
110 if (checkState == Qt::Checked) {
111 overhangED->setEnabled(true);
112 overhangUnitLC->setEnabled(true);
114 overhangED->setEnabled(false);
115 overhangUnitLC->setEnabled(false);
119 void GuiWrapDialog::linesChecked(int checkState)
121 if (checkState == Qt::Checked)
122 linesSB->setEnabled(true);
124 linesSB->setEnabled(false);
128 void GuiWrapDialog::applyView()
130 double const width_value = widthED->text().toDouble();
131 Length::UNIT widthUnit = widthUnitLC->currentLengthItem();
132 if (widthED->text().isEmpty())
133 widthUnit = Length::UNIT_NONE;
134 double const overhang_value = overhangED->text().toDouble();
135 Length::UNIT overhangUnit = overhangUnitLC->currentLengthItem();
136 if (overhangED->text().isEmpty())
137 overhangUnit = Length::UNIT_NONE;
139 InsetWrapParams & params = controller().params();
141 params.width = Length(width_value, widthUnit);
143 if (overhangCB->checkState() == Qt::Checked)
144 params.overhang = Length(overhang_value, overhangUnit);
146 // when value is "0" the option is not set in the LaTeX-output
148 params.overhang = Length("0in");
150 if (linesCB->checkState() == Qt::Checked)
151 params.lines = linesSB->value();
153 // when value is "0" the option is not set in the LaTeX-output
157 switch (valignCO->currentIndex()) {
159 params.placement = "o";
162 params.placement = "i";
165 params.placement = "l";
168 params.placement = "r";
174 void GuiWrapDialog::updateContents()
176 InsetWrapParams & params = controller().params();
178 //0pt is a legal width now, it yields a
179 //wrapfloat just wide enough for the contents.
180 Length len_w(params.width);
181 widthED->setText(QString::number(len_w.value()));
182 widthUnitLC->setCurrentItem(len_w.unit());
183 Length len_o(params.overhang);
184 overhangED->setText(QString::number(len_o.value()));
185 overhangUnitLC->setCurrentItem(len_o.unit());
186 linesSB->setValue(params.lines);
189 if (params.placement == "i")
191 else if (params.placement == "l")
193 else if (params.placement == "r")
196 valignCO->setCurrentIndex(item);
199 } // namespace frontend
203 #include "GuiWrap_moc.cpp"