Better time spin box.
This commit is contained in:
parent
f9fc5b1dfe
commit
9a892ec50f
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include "gui/timespinbox.h"
|
#include "gui/timespinbox.h"
|
||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
|
||||||
TimeSpinBox::TimeSpinBox(QWidget *parent) : QDoubleSpinBox(parent) {
|
TimeSpinBox::TimeSpinBox(QWidget *parent) : QDoubleSpinBox(parent) {
|
||||||
setMinimum(5.0);
|
setMinimum(5.0);
|
||||||
@ -36,7 +38,26 @@ double TimeSpinBox::valueFromText(const QString &text) const {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
else {
|
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);
|
input = textFromValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QValidator::State TimeSpinBox::validate(QString &input, int &pos) const {
|
||||||
|
return (valueFromText(input) != -1.0) ? QValidator::Acceptable : QValidator::Intermediate;
|
||||||
|
}
|
||||||
|
@ -29,6 +29,7 @@ class TimeSpinBox : public QDoubleSpinBox {
|
|||||||
double valueFromText(const QString &text) const;
|
double valueFromText(const QString &text) const;
|
||||||
QString textFromValue(double val) const;
|
QString textFromValue(double val) const;
|
||||||
void fixup(QString &input) const;
|
void fixup(QString &input) const;
|
||||||
|
QValidator::State validate(QString &input, int &pos) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TIMESPINBOX_H
|
#endif // TIMESPINBOX_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user