Index: sources/gui/qml/compounds/ValueAdjuster.qml =================================================================== diff -u -r5f4b3aacfede4aa545a44c7f3b33ca649b81aac7 -rf2aa3ee850de1023cfc011b845ed0364d251b749 --- sources/gui/qml/compounds/ValueAdjuster.qml (.../ValueAdjuster.qml) (revision 5f4b3aacfede4aa545a44c7f3b33ca649b81aac7) +++ sources/gui/qml/compounds/ValueAdjuster.qml (.../ValueAdjuster.qml) (revision f2aa3ee850de1023cfc011b845ed0364d251b749) @@ -30,11 +30,13 @@ property bool editable : true property bool canOff : false property bool canRefresh : false + property alias textColor : _text.color // fix floating-point precision issue - readonly property real stepVal : Math.round(step * 100) / 100 - readonly property real minVal : Math.round(minimum * 100) / 100 - readonly property real val : Math.round(value * 100) / 100 + readonly property int multiplier : Math.pow(10, decimal) + readonly property real stepVal : calculatePrecisionValue(step) + readonly property real minVal : calculatePrecisionValue(minimum) + readonly property real val : calculatePrecisionValue(value) readonly property bool canIncrement : isActive ? value < maximum : true readonly property bool canDecrement : isActive ? canOff ? value > 0 : @@ -49,27 +51,35 @@ if ( isActive ) { didChange(_root.defaultValue) } } + // round the value based on the given precision (not step) + function calculatePrecisionValue(value) { + return Math.round(value * multiplier) / multiplier + } + function refresh() { canRefresh = true } function clear() { didActiveChange(false) } function increment() { let tValue = value + let stepDelta = calculatePrecisionValue(stepVal - (val % stepVal)) + let tStep = (stepDelta === 0) ? stepVal : stepDelta if ( ! isActive ) { didActiveChange(true); return; } - if ( canOff ) { tValue = val < minVal ? minVal : val + stepVal } - else { tValue += stepVal } + if ( canOff ) { tValue = val < minVal ? minVal : val + tStep } + else { tValue += tStep } didChange(tValue) - } - function decrement(vValue) { - let tValue = value + function decrement() { + let tValue = val + let stepDelta = calculatePrecisionValue(val % stepVal) + let tStep = (stepDelta === 0) ? stepVal : stepDelta if ( ! isActive ) { didActiveChange(true); return; } - if ( canOff ) { tValue = val > minVal ? val - stepVal : 0 } - else { tValue -= stepVal } + if ( canOff ) { tValue = val > minVal ? val - tStep : 0 } + else { tValue -= tStep } didChange(tValue) } @@ -137,8 +147,7 @@ } onReleased: { - _sliderMouseArea.grabbed = true -. grabbed = false + _sliderMouseArea.grabbed = false _slider.opacity = 0 }