#include "ControlWrap.h"
#include "LengthCombo.h"
#include "qt_helpers.h"
+#include "Validator.h"
#include "insets/InsetWrap.h"
-#include "support/convert.h"
#include "support/lstrings.h"
#include <QLineEdit>
connect(widthED, SIGNAL(textChanged(const QString &)),
this, SLOT(change_adaptor()));
- connect(unitsLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+ connect(widthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
this, SLOT(change_adaptor()));
connect(valignCO, SIGNAL(highlighted(const QString &)),
this, SLOT(change_adaptor()));
+ connect(overhangCB, SIGNAL(stateChanged(int)),
+ this, SLOT(change_adaptor()));
+ connect(overhangED, SIGNAL(textChanged(const QString &)),
+ this, SLOT(change_adaptor()));
+ connect(overhangUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+ this, SLOT(change_adaptor()));
+ connect(linesCB, SIGNAL(stateChanged(int)),
+ this, SLOT(change_adaptor()));
+ connect(linesSB, SIGNAL(valueChanged(int)),
+ this, SLOT(change_adaptor()));
+
+ connect(overhangCB, SIGNAL(stateChanged(int)), this, SLOT(overhangChecked(int)));
+ connect(linesCB, SIGNAL(stateChanged(int)), this, SLOT(linesChecked(int)));
+
+ widthED->setValidator(unsignedLengthValidator(widthED));
+ // FIXME:
+ // overhang can be negative, but the unsignedLengthValidator allows this
+ overhangED->setValidator(unsignedLengthValidator(overhangED));
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
bc().setRestore(restorePB);
bc().setCancel(closePB);
bc().addReadOnly(widthED);
- bc().addReadOnly(unitsLC);
+ bc().addReadOnly(widthUnitLC);
bc().addReadOnly(valignCO);
+ bc().addReadOnly(overhangCB);
+ bc().addReadOnly(linesCB);
+
+ // initialize the length validator
+ bc().addCheckedLineEdit(widthED, widthLA);
+ bc().addCheckedLineEdit(overhangED, overhangCB);
}
-ControlWrap & GuiWrapDialog::controller() const
+ControlWrap & GuiWrapDialog::controller()
{
return static_cast<ControlWrap &>(GuiDialog::controller());
}
}
+void GuiWrapDialog::overhangChecked(int checkState)
+{
+ if (checkState == Qt::Checked) {
+ overhangED->setEnabled(true);
+ overhangUnitLC->setEnabled(true);
+ } else {
+ overhangED->setEnabled(false);
+ overhangUnitLC->setEnabled(false);
+ }
+}
+
+void GuiWrapDialog::linesChecked(int checkState)
+{
+ if (checkState == Qt::Checked)
+ linesSB->setEnabled(true);
+ else
+ linesSB->setEnabled(false);
+}
+
+
void GuiWrapDialog::applyView()
{
- double const value = widthED->text().toDouble();
- Length::UNIT unit = unitsLC->currentLengthItem();
+ double const width_value = widthED->text().toDouble();
+ Length::UNIT widthUnit = widthUnitLC->currentLengthItem();
if (widthED->text().isEmpty())
- unit = Length::UNIT_NONE;
-
+ widthUnit = Length::UNIT_NONE;
+ double const overhang_value = overhangED->text().toDouble();
+ Length::UNIT overhangUnit = overhangUnitLC->currentLengthItem();
+ if (overhangED->text().isEmpty())
+ overhangUnit = Length::UNIT_NONE;
+
InsetWrapParams & params = controller().params();
- params.width = Length(value, unit);
+ params.width = Length(width_value, widthUnit);
+
+ if (overhangCB->checkState() == Qt::Checked)
+ params.overhang = Length(overhang_value, overhangUnit);
+ else
+ // when value is "0" the option is not set in the LaTeX-output
+ // in InsetWrap.cpp
+ params.overhang = Length("0in");
+
+ if (linesCB->checkState() == Qt::Checked)
+ params.lines = linesSB->value();
+ else
+ // when value is "0" the option is not set in the LaTeX-output
+ // in InsetWrap.cpp
+ params.lines = 0;
switch (valignCO->currentIndex()) {
case 0:
}
-static string const numtostr(double val)
-{
- string a = convert<string>(val);
- return a;
- //0pt is a legal width now, it yields a
- //wrapfloat just wide enough for the contents.
-}
-
-
-void GuiWrapDialog::update_contents()
+void GuiWrapDialog::updateContents()
{
InsetWrapParams & params = controller().params();
- Length len(params.width);
- widthED->setText(toqstr(numtostr(len.value())));
- unitsLC->setCurrentItem(len.unit());
+ //0pt is a legal width now, it yields a
+ //wrapfloat just wide enough for the contents.
+ Length len_w(params.width);
+ widthED->setText(QString::number(len_w.value()));
+ widthUnitLC->setCurrentItem(len_w.unit());
+ Length len_o(params.overhang);
+ overhangED->setText(QString::number(len_o.value()));
+ overhangUnitLC->setCurrentItem(len_o.unit());
+ linesSB->setValue(params.lines);
int item = 0;
if (params.placement == "i")