Index: sources/gui/qml/compounds/ValueAdjuster.qml =================================================================== diff -u -rf2aa3ee850de1023cfc011b845ed0364d251b749 -r135c320c850b09365c04e03d95195412c12fba72 --- sources/gui/qml/compounds/ValueAdjuster.qml (.../ValueAdjuster.qml) (revision f2aa3ee850de1023cfc011b845ed0364d251b749) +++ sources/gui/qml/compounds/ValueAdjuster.qml (.../ValueAdjuster.qml) (revision 135c320c850b09365c04e03d95195412c12fba72) @@ -32,58 +32,78 @@ property bool canRefresh : false property alias textColor : _text.color - // fix floating-point precision issue - 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) + QtObject { id: _private + // fix floating-point precision issue + readonly property int multiplier : Math.pow(10, decimal) + readonly property real stepVal : calculatePrecisionValue(step) + readonly property real minVal : calculatePrecisionValue(minimum) + readonly property real maxVal : calculatePrecisionValue(maximum) + readonly property real val : calculatePrecisionValue(value) - readonly property bool canIncrement : isActive ? value < maximum : true - readonly property bool canDecrement : isActive ? canOff ? value > 0 : - value > minimum : true + readonly property bool canIncrement : isActive ? value < maximum : true + readonly property bool canDecrement : isActive ? canOff ? value > 0 : + value > minimum : true + + // round the value based on the given precision (not step) + function calculatePrecisionValue(value) { + return Math.round(value * _private.multiplier) / _private.multiplier + } - signal didChange (real vValue) - signal didActiveChange (bool vState) + // return a fixed point int from the inputted float (using the set precision) + function fixedValue(value) { + return Math.round(value * _private.multiplier) + } - onIsActiveChanged : { - if ( canRefresh ) { canRefresh = false; return; } + function increment() { + if ( ! isActive ) { didActiveChange(true); return } - if ( isActive ) { didChange(_root.defaultValue) } - } + let tValue = _private.val + if (canOff && _private.val < _private.minVal) { + tValue = _private.minVal + } + else { + let fixedVal = _private.fixedValue(_private.val) + let fixedStep = _private.fixedValue(_private.stepVal) + let fixedDelta = fixedStep - (fixedVal % fixedStep) + tValue = (fixedVal + fixedDelta) / _private.multiplier + tValue = Math.min(_private.maxVal, tValue) + } - // round the value based on the given precision (not step) - function calculatePrecisionValue(value) { - return Math.round(value * multiplier) / multiplier - } + didChange(tValue) + } - function refresh() { canRefresh = true } + function decrement() { + if ( ! isActive ) { didActiveChange(true); return } - function clear() { didActiveChange(false) } + let tValue = _private.val + if (canOff && _private.val === _private.minVal) { + tValue = 0 + } + else { + let fixedVal = _private.fixedValue(_private.val) + let fixedStep = _private.fixedValue(_private.stepVal) + let fixedDelta = fixedVal % fixedStep + tValue = (fixedVal - (fixedDelta > 0 ? fixedDelta : fixedStep)) / _private.multiplier + tValue = Math.max(_private.minVal, tValue) + } - 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 + tStep } - else { tValue += tStep } - - didChange(tValue) + didChange(tValue) + } } - function decrement() { - let tValue = val - let stepDelta = calculatePrecisionValue(val % stepVal) - let tStep = (stepDelta === 0) ? stepVal : stepDelta - if ( ! isActive ) { didActiveChange(true); return; } + signal didChange (real vValue) + signal didActiveChange (bool vState) - if ( canOff ) { tValue = val > minVal ? val - tStep : 0 } - else { tValue -= tStep } + onIsActiveChanged : { + if ( canRefresh ) { canRefresh = false; return } - didChange(tValue) + if ( isActive ) { didChange(_root.defaultValue) } } + function refresh() { canRefresh = true } + + function clear() { didActiveChange(false) } + Text { id: _text anchors.centerIn: parent text : _root.isActive ? _root.canOff ? _root.value === 0 ? @@ -194,11 +214,11 @@ leftMargin : Variables.defaultMargin } iconSize : Variables.circleButtonDefaultDiameter - enabled : _root.canDecrement + enabled : _private.canDecrement visible : _root.editable iconImageSource : enabled ? "qrc:/images/iArrowLeft" : "qrc:/images/iArrowLeftDisabled" - onClicked : decrement() + onClicked : _private.decrement() } IconButton { id: _rightArrow @@ -208,10 +228,10 @@ rightMargin : Variables.defaultMargin } iconSize : Variables.circleButtonDefaultDiameter - enabled : _root.canIncrement + enabled : _private.canIncrement visible : _root.editable iconImageSource : enabled ? "qrc:/images/iArrowRight" : "qrc:/images/iArrowRightDisabled" - onClicked : increment() + onClicked : _private.increment() } }