From 4c63bdbff0c4ac57b28c5873aa0ff24865701ce6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Mon, 22 Nov 2004 12:22:19 +0000 Subject: [PATCH] glue length validator for qt git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9286 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 8 ++++++++ src/frontends/qt2/QVSpace.C | 4 ++++ src/frontends/qt2/QVSpaceDialog.C | 18 +++++++++++++++++- src/frontends/qt2/lengthcombo.C | 2 +- src/frontends/qt2/lengthvalidator.C | 20 +++++++++++++++++--- src/frontends/qt2/lengthvalidator.h | 6 +++++- 6 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 60e205896d..918c219ff0 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,11 @@ +2004-11-22 Jürgen Spitzmüller + + * lengthvalidator.[Ch]: add GlueLength validator + * QVSpace.C: + * QVSpaceDialog.C: use GlueLength validator + + * lengthcombo.C: whitespace + 2004-11-17 Lars Gullik Bjonnes * QPrefsDialog.h: include LColor.h to satisfy concept checks. diff --git a/src/frontends/qt2/QVSpace.C b/src/frontends/qt2/QVSpace.C index d7d7f25218..3c5f7a4734 100644 --- a/src/frontends/qt2/QVSpace.C +++ b/src/frontends/qt2/QVSpace.C @@ -19,6 +19,7 @@ #include "QVSpaceDialog.h" #include "Qt2BC.h" +#include "checkedwidgets.h" #include "lengthcombo.h" #include "qt_helpers.h" @@ -150,6 +151,9 @@ void QVSpace::build_dialog() bcview().addReadOnly(dialog_->unitCO); bcview().addReadOnly(dialog_->keepCB); + // initialize the length validator + addCheckedLineEdit(bcview(), dialog_->valueLE, dialog_->valueL); + // remove the %-items from the unit choice dialog_->unitCO->noPercents(); } diff --git a/src/frontends/qt2/QVSpaceDialog.C b/src/frontends/qt2/QVSpaceDialog.C index 133f0b8409..e121594ea4 100644 --- a/src/frontends/qt2/QVSpaceDialog.C +++ b/src/frontends/qt2/QVSpaceDialog.C @@ -16,6 +16,7 @@ #include "QVSpace.h" #include "lengthcombo.h" +#include "lengthvalidator.h" #include "qt_helpers.h" #include @@ -27,6 +28,19 @@ namespace lyx { namespace frontend { + +namespace { + +LengthValidator * unsignedLengthValidator(QLineEdit * ed) +{ + LengthValidator * v = new LengthValidator(ed); + v->setBottom(LyXGlueLength()); + return v; +} + +} // namespace anon + + QVSpaceDialog::QVSpaceDialog(QVSpace * form) : QVSpaceDialogBase(0, 0, false, 0), form_(form) @@ -37,6 +51,8 @@ QVSpaceDialog::QVSpaceDialog(QVSpace * form) form_, SLOT(slotApply())); connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose())); + + valueLE->setValidator(unsignedLengthValidator(valueLE)); } @@ -55,7 +71,7 @@ void QVSpaceDialog::change_adaptor() void QVSpaceDialog::enableCustom(int) { - bool const enable = spacingCO->currentItem()==5; + bool const enable = spacingCO->currentItem() == 5; valueLE->setEnabled(enable); unitCO->setEnabled(enable); } diff --git a/src/frontends/qt2/lengthcombo.C b/src/frontends/qt2/lengthcombo.C index 4fc1a9fe7a..843e9e97b9 100644 --- a/src/frontends/qt2/lengthcombo.C +++ b/src/frontends/qt2/lengthcombo.C @@ -19,7 +19,7 @@ LengthCombo::LengthCombo(QWidget * parent, char * name) : QComboBox(parent, name) { - for (int i=0; i < num_units; i++) + for (int i = 0; i < num_units; i++) insertItem(unit_name_gui[i]); connect(this, SIGNAL(activated(int)), diff --git a/src/frontends/qt2/lengthvalidator.C b/src/frontends/qt2/lengthvalidator.C index f346163d43..458d0a4f7d 100644 --- a/src/frontends/qt2/lengthvalidator.C +++ b/src/frontends/qt2/lengthvalidator.C @@ -25,16 +25,22 @@ using std::string; LengthValidator::LengthValidator(QWidget * parent, const char * name) : QValidator(parent, name), - no_bottom_(true) + no_bottom_(true), glue_length_(false) {} QValidator::State LengthValidator::validate(QString & qtext, int &) const { string const text = fromqstr(qtext); - if (text.empty() || isStrDbl(text)) + if (!text.empty() && isStrDbl(text)) return QValidator::Acceptable; + if (glue_length_) { + LyXGlueLength gl; + return (isValidGlueLength(text, &gl)) ? + QValidator::Acceptable : QValidator::Intermediate; + } + LyXLength l; bool const valid_length = isValidLength(text, &l); if (!valid_length) @@ -48,8 +54,16 @@ QValidator::State LengthValidator::validate(QString & qtext, int &) const } -void LengthValidator::setBottom(LyXLength b) +void LengthValidator::setBottom(LyXLength const & b) { b_ = b; no_bottom_ = false; } + + +void LengthValidator::setBottom(LyXGlueLength const & g) +{ + g_ = g; + no_bottom_ = false; + glue_length_ = true; +} diff --git a/src/frontends/qt2/lengthvalidator.h b/src/frontends/qt2/lengthvalidator.h index 48bf2ff591..ea45721154 100644 --- a/src/frontends/qt2/lengthvalidator.h +++ b/src/frontends/qt2/lengthvalidator.h @@ -13,6 +13,7 @@ #define LENGTHVALIDATOR_H #include "lyxlength.h" +#include "lyxgluelength.h" #include class QWidget; @@ -26,7 +27,8 @@ public: QValidator::State validate(QString &, int &) const; - void setBottom(LyXLength); + void setBottom(LyXLength const &); + void setBottom(LyXGlueLength const &); LyXLength bottom() const { return b_; } private: @@ -36,7 +38,9 @@ private: #endif LyXLength b_; + LyXGlueLength g_; bool no_bottom_; + bool glue_length_; }; # endif // NOT LENGTHVALIDATOR_H -- 2.39.2