]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiVSpace.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiVSpace.cpp
index e3332c95a82d2004d5807c011220a4498aadec66..70d2ba7e6e4f7ffc642969da6645207bf8024ccf 100644 (file)
@@ -3,12 +3,12 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author André Pönitz
- * \author Jürgen Vigna
+ * \author André Pönitz
+ * \author Jürgen Vigna
  * \author Rob Lahaye
  * \author Angus Leeming
  * \author Edwin Leuven
- * \author Jürgen Spitzmüller
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include "GuiVSpace.h"
 
-#include "ControlVSpace.h"
 #include "LengthCombo.h"
 #include "qt_helpers.h"
 #include "Validator.h"
 
-#include "LyXRC.h" // to set the default length values
 #include "Spacing.h"
-#include "VSpace.h"
+#include "FuncRequest.h"
 
-#include "ControlVSpace.h"
-#include "frontend_helpers.h"
+#include "insets/InsetVSpace.h"
 
+#include "support/gettext.h"
 #include "support/lstrings.h"
 
 #include <QCheckBox>
-#include <QCloseEvent>
 #include <QLineEdit>
 #include <QPushButton>
 #include <QValidator>
 
-using std::string;
-
+using namespace std;
 
 namespace lyx {
 namespace frontend {
 
-GuiVSpaceDialog::GuiVSpaceDialog(LyXView & lv)
-       : GuiDialog(lv, "vspace")
+GuiVSpace::GuiVSpace(GuiView & lv)
+       : GuiDialog(lv, "vspace", qt_("Vertical Space Settings"))
 {
        setupUi(this);
-       setViewTitle(_("Vertical Space Settings"));
-       setController(new ControlVSpace(*this));
 
        connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
        connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
        connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
 
-       connect(spacingCO, SIGNAL(highlighted(const QString &)),
+       connect(spacingCO, SIGNAL(highlighted(QString)),
                this, SLOT(change_adaptor()));
-       connect(valueLE, SIGNAL(textChanged(const QString &)),
+       connect(valueLE, SIGNAL(textChanged(QString)),
                this, SLOT(change_adaptor()));
        connect(spacingCO, SIGNAL(activated(int)),
                this, SLOT(enableCustom(int)));
@@ -65,7 +59,7 @@ GuiVSpaceDialog::GuiVSpaceDialog(LyXView & lv)
        connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
                this, SLOT(change_adaptor()));
 
-       valueLE->setValidator(unsignedLengthValidator(valueLE));
+       valueLE->setValidator(unsignedGlueLengthValidator(valueLE));
 
        // Manage the ok, apply, restore and cancel/close buttons
        bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
@@ -81,32 +75,16 @@ GuiVSpaceDialog::GuiVSpaceDialog(LyXView & lv)
 
        // initialize the length validator
        bc().addCheckedLineEdit(valueLE, valueL);
-
-       // remove the %-items from the unit choice
-       unitCO->noPercents();
-}
-
-
-ControlVSpace & GuiVSpaceDialog::controller()
-{
-       return static_cast<ControlVSpace &>(GuiDialog::controller());
 }
 
 
-void GuiVSpaceDialog::closeEvent(QCloseEvent * e)
-{
-       slotClose();
-       e->accept();
-}
-
-
-void GuiVSpaceDialog::change_adaptor()
+void GuiVSpace::change_adaptor()
 {
        changed();
 }
 
 
-void GuiVSpaceDialog::enableCustom(int selection)
+void GuiVSpace::enableCustom(int selection)
 {
        bool const enable = selection == 5;
        valueLE->setEnabled(enable);
@@ -132,8 +110,7 @@ static void setWidgetsFromVSpace(VSpace const & space,
        spacing->setCurrentIndex(item);
        keep->setChecked(space.keep());
 
-       Length::UNIT default_unit =
-                       (lyxrc.default_papersize > 3) ? Length::CM : Length::IN;
+       Length::UNIT const default_unit = Length::defaultUnit();
        bool const custom_vspace = space.kind() == VSpace::LENGTH;
        if (custom_vspace) {
                value->setEnabled(true);
@@ -167,28 +144,49 @@ static VSpace setVSpaceFromWidgets(int spacing,
 }
 
 
-void GuiVSpaceDialog::applyView()
+void GuiVSpace::applyView()
 {
        // If a vspace choice is "Length" but there's no text in
        // the input field, do not insert a vspace at all.
        if (spacingCO->currentIndex() == 5 && valueLE->text().isEmpty())
                return;
 
-       VSpace const space = setVSpaceFromWidgets(spacingCO->currentIndex(),
+       params_ = setVSpaceFromWidgets(spacingCO->currentIndex(),
                        valueLE, unitCO, keepCB->isChecked()); 
+}
+
 
-       controller().params() = space;
+void GuiVSpace::updateContents()
+{
+       setWidgetsFromVSpace(params_, spacingCO, valueLE, unitCO, keepCB);
+}
+
+
+bool GuiVSpace::initialiseParams(string const & data)
+{
+       InsetVSpace::string2params(data, params_);
+       setButtonsValid(true);
+       return true;
+}
+
+
+void GuiVSpace::clearParams()
+{
+       params_ = VSpace();
 }
 
 
-void GuiVSpaceDialog::updateContents()
+void GuiVSpace::dispatchParams()
 {
-       setWidgetsFromVSpace(controller().params(),
-               spacingCO, valueLE, unitCO, keepCB);
+       dispatch(FuncRequest(getLfun(), InsetVSpace::params2string(params_)));
 }
 
+
+Dialog * createGuiVSpace(GuiView & lv) { return new GuiVSpace(lv); }
+
+
 } // namespace frontend
 } // namespace lyx
 
 
-#include "GuiVSpace_moc.cpp"
+#include "moc_GuiVSpace.cpp"