diff --git a/src/gui/timespinbox.cpp b/src/gui/timespinbox.cpp index be5f0014a..addea9ee3 100644 --- a/src/gui/timespinbox.cpp +++ b/src/gui/timespinbox.cpp @@ -17,6 +17,8 @@ #include "gui/timespinbox.h" +#include + TimeSpinBox::TimeSpinBox(QWidget *parent) : QDoubleSpinBox(parent) { setMinimum(5.0); @@ -36,7 +38,26 @@ double TimeSpinBox::valueFromText(const QString &text) const { return value; } else { - return 0.0; + QRegExp rx("\\b[0-9]{1,}\\b"); + QStringList numbers; + int pos = 0; + int count = 0; + + while ((pos = rx.indexIn(text, pos)) != -1) { + numbers.append(rx.cap(0)); + + if (pos >= 0) { + ++pos; + ++count; + } + } + + if (numbers.size() == 2) { + return (numbers.at(0).toDouble() * 60.0) + numbers.at(1).toDouble(); + } + else { + return -1.0; + } } } @@ -59,3 +80,7 @@ void TimeSpinBox::fixup(QString &input) const { input = textFromValue(value); } } + +QValidator::State TimeSpinBox::validate(QString &input, int &pos) const { + return (valueFromText(input) != -1.0) ? QValidator::Acceptable : QValidator::Intermediate; +} diff --git a/src/gui/timespinbox.h b/src/gui/timespinbox.h index 74c7f1ebd..7c848c487 100644 --- a/src/gui/timespinbox.h +++ b/src/gui/timespinbox.h @@ -29,6 +29,7 @@ class TimeSpinBox : public QDoubleSpinBox { double valueFromText(const QString &text) const; QString textFromValue(double val) const; void fixup(QString &input) const; + QValidator::State validate(QString &input, int &pos) const; }; #endif // TIMESPINBOX_H