X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FValidator.cpp;h=6d0ffc0175242391a297dbda0fdb84944774448c;hb=1f10969bb5c5f36017bf5ba8671381b09945cf57;hp=13f813e9f39a2f2a52760c58a014875bb4d99a91;hpb=a756403301ff8fb78df4dc1e131e4cd50cd976e1;p=lyx.git diff --git a/src/frontends/qt4/Validator.cpp b/src/frontends/qt4/Validator.cpp index 13f813e9f3..6d0ffc0175 100644 --- a/src/frontends/qt4/Validator.cpp +++ b/src/frontends/qt4/Validator.cpp @@ -34,21 +34,37 @@ namespace frontend { LengthValidator::LengthValidator(QWidget * parent) : QValidator(parent), - no_bottom_(true), glue_length_(false) + no_bottom_(true), glue_length_(false), unsigned_(false) {} QValidator::State LengthValidator::validate(QString & qtext, int &) const { + QLocale loc; bool ok; - qtext.trimmed().toDouble(&ok); - if (qtext.isEmpty() || ok) + double d = loc.toDouble(qtext.trimmed(), &ok); + // QLocale::toDouble accepts something like "1." + // We don't. + bool dp = qtext.endsWith(loc.decimalPoint()); + if (!ok) { + // Fall back to C + QLocale c(QLocale::C); + d = c.toDouble(qtext.trimmed(), &ok); + dp = qtext.endsWith(c.decimalPoint()); + } + + if (ok && unsigned_ && d < 0) + return QValidator::Invalid; + + if (qtext.isEmpty() || (ok && !dp)) return QValidator::Acceptable; string const text = fromqstr(qtext); if (glue_length_) { GlueLength gl; + if (unsigned_ && gl.len().value() < 0) + return QValidator::Invalid; return (isValidGlueLength(text, &gl)) ? QValidator::Acceptable : QValidator::Intermediate; } @@ -61,6 +77,9 @@ QValidator::State LengthValidator::validate(QString & qtext, int &) const if (no_bottom_) return QValidator::Acceptable; + if (unsigned_ && l.value() < 0) + return QValidator::Invalid; + return b_.inPixels(100) <= l.inPixels(100) ? QValidator::Acceptable : QValidator::Intermediate; } @@ -85,6 +104,7 @@ LengthValidator * unsignedLengthValidator(QLineEdit * ed) { LengthValidator * v = new LengthValidator(ed); v->setBottom(Length()); + v->setUnsigned(true); return v; } @@ -93,6 +113,7 @@ LengthValidator * unsignedGlueLengthValidator(QLineEdit * ed) { LengthValidator * v = new LengthValidator(ed); v->setBottom(GlueLength()); + v->setUnsigned(true); return v; } @@ -115,6 +136,7 @@ LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed, QString const { LengthAutoValidator * v = new LengthAutoValidator(ed, autotext); v->setBottom(Length()); + v->setUnsigned(true); return v; }