* 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 "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(QWidget * parent) : InsetParamsWidget(parent)
{
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 &)),
- this, SLOT(change_adaptor()));
- connect(valueLE, SIGNAL(textChanged(const QString &)),
- this, SLOT(change_adaptor()));
- connect(spacingCO, SIGNAL(activated(int)),
- this, SLOT(enableCustom(int)));
+ connect(valueLE, SIGNAL(textChanged(QString)),
+ this, SIGNAL(changed()));
connect(keepCB, SIGNAL(clicked()),
- this, SLOT(change_adaptor()));
+ this, SIGNAL(changed()));
connect(unitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
- this, SLOT(change_adaptor()));
+ this, SIGNAL(changed()));
- valueLE->setValidator(unsignedLengthValidator(valueLE));
-
- // Manage the ok, apply, restore and cancel/close buttons
- bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
- bc().setOK(okPB);
- bc().setApply(applyPB);
- bc().setCancel(closePB);
+ connect(spacingCO, SIGNAL(activated(int)),
+ this, SLOT(enableCustom(int)));
- // disable for read-only documents
- bc().addReadOnly(spacingCO);
- bc().addReadOnly(valueLE);
- bc().addReadOnly(unitCO);
- bc().addReadOnly(keepCB);
+ // Set up a signed glue length validator
+ LengthValidator * v = new LengthValidator(valueLE);
+ v->setBottom(GlueLength());
+ valueLE->setValidator(v);
// initialize the length validator
- bc().addCheckedLineEdit(valueLE, valueL);
-
- // remove the %-items from the unit choice
- unitCO->noPercents();
+ addCheckedWidget(valueLE, valueL);
+ enableCustom(spacingCO->currentIndex());
}
-ControlVSpace & GuiVSpaceDialog::controller() const
-{
- return static_cast<ControlVSpace &>(Dialog::controller());
-}
-
-
-void GuiVSpaceDialog::closeEvent(QCloseEvent * e)
-{
- slotWMHide();
- e->accept();
-}
-
-
-void GuiVSpaceDialog::change_adaptor()
-{
- changed();
-}
-
-
-void GuiVSpaceDialog::enableCustom(int selection)
+void GuiVSpace::enableCustom(int selection)
{
bool const enable = selection == 5;
valueLE->setEnabled(enable);
+ if (enable)
+ valueLE->setFocus();
+ valueL->setEnabled(enable);
unitCO->setEnabled(enable);
+ changed();
}
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);
}
-void GuiVSpaceDialog::applyView()
+docstring GuiVSpace::dialogToParams() const
{
// 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;
+ return docstring();
+
+ VSpace const params = setVSpaceFromWidgets(spacingCO->currentIndex(),
+ valueLE, unitCO, keepCB->isChecked());
+ return from_ascii(InsetVSpace::params2string(params));
+}
- VSpace const space = setVSpaceFromWidgets(spacingCO->currentIndex(),
- valueLE, unitCO, keepCB->isChecked());
- controller().params() = space;
+void GuiVSpace::paramsToDialog(Inset const * inset)
+{
+ InsetVSpace const * vs = static_cast<InsetVSpace const *>(inset);
+ VSpace const & params = vs->space();
+ setWidgetsFromVSpace(params, spacingCO, valueLE, unitCO, keepCB);
+ enableCustom(spacingCO->currentIndex());
}
-void GuiVSpaceDialog::update_contents()
+bool GuiVSpace::checkWidgets(bool readonly) const
{
- setWidgetsFromVSpace(controller().params(),
- spacingCO, valueLE, unitCO, keepCB);
+ valueLE->setReadOnly(readonly);
+ keepCB->setEnabled(!readonly);
+
+ if (readonly) {
+ spacingCO->setEnabled(false);
+ unitCO->setEnabled(false);
+ } else {
+ bool const enable = (spacingCO->currentIndex() == 5);
+ valueLE->setEnabled(enable);
+ valueL->setEnabled(enable);
+ unitCO->setEnabled(enable);
+ }
+
+ return InsetParamsWidget::checkWidgets();
}
} // namespace frontend
} // namespace lyx
-#include "GuiVSpace_moc.cpp"
+#include "moc_GuiVSpace.cpp"