]> git.lyx.org Git - features.git/commitdiff
glue length validator for qt
authorJürgen Spitzmüller <spitz@lyx.org>
Mon, 22 Nov 2004 12:22:19 +0000 (12:22 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Mon, 22 Nov 2004 12:22:19 +0000 (12:22 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9286 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt2/ChangeLog
src/frontends/qt2/QVSpace.C
src/frontends/qt2/QVSpaceDialog.C
src/frontends/qt2/lengthcombo.C
src/frontends/qt2/lengthvalidator.C
src/frontends/qt2/lengthvalidator.h

index 60e205896da4319d6491434dc62a2345042145b9..918c219ff03970b46520023bd4a98428768a2934 100644 (file)
@@ -1,3 +1,11 @@
+2004-11-22  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
+
+       * lengthvalidator.[Ch]: add GlueLength validator
+       * QVSpace.C:
+       * QVSpaceDialog.C: use GlueLength validator
+       
+       * lengthcombo.C: whitespace
+
 2004-11-17  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * QPrefsDialog.h: include LColor.h to satisfy concept checks.
index d7d7f25218a18d30d2a8c6e58024b86ac6519ca8..3c5f7a47340788a0b7cac33a727a8d9a6a5f0f8f 100644 (file)
@@ -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();
 }
index 133f0b840966208162477a7209038465091d2a45..e121594ea4fe34b76fdef8ea249272ae8f9d5e53 100644 (file)
@@ -16,6 +16,7 @@
 #include "QVSpace.h"
 
 #include "lengthcombo.h"
+#include "lengthvalidator.h"
 #include "qt_helpers.h"
 
 #include <qcombobox.h>
 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);
 }
index 4fc1a9fe7ae57a4348343e1486174aa4391cf038..843e9e97b9e178c0f999ac0348ef42927e6a88c7 100644 (file)
@@ -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)),
index f346163d4374719e373cba8f3bc389f0c4c8bc3b..458d0a4f7dbcf6385eeae452384992dc923b7c2e 100644 (file)
@@ -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;
+}
index 48bf2ff591ab7c73e577bb626497dc2eb40046df..ea457211549860287f5f3228ccab3979852b629f 100644 (file)
@@ -13,6 +13,7 @@
 #define LENGTHVALIDATOR_H
 
 #include "lyxlength.h"
+#include "lyxgluelength.h"
 #include <qvalidator.h>
 
 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