Index: sources/gui/qml/components/Slider.qml =================================================================== diff -u -r3bf1c89cba7851e7658d4a7f2e7054ee6a4ff000 -r18c39727da06312b90d15751e6a27e03c7b6742a --- sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision 3bf1c89cba7851e7658d4a7f2e7054ee6a4ff000) +++ sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision 18c39727da06312b90d15751e6a27e03c7b6742a) @@ -24,9 +24,7 @@ * \brief Denali project ProgressBar */ RangeRect { id: _root - property alias value : _progressRect.value - property real displayedValue : 0 - property real initActiveValue : _root.minimum // the value to assigned upon first activation + property real value : _progressRect.value property real step : 1 property bool stepSnap : false @@ -75,17 +73,21 @@ let newValue = Number.NaN if(vIsIncrement) { - newValue = _root.value + amountChanged + newValue = _progressRect.value + amountChanged } else { - newValue = _root.value - amountChanged + newValue = _progressRect.value - amountChanged } // Capping values based on min/max threshold if ( newValue < minimum ) newValue = minimum if ( newValue > maximum ) newValue = maximum - // update new value - update(newValue.toFixed(decimal)) + // Update the slider's visual value + _private.previousSliderValue = newValue // for comparison purposes + _progressRect.value = newValue // visual value + + // update slider value with rounded new value + update(newValue) } function setActiveVisuals(active) { @@ -98,6 +100,8 @@ } } + onEnabledChanged: _progressRect.value = minimum // reset the visual progress bar + onIsActiveChanged: { setActiveVisuals(isActive) @@ -106,21 +110,14 @@ // It allows correct behavior when using arrow on a first initialize increment of // the slider when the slider has inActiveZero to true. if(!isActive) { - value = inActiveZero ? 0 : minimum + _root.value = inActiveZero ? 0 : minimum } else { - value = initActiveValue + _root.value = _progressRect.value = minimum } activeChanged() // emit } - onValueChanged: { - if ( _root.isActive ) { - // update the displayed value to the attentive snapped value - _root.displayedValue = calculateRoundedValue(_root.value) - } - } - height : Variables.sliderDefaultBodyHeight touchMargin : 25 leftRightTouchMargin: _handler.width/2 @@ -238,9 +235,10 @@ ProgressRect { id: _progressRect property real previousSliderValue: Number.NaN - value : (inActiveZero && (!isActive)) ? 0 : initActiveValue + value : minimum color : Colors.sliderHighlightColor decimal : _root.decimal + minimum : _root.minimum maximum : _root.maximum leftRightTouchMargin: _handler.width/2 @@ -269,16 +267,21 @@ // Check the cursor's current value to determine if the cursor had moved // Do not avoid type coercion, it will produce undesired results - if(newCurrentValue != _progressRect.previousSliderValue) { - // The cursor did move + if(newCurrentValue != _private.previousSliderValue) { + + // The cursor did move if(stepSnapOnRelease) { // check for snapping state to save an iteration of recalculation if snap is off newCurrentValue = calculateValue(vCurrentPositionX, stepSnapOnRelease) } // Update the slider's value since the cursor did move - update(newCurrentValue) - _progressRect.previousSliderValue = newCurrentValue + _private.previousSliderValue = newCurrentValue // for comparison purposes + _progressRect.value = newCurrentValue // visual value + + // update slider value with rounded new value + update(calculateRoundedValue(newCurrentValue)) + } } @@ -287,21 +290,16 @@ // Need to account for the extended touch areas let adjustedXPosition = vMouseEvent.x - _progressRect.leftRightTouchMargin let newCurrentValue = calculateValue(adjustedXPosition, !stepSnapOnRelease) - update(newCurrentValue) + _progressRect.value = newCurrentValue // update visual active slider bar + + update(calculateRoundedValue(newCurrentValue)) // displayed/slider value } + onPressed: { // Indicate that the slider body was selected to provide handling/activation sliderSelected() // emit - // On a pressed action, if the snapped version of the new value is the same as the - // current snapped value, do nothing; otherwise update the value to stay under - // the cursor until a release action happens to update to new snapped value - let adjustedXPosition = vMouseEvent.x - _progressRect.leftRightTouchMargin - let newCurrentValue = calculateValue(adjustedXPosition, !stepSnapOnRelease) - let roundedNewNumber = calculateRoundedValue(newCurrentValue) - if(roundedNewNumber != _progressRect.value){ - update(newCurrentValue) - } + updateHandleValue(vMouseEvent.x - _progressRect.leftRightTouchMargin) } onReleased: { // Need to account for the extended touch areas @@ -327,11 +325,6 @@ anchors.fill: parent propagateComposedEvents: true onPressed: { - // Handle was inactive and was selected, update the value - if ( !_root.isActive ) { - value = inActiveZero ? 0 : minimum - _root.displayedValue = calculateRoundedValue(value) - } mouse.accepted = false // allow propagtion to the lower mouse areas handleSelected() // emit }