Index: sources/gui/qml/compounds/ValueAdjuster.qml =================================================================== diff -u -rea4de12b2c7d6306a9cb89ff23eb95ccd25077a1 -r90f945668f1fff9ecb182b16ee33997cf515f52c --- sources/gui/qml/compounds/ValueAdjuster.qml (.../ValueAdjuster.qml) (revision ea4de12b2c7d6306a9cb89ff23eb95ccd25077a1) +++ sources/gui/qml/compounds/ValueAdjuster.qml (.../ValueAdjuster.qml) (revision 90f945668f1fff9ecb182b16ee33997cf515f52c) @@ -24,48 +24,61 @@ property real minimum : 0 property real maximum : 0 property real value : 0 - property real defaultValue : 0 + property real defaultValue: 0 property real step : 0 - - property bool active : false + property bool isActive : false property bool editable : true + property bool canOff : false + property bool canRefresh : false - property bool canIncrement : active ? value < maximum : true - property bool canDecrement : active ? allowOff ? value > 0 : - value > minimum : true - - property bool allowOff : false - // 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 - onActiveChanged : if ( active ) { _root.value = _root.defaultValue } + readonly property bool canIncrement : isActive ? value < maximum : true + readonly property bool canDecrement : isActive ? canOff ? value > 0 : + value > minimum : true - function clear() { _root.active = false } + signal didChange (real vValue) + signal didActiveChange (bool vState) + onIsActiveChanged : { + if ( canRefresh ) { canRefresh = false; return; } + + if ( isActive ) { didChange(_root.defaultValue) } + } + + function refresh() { canRefresh = true } + + function clear() { didActiveChange(false) } + function increment() { - if ( ! active ) { active = true } - else { - if ( allowOff ) { value = val < minVal ? minVal : val + stepVal } - else { value += stepVal } - } + let tValue = value + if ( ! isActive ) { didActiveChange(true); return; } + + if ( canOff ) { tValue = val < minVal ? minVal : val + stepVal } + else { tValue += stepVal } + + didChange(tValue) + } - function decrement() { - if ( ! active ) { active = true } - else { - if ( allowOff ) { value = val > minVal ? val - stepVal : 0 } - else { value -= stepVal } - } + function decrement(vValue) { + let tValue = value + if ( ! isActive ) { didActiveChange(true); return; } + + if ( canOff ) { tValue = val > minVal ? val - stepVal : 0 } + else { tValue -= stepVal } + + didChange(tValue) } Text { id: _text anchors.centerIn: parent - text : _root.active ? _root.allowOff ? _root.value === 0 ? - "OFF" : - _root.value.toFixed( _root.decimal ) : + text : _root.isActive ? _root.canOff ? _root.value === 0 ? + "OFF" : + _root.value.toFixed( _root.decimal ) : _root.value.toFixed( _root.decimal ) : Variables.emptyEntry color : Colors.offWhite font.pixelSize : Fonts.fontPixelValueControl @@ -118,10 +131,7 @@ pressAndHoldInterval: 0 onClicked: { - if ( _root.editable ) { - active = true - focus = true - } + if ( _root.editable ) { didActiveChange(true); focus = true } _slider.opacity = 0 } @@ -133,10 +143,7 @@ } onPressAndHold: { - if ( _root.editable ) { - active = true - focus = true - } + if ( _root.editable ) { didActiveChange(true); focus = true } _sliderMouseArea.grabbed = true } @@ -148,7 +155,7 @@ _slider.pos = Math.max(0, Math.min(1, mouse.x / parent.width)) let raw = _slider.from + _slider.pos * (_slider.to - _slider.from) let stepped = Math.round((raw - _slider.from) / _root.step) * _root.step + _slider.from - _root.value = stepped + didChange(stepped) } }