diff --git a/src/widget/wbeatspinbox.cpp b/src/widget/wbeatspinbox.cpp index 1509e8457ce..762fbe99561 100644 --- a/src/widget/wbeatspinbox.cpp +++ b/src/widget/wbeatspinbox.cpp @@ -1,10 +1,12 @@ +#include + #include "widget/wbeatspinbox.h" #include "control/controlobject.h" #include "control/controlproxy.h" #include "util/math.h" -QRegExp WBeatSpinBox::s_regexpBlacklist("[^0-9./ ]"); +QRegExp WBeatSpinBox::s_regexpBlacklist("[^0-9.,/ ]"); WBeatSpinBox::WBeatSpinBox(QWidget * parent, ControlObject* pValueControl, int decimals, double minimum, double maximum) @@ -34,21 +36,31 @@ void WBeatSpinBox::setup(const QDomNode& node, const SkinContext& context) { } void WBeatSpinBox::stepBy(int steps) { - double newValue = value() * pow(2, steps); - if (newValue < minimum()) { - newValue = minimum(); - } else if (newValue > maximum()) { - newValue = maximum(); + double oldValue = m_valueControl.get(); + double newValue; + QString temp = text(); + int cursorPos = lineEdit()->cursorPosition(); + if (validate(temp, cursorPos) == QValidator::Acceptable) { + double editValue = valueFromText(temp); + newValue = editValue * pow(2, steps); + if (newValue < minimum() || newValue > maximum()) { + // don't clamp the value here to not fall out of a measure + newValue = editValue; + } + } else { + // here we have an unacceptable edit, going back to the old value first + newValue = oldValue; } // Do not call QDoubleSpinBox::setValue directly in case // the new value of the ControlObject needs to be confirmed. // Curiously, m_valueControl.set() does not cause slotControlValueChanged // to execute for beatjump_size, so call QDoubleSpinBox::setValue in this function. - double oldValue = m_valueControl.get(); m_valueControl.set(newValue); - if (m_valueControl.get() != oldValue) { - setValue(newValue); + double coValue = m_valueControl.get(); + if (coValue != value()) { + setValue(coValue); } + selectAll(); } void WBeatSpinBox::slotSpinboxValueChanged(double newValue) { @@ -138,23 +150,14 @@ QString WBeatSpinBox::textFromValue(double value) const { sFracPart = fractionString(29, 32); } else if (dFracPart == 0.96875) { sFracPart = fractionString(31, 32); + } else { + return locale().toString(value, 'g', 5); } if (dWholePart > 0) { - if (sFracPart.isEmpty()) { - if (dFracPart == 0.00000) { - return QString::number(dWholePart, 'f', 0); - } else { - return QString::number(value, 'f', 5); - } - } - return QString::number(dWholePart, 'f', 0) + " " + sFracPart; - } else { - if (sFracPart.isEmpty() ) { - return QString::number(value, 'f', 5); - } - return sFracPart; + return locale().toString(dWholePart, 'f', 0) + " " + sFracPart; } + return sFracPart; } double WBeatSpinBox::valueFromText(const QString& text) const { @@ -164,7 +167,7 @@ double WBeatSpinBox::valueFromText(const QString& text) const { bool conversionWorked = false; double dValue; - dValue = text.toDouble(&conversionWorked); + dValue = locale().toDouble(text, &conversionWorked); if (conversionWorked) { return dValue; } @@ -183,7 +186,8 @@ double WBeatSpinBox::valueFromText(const QString& text) const { sNumerator = splitFraction.at(0); sDenominator = splitFraction.at(1); - return sIntPart.toDouble() + sNumerator.toDouble() / sDenominator.toDouble(); + return locale().toDouble(sIntPart) + + locale().toDouble(sNumerator) / locale().toDouble(sDenominator); } QValidator::State WBeatSpinBox::validate(QString& input, int& pos) const { @@ -200,7 +204,7 @@ QValidator::State WBeatSpinBox::validate(QString& input, int& pos) const { } bool conversionWorked = false; - input.toDouble(&conversionWorked); + locale().toDouble(input, &conversionWorked); if (conversionWorked) { return QValidator::Acceptable; }