]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiWrap.cpp
GuiWrap.cpp: disconnect the widgets that are by default disabled from readonly
[lyx.git] / src / frontends / qt4 / GuiWrap.cpp
index 88a85a25072c6b246f278f00f09eb110c9cfb155..ac761d55f8f9dfb3cb133fd093248bae27164c59 100644 (file)
 #include <config.h>
 
 #include "GuiWrap.h"
-#include "Qt2BC.h"
 
+#include "ControlWrap.h"
 #include "LengthCombo.h"
 #include "qt_helpers.h"
-
-#include "controllers/ControlWrap.h"
+#include "Validator.h"
 
 #include "insets/InsetWrap.h"
 
-#include "support/convert.h"
 #include "support/lstrings.h"
 
 #include <QLineEdit>
 #include <QCloseEvent>
 #include <QPushButton>
 
-
 using std::string;
 
+
 namespace lyx {
 namespace frontend {
 
-/////////////////////////////////////////////////////////////////////
-//
-// GuiWrapDialog
-//
-/////////////////////////////////////////////////////////////////////
-
-
-GuiWrapDialog::GuiWrapDialog(GuiWrap * form)
-       : form_(form)
+GuiWrapDialog::GuiWrapDialog(LyXView & lv)
+       : GuiDialog(lv, "wrap")
 {
        setupUi(this);
+       setViewTitle(_("Wrap Float Settings"));
+       setController(new ControlWrap(*this));
 
-       connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
-       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+       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(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().setOK(okPB);
+       bc().setApply(applyPB);
+       bc().setCancel(closePB);
+
+       bc().addReadOnly(widthED);
+       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()
+{
+       return static_cast<ControlWrap &>(GuiDialog::controller());
 }
 
 
 void GuiWrapDialog::closeEvent(QCloseEvent * e)
 {
-       form_->slotWMHide();
+       slotClose();
        e->accept();
 }
 
 
 void GuiWrapDialog::change_adaptor()
 {
-       form_->changed();
+       changed();
 }
 
-/////////////////////////////////////////////////////////////////////
-//
-// GuiWrap
-//
-/////////////////////////////////////////////////////////////////////
 
-typedef QController<ControlWrap, GuiView<GuiWrapDialog> > wrap_base_class;
-
-GuiWrap::GuiWrap(Dialog & parent)
-       : wrap_base_class(parent, _("Text Wrap Settings"))
+void GuiWrapDialog::overhangChecked(int checkState)
 {
+       if (checkState == Qt::Checked) {
+               overhangED->setEnabled(true);
+               overhangUnitLC->setEnabled(true);
+       } else { 
+               overhangED->setEnabled(false);
+               overhangUnitLC->setEnabled(false);
+       }
 }
 
-
-void GuiWrap::build_dialog()
+void GuiWrapDialog::linesChecked(int checkState)
 {
-       dialog_.reset(new GuiWrapDialog(this));
-
-       bcview().setRestore(dialog_->restorePB);
-       bcview().setOK(dialog_->okPB);
-       bcview().setApply(dialog_->applyPB);
-       bcview().setCancel(dialog_->closePB);
-
-       bcview().addReadOnly(dialog_->widthED);
-       bcview().addReadOnly(dialog_->unitsLC);
-       bcview().addReadOnly(dialog_->valignCO);
+       if (checkState == Qt::Checked)
+               linesSB->setEnabled(true);
+       else 
+               linesSB->setEnabled(false);
 }
 
 
-void GuiWrap::apply()
+void GuiWrapDialog::applyView()
 {
-       double const value = convert<double>(fromqstr(dialog_->widthED->text()));
-       Length::UNIT unit = dialog_->unitsLC->currentLengthItem();
-       if (dialog_->widthED->text().isEmpty())
-               unit = Length::UNIT_NONE;
-
+       double const width_value = widthED->text().toDouble();
+       Length::UNIT widthUnit = widthUnitLC->currentLengthItem();
+       if (widthED->text().isEmpty())
+               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);
 
-       switch (dialog_->valignCO->currentIndex()) {
+       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:
-               params.placement.erase();
+               params.placement = "o";
                break;
        case 1:
-               params.placement = "l";
+               params.placement = "i";
                break;
        case 2:
-               params.placement = "r";
+               params.placement = "l";
                break;
        case 3:
-               params.placement = "p";
+               params.placement = "r";
                break;
        }
 }
 
 
-static string const numtostr(double val)
-{
-       string a = convert<string>(val);
-       // FIXME: Will this test ever trigger? (Lgb)
-       if (a == "0")
-               a.erase();
-       return a;
-}
-
-
-void GuiWrap::update_contents()
+void GuiWrapDialog::updateContents()
 {
        InsetWrapParams & params = controller().params();
 
-       Length len(params.width);
-       dialog_->widthED->setText(toqstr(numtostr(len.value())));
-       dialog_->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 == "l")
+       if (params.placement == "i")
                item = 1;
-       else if (params.placement == "r")
+       else if (params.placement == "l")
                item = 2;
-       else if (params.placement == "p")
+       else if (params.placement == "r")
                item = 3;
 
-       dialog_->valignCO->setCurrentIndex(item);
+       valignCO->setCurrentIndex(item);
 }
 
 } // namespace frontend