X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FValidator.cpp;h=e156dcb099dedbe83a86326438d197cae0c494b3;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=262574d5b4ad2f898751f184adbbd4a3d0805bde;hpb=8c5f097b5d59cc157b39a08fa5d3f5fa82cf1e4f;p=lyx.git diff --git a/src/frontends/qt4/Validator.cpp b/src/frontends/qt4/Validator.cpp index 262574d5b4..e156dcb099 100644 --- a/src/frontends/qt4/Validator.cpp +++ b/src/frontends/qt4/Validator.cpp @@ -15,27 +15,22 @@ #include "Validator.h" #include "qt_helpers.h" -#include "gettext.h" -#include "lyxrc.h" +#include "support/gettext.h" +#include "LyXRC.h" -#include "frontends/Alert.h" - -#include "frontends/controllers/Dialog.h" +#include "frontends/alert.h" #include "support/docstring.h" #include "support/lstrings.h" -#include "support/std_ostream.h" #include +#include #include -#include - -using lyx::support::isStrDbl; -using std::string; - +using namespace std; namespace lyx { +namespace frontend { LengthValidator::LengthValidator(QWidget * parent) : QValidator(parent), @@ -45,17 +40,20 @@ LengthValidator::LengthValidator(QWidget * parent) QValidator::State LengthValidator::validate(QString & qtext, int &) const { - string const text = fromqstr(qtext); - if (text.empty() || isStrDbl(text)) + bool ok; + qtext.trimmed().toDouble(&ok); + if (qtext.isEmpty() || ok) return QValidator::Acceptable; + string const text = fromqstr(qtext); + if (glue_length_) { - LyXGlueLength gl; + GlueLength gl; return (isValidGlueLength(text, &gl)) ? QValidator::Acceptable : QValidator::Intermediate; - } + } - LyXLength l; + Length l; bool const valid_length = isValidLength(text, &l); if (!valid_length) return QValidator::Intermediate; @@ -68,14 +66,14 @@ QValidator::State LengthValidator::validate(QString & qtext, int &) const } -void LengthValidator::setBottom(LyXLength const & b) +void LengthValidator::setBottom(Length const & b) { b_ = b; no_bottom_ = false; } -void LengthValidator::setBottom(LyXGlueLength const & g) +void LengthValidator::setBottom(GlueLength const & g) { g_ = g; no_bottom_ = false; @@ -86,45 +84,55 @@ void LengthValidator::setBottom(LyXGlueLength const & g) LengthValidator * unsignedLengthValidator(QLineEdit * ed) { LengthValidator * v = new LengthValidator(ed); - v->setBottom(LyXLength()); + v->setBottom(Length()); + return v; +} + + +LengthValidator * unsignedGlueLengthValidator(QLineEdit * ed) +{ + LengthValidator * v = new LengthValidator(ed); + v->setBottom(GlueLength()); return v; } -LengthAutoValidator::LengthAutoValidator(QWidget * parent) - : LengthValidator(parent) +LengthAutoValidator::LengthAutoValidator(QWidget * parent, QString const autotext) + : LengthValidator(parent), + autotext_(autotext) {} QValidator::State LengthAutoValidator::validate(QString & qtext, int & dummy) const { - string const text = fromqstr(qtext); - if (text == "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); - v->setBottom(LyXLength()); + 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) +{} DoubleAutoValidator::DoubleAutoValidator(double bottom, - double top, int decimals, QObject * parent) : - QDoubleValidator(bottom, top, decimals, parent) {} + double top, int decimals, QObject * parent) + : QDoubleValidator(bottom, top, decimals, parent) +{} QValidator::State DoubleAutoValidator::validate(QString & input, int & pos) const { - string const text = fromqstr(input); - if (text == "auto") + if (input == autotext_) return QValidator::Acceptable; return QDoubleValidator::validate(input, pos); } @@ -164,9 +172,9 @@ QValidator::State PathValidator::validate(QString & qtext, int &) const if (!latex_doc_) return QValidator::Acceptable; - docstring const text = lyx::support::trim(qstring_to_ucs4(qtext)); + docstring const text = support::trim(qstring_to_ucs4(qtext)); if (text.empty()) - return acceptable_if_empty_ ? + return acceptable_if_empty_ ? QValidator::Acceptable : QValidator::Intermediate; docstring invalid_chars = from_ascii("#$%{}()[]\"^"); @@ -177,7 +185,7 @@ QValidator::State PathValidator::validate(QString & qtext, int &) const static int counter = 0; if (counter == 0) { - lyx::frontend::Alert::error(_("Invalid filename"), + Alert::error(_("Invalid filename"), _("LyX does not provide LaTeX support for file names containing any of these characters:\n") + printable_list(invalid_chars)); } @@ -189,10 +197,9 @@ QValidator::State PathValidator::validate(QString & qtext, int &) const } -void PathValidator::setChecker(lyx::frontend::KernelDocType const & type, - LyXRC const & lyxrc) +void PathValidator::setChecker(KernelDocType const & type, LyXRC const & lyxrc) { - latex_doc_ = type == lyx::frontend::Kernel::LATEX; + latex_doc_ = type == LATEX; tex_allows_spaces_ = lyxrc.tex_allows_spaces; } @@ -207,7 +214,7 @@ PathValidator * getPathValidator(QLineEdit * ed) return dynamic_cast(validator); } +} // namespace frontend } // namespace lyx -#include "Validator_moc.cpp" - +#include "moc_Validator.cpp"