X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiWrap.cpp;h=e22be0898c2e97f599dc76aa8d8f332f3af41446;hb=b6eacd8d4f86734e8abef3335b190ce12a6a11b5;hp=ac761d55f8f9dfb3cb133fd093248bae27164c59;hpb=2c885f9a6d153b0f6578d5ae18821409ca405393;p=lyx.git diff --git a/src/frontends/qt4/GuiWrap.cpp b/src/frontends/qt4/GuiWrap.cpp index ac761d55f8..e22be0898c 100644 --- a/src/frontends/qt4/GuiWrap.cpp +++ b/src/frontends/qt4/GuiWrap.cpp @@ -3,7 +3,7 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author Jürgen Spitzmüller + * \author Jürgen Spitzmüller * * Full author contact details are available in file CREDITS. */ @@ -12,46 +12,41 @@ #include "GuiWrap.h" -#include "ControlWrap.h" #include "LengthCombo.h" #include "qt_helpers.h" #include "Validator.h" +#include "FuncRequest.h" -#include "insets/InsetWrap.h" - +#include "support/gettext.h" #include "support/lstrings.h" #include -#include #include -using std::string; - +using namespace std; namespace lyx { namespace frontend { -GuiWrapDialog::GuiWrapDialog(LyXView & lv) - : GuiDialog(lv, "wrap") +GuiWrap::GuiWrap(GuiView & lv) + : GuiDialog(lv, "wrap", qt_("Wrap Float Settings")) { setupUi(this); - setViewTitle(_("Wrap Float Settings")); - setController(new ControlWrap(*this)); - connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore())); - connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); + connect(buttonBox, SIGNAL(clicked(QAbstractButton *)), + this, SLOT(slotButtonBox(QAbstractButton *))); - connect(widthED, SIGNAL(textChanged(const QString &)), + connect(valignCO, SIGNAL(highlighted(QString)), this, SLOT(change_adaptor())); - connect(widthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)), + connect(floatCB, SIGNAL(stateChanged(int)), this, SLOT(change_adaptor())); - connect(valignCO, SIGNAL(highlighted(const QString &)), + connect(widthED, SIGNAL(textChanged(QString)), + this, SLOT(change_adaptor())); + connect(widthUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)), this, SLOT(change_adaptor())); connect(overhangCB, SIGNAL(stateChanged(int)), this, SLOT(change_adaptor())); - connect(overhangED, SIGNAL(textChanged(const QString &)), + connect(overhangED, SIGNAL(textChanged(QString)), this, SLOT(change_adaptor())); connect(overhangUnitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)), this, SLOT(change_adaptor())); @@ -60,25 +55,26 @@ GuiWrapDialog::GuiWrapDialog(LyXView & lv) 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().setOK(okPB); - bc().setApply(applyPB); - bc().setCancel(closePB); + bc().setOK(buttonBox->button(QDialogButtonBox::Ok)); + bc().setApply(buttonBox->button(QDialogButtonBox::Apply)); + bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel)); + bc().setRestore(buttonBox->button(QDialogButtonBox::Reset)); + bc().addReadOnly(valignCO); + bc().addReadOnly(floatCB); bc().addReadOnly(widthED); bc().addReadOnly(widthUnitLC); - bc().addReadOnly(valignCO); bc().addReadOnly(overhangCB); + bc().addReadOnly(overhangED); + bc().addReadOnly(overhangUnitLC); bc().addReadOnly(linesCB); + bc().addReadOnly(linesSB); // initialize the length validator bc().addCheckedLineEdit(widthED, widthLA); @@ -86,46 +82,13 @@ GuiWrapDialog::GuiWrapDialog(LyXView & lv) } -ControlWrap & GuiWrapDialog::controller() -{ - return static_cast(GuiDialog::controller()); -} - - -void GuiWrapDialog::closeEvent(QCloseEvent * e) -{ - slotClose(); - e->accept(); -} - - -void GuiWrapDialog::change_adaptor() +void GuiWrap::change_adaptor() { changed(); } -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() +void GuiWrap::applyView() { double const width_value = widthED->text().toDouble(); Length::UNIT widthUnit = widthUnitLC->currentLengthItem(); @@ -135,69 +98,119 @@ void GuiWrapDialog::applyView() Length::UNIT overhangUnit = overhangUnitLC->currentLengthItem(); if (overhangED->text().isEmpty()) overhangUnit = Length::UNIT_NONE; - - InsetWrapParams & params = controller().params(); - params.width = Length(width_value, widthUnit); + params_.width = Length(width_value, widthUnit); if (overhangCB->checkState() == Qt::Checked) - params.overhang = Length(overhang_value, overhangUnit); + 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"); + params_.overhang = Length("0in"); if (linesCB->checkState() == Qt::Checked) - params.lines = linesSB->value(); + params_.lines = linesSB->value(); else // when value is "0" the option is not set in the LaTeX-output // in InsetWrap.cpp - params.lines = 0; + params_.lines = 0; + bool floatOn = false; + if (floatCB->checkState() == Qt::Checked) + floatOn = true; switch (valignCO->currentIndex()) { case 0: - params.placement = "o"; + if (floatOn) + params_.placement = "O"; + else + params_.placement = "o"; break; case 1: - params.placement = "i"; + if (floatOn) + params_.placement = "I"; + else + params_.placement = "i"; break; case 2: - params.placement = "l"; + if (floatOn) + params_.placement = "L"; + else + params_.placement = "l"; break; case 3: - params.placement = "r"; + if (floatOn) + params_.placement = "R"; + else + params_.placement = "r"; break; } } -void GuiWrapDialog::updateContents() +void GuiWrap::paramsToDialog(InsetWrapParams const & params) { - InsetWrapParams & params = controller().params(); - - //0pt is a legal width now, it yields a - //wrapfloat just wide enough for the contents. - Length len_w(params.width); + // 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()); + if (len_o.value() == 0) + overhangCB->setCheckState(Qt::Unchecked); + else + overhangCB->setCheckState(Qt::Checked); + linesSB->setValue(params.lines); + if (params.lines == 0) + linesCB->setCheckState(Qt::Unchecked); + else + linesCB->setCheckState(Qt::Checked); int item = 0; - if (params.placement == "i") + if (params.placement == "i" || params.placement == "I") item = 1; - else if (params.placement == "l") + else if (params.placement == "l" || params.placement == "L") item = 2; - else if (params.placement == "r") + else if (params.placement == "r" || params.placement == "R") item = 3; valignCO->setCurrentIndex(item); + + if (params.placement == "O" || params.placement == "I" + || params.placement == "L" || params.placement == "R") + floatCB->setCheckState(Qt::Checked); +} + + +bool GuiWrap::initialiseParams(string const & sdata) +{ + InsetWrap::string2params(sdata, params_); + paramsToDialog(params_); + return true; } + +void GuiWrap::clearParams() +{ + params_ = InsetWrapParams(); +} + + +void GuiWrap::dispatchParams() +{ + string const lfun = InsetWrap::params2string(params_); + dispatch(FuncRequest(getLfun(), lfun)); +} + + +Dialog * createGuiWrap(GuiView & lv) { return new GuiWrap(lv); } + + } // namespace frontend } // namespace lyx -#include "GuiWrap_moc.cpp" +#include "moc_GuiWrap.cpp"