]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/Validator.cpp
If we are in a closeEvent, we don't want to close all buffers, because these may...
[lyx.git] / src / frontends / qt4 / Validator.cpp
index e5878b1b63d86ef850ca46e09b6f31f7c91eb2ce..e156dcb099dedbe83a86326438d197cae0c494b3 100644 (file)
@@ -15,7 +15,7 @@
 #include "Validator.h"
 #include "qt_helpers.h"
 
-#include "gettext.h"
+#include "support/gettext.h"
 #include "LyXRC.h"
 
 #include "frontends/alert.h"
 #include "support/lstrings.h"
 
 #include <QLineEdit>
+#include <QLocale>
 #include <QWidget>
 
-using lyx::support::isStrDbl;
-using std::string;
-
+using namespace std;
 
 namespace lyx {
+namespace frontend {
 
 LengthValidator::LengthValidator(QWidget * parent)
        : QValidator(parent),
@@ -40,10 +40,13 @@ 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_) {
                GlueLength gl;
                return (isValidGlueLength(text, &gl)) ?
@@ -86,30 +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
 {
-       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);
+       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)
 {}
 
 
@@ -120,7 +132,7 @@ 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);
 }
@@ -173,7 +185,7 @@ QValidator::State PathValidator::validate(QString & qtext, int &) const
 
                static int counter = 0;
                if (counter == 0) {
-                       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));
                }
@@ -185,10 +197,9 @@ QValidator::State PathValidator::validate(QString & qtext, int &) const
 }
 
 
-void PathValidator::setChecker(frontend::KernelDocType const & type,
-                              LyXRC const & lyxrc)
+void PathValidator::setChecker(KernelDocType const & type, LyXRC const & lyxrc)
 {
-       latex_doc_ = type == frontend::LATEX;
+       latex_doc_ = type == LATEX;
        tex_allows_spaces_ = lyxrc.tex_allows_spaces;
 }
 
@@ -203,6 +214,7 @@ PathValidator * getPathValidator(QLineEdit * ed)
        return dynamic_cast<PathValidator *>(validator);
 }
 
+} // namespace frontend
 } // namespace lyx
 
-#include "Validator_moc.cpp"
+#include "moc_Validator.cpp"