X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FValidator.cpp;h=7f5d5d45e283634838252b710757d72918d08223;hb=43c09d723435a5b203f2ac0c39e2086de836b386;hp=51103d957df393514ffbeee851c1fc1bbf373f7e;hpb=1fc477efac5fd3804c6407a03791e713f643fc43;p=lyx.git diff --git a/src/frontends/qt4/Validator.cpp b/src/frontends/qt4/Validator.cpp index 51103d957d..7f5d5d45e2 100644 --- a/src/frontends/qt4/Validator.cpp +++ b/src/frontends/qt4/Validator.cpp @@ -24,6 +24,7 @@ #include "support/lstrings.h" #include +#include #include using namespace std; @@ -39,10 +40,13 @@ LengthValidator::LengthValidator(QWidget * parent) QValidator::State LengthValidator::validate(QString & qtext, int &) const { - string const text = fromqstr(qtext); - if (text.empty() || support::isStrDbl(text)) + bool ok; + qtext.trimmed().toDouble(&ok); + if (qtext.isEmpty() || ok) return QValidator::Acceptable; + string const text = fromqstr(qtext); + if (glue_length_) { GlueLength gl; return (isValidGlueLength(text, &gl)) ? @@ -85,29 +89,39 @@ LengthValidator * unsignedLengthValidator(QLineEdit * ed) } -LengthAutoValidator::LengthAutoValidator(QWidget * parent) - : LengthValidator(parent) +LengthValidator * unsignedGlueLengthValidator(QLineEdit * ed) +{ + LengthValidator * v = new LengthValidator(ed); + v->setBottom(GlueLength()); + return v; +} + + +LengthAutoValidator::LengthAutoValidator(QWidget * parent, QString const autotext) + : LengthValidator(parent), + autotext_(autotext) {} QValidator::State LengthAutoValidator::validate(QString & qtext, int & dummy) const { - if (qtext == "auto") + if (qtext == autotext_) return QValidator::Acceptable; return LengthValidator::validate(qtext, dummy); } -LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed) +LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed, QString const autotext) { - LengthAutoValidator * v = new LengthAutoValidator(ed); + LengthAutoValidator * v = new LengthAutoValidator(ed, autotext); v->setBottom(Length()); return v; } -DoubleAutoValidator::DoubleAutoValidator(QWidget * parent) - : QDoubleValidator(parent) +DoubleAutoValidator::DoubleAutoValidator(QWidget * parent, QString const autotext) + : QDoubleValidator(parent), + autotext_(autotext) {} @@ -118,12 +132,24 @@ DoubleAutoValidator::DoubleAutoValidator(double bottom, QValidator::State DoubleAutoValidator::validate(QString & input, int & pos) const { - if (input == "auto") + if (input == autotext_) return QValidator::Acceptable; return QDoubleValidator::validate(input, pos); } +NoNewLineValidator::NoNewLineValidator(QWidget * parent) + : QValidator(parent) +{} + + +QValidator::State NoNewLineValidator::validate(QString & qtext, int &) const +{ + qtext.remove(QRegExp("[\\n\\r]")); + return QValidator::Acceptable; +} + + PathValidator::PathValidator(bool acceptable_if_empty, QWidget * parent) : QValidator(parent),