commit 98bfbe9ddffe483c99fb27493bcb1bc26a3dc082
Author: Richard Kimberly Heck <[email protected]>
Date:   Sun Jan 10 02:40:12 2021 -0500

    Fix bug #6128.
---
 src/frontends/qt/GuiGraphics.cpp |    4 ++--
 src/frontends/qt/Validator.cpp   |   25 ++++++++++++++++++++-----
 src/frontends/qt/Validator.h     |   12 +++++++++---
 3 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/src/frontends/qt/GuiGraphics.cpp b/src/frontends/qt/GuiGraphics.cpp
index 51036e1..9d04527 100644
--- a/src/frontends/qt/GuiGraphics.cpp
+++ b/src/frontends/qt/GuiGraphics.cpp
@@ -158,8 +158,8 @@ GuiGraphics::GuiGraphics(GuiView & lv)
        scaleValidator->setBottom(0);
        scaleValidator->setDecimals(256); //I guess that will do
        Scale->setValidator(scaleValidator);
-       Height->setValidator(unsignedLengthAutoValidator(Height, qt_(autostr)));
-       Width->setValidator(unsignedLengthAutoValidator(Width, qt_(autostr)));
+       Height->setValidator(positiveLengthAutoValidator(Height, qt_(autostr)));
+       Width->setValidator(positiveLengthAutoValidator(Width, qt_(autostr)));
        angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
 
        //clipping pane
diff --git a/src/frontends/qt/Validator.cpp b/src/frontends/qt/Validator.cpp
index 7c97345..83dcb0c 100644
--- a/src/frontends/qt/Validator.cpp
+++ b/src/frontends/qt/Validator.cpp
@@ -57,6 +57,9 @@ QValidator::State LengthValidator::validate(QString & qtext, 
int &) const
        if (ok && unsigned_ && d < 0)
                return QValidator::Invalid;
 
+       if (ok && positive_ && d <=0)
+               return QValidator::Invalid;
+
        if (qtext.isEmpty() || (ok && !dp))
                return QValidator::Acceptable;
 
@@ -81,21 +84,24 @@ QValidator::State LengthValidator::validate(QString & 
qtext, int &) const
        if (unsigned_ && l.value() < 0)
                return QValidator::Invalid;
 
-       return b_.inPixels(100) <= l.inPixels(100) ?
+       if (positive_ && l.value() <= 0)
+               return QValidator::Invalid;
+
+       return bottom_.inPixels(100) <= l.inPixels(100) ?
                QValidator::Acceptable : QValidator::Intermediate;
 }
 
 
 void LengthValidator::setBottom(Length const & b)
 {
-       b_ = b;
+       bottom_ = b;
        no_bottom_ = false;
 }
 
 
 void LengthValidator::setBottom(GlueLength const & g)
 {
-       g_ = g;
+       glue_bottom_ = g;
        no_bottom_ = false;
        glue_length_ = true;
 }
@@ -142,6 +148,15 @@ LengthAutoValidator * 
unsignedLengthAutoValidator(QLineEdit * ed, QString const
 }
 
 
+LengthAutoValidator * positiveLengthAutoValidator(QLineEdit * ed, QString 
const & autotext)
+{
+       LengthAutoValidator * v = new LengthAutoValidator(ed, autotext);
+       v->setBottom(Length());
+       v->setPositive(true);
+       return v;
+}
+
+
 DoubleAutoValidator::DoubleAutoValidator(QWidget * parent, QString const & 
autotext)
        : QDoubleValidator(parent),
          autotext_(autotext)
@@ -242,10 +257,10 @@ void PathValidator::setChecker(KernelDocType const & 
type, LyXRC const & rc)
 PathValidator * getPathValidator(QLineEdit * ed)
 {
        if (!ed)
-               return 0;
+               return nullptr;
        QValidator * validator = const_cast<QValidator *>(ed->validator());
        if (!validator)
-               return 0;
+               return nullptr;
        return dynamic_cast<PathValidator *>(validator);
 }
 
diff --git a/src/frontends/qt/Validator.h b/src/frontends/qt/Validator.h
index 1ece3a4..c023f61 100644
--- a/src/frontends/qt/Validator.h
+++ b/src/frontends/qt/Validator.h
@@ -61,16 +61,18 @@ public:
        //@{
        void setBottom(Length const &);
        void setBottom(GlueLength const &);
-       Length bottom() const { return b_; }
+        Length bottom() const { return bottom_; }
        void setUnsigned(bool const u) { unsigned_ = u; }
+        void setPositive(bool const u) { positive_ = u; }
        //@}
 
 private:
-       Length b_;
-       GlueLength g_;
+        Length bottom_;
+        GlueLength glue_bottom_;
        bool no_bottom_;
        bool glue_length_;
        bool unsigned_;
+        bool positive_;
 };
 
 
@@ -107,6 +109,10 @@ private:
 LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *, QString const & 
autotext);
 
 
+/// @returns a new @c LengthAutoValidator that does not accept negative 
lengths.
+LengthAutoValidator * positiveLengthAutoValidator(QLineEdit *, QString const & 
autotext);
+
+
 /**
  * A class to determine whether the passed is a double
  * or is @param autotext.
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to