Index: sources/gui/qml/components/Slider.qml =================================================================== diff -u -r00ed70b03062c6f4fa1bfd2e515efd777e086f85 -r83b9d737cd495b34a7b42f5409962a9442f3b8f4 --- sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision 00ed70b03062c6f4fa1bfd2e515efd777e086f85) +++ sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision 83b9d737cd495b34a7b42f5409962a9442f3b8f4) @@ -1,13 +1,13 @@ /*! * - * Copyright (c) 2020-2023 Diality Inc. - All Rights Reserved. + * Copyright (c) 2020-2024 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file Slider.qml * \author (last) Behrouz NematiPour - * \date (last) 31-Mar-2023 + * \date (last) 26-Jan-2024 * \author (original) Behrouz NematiPour * \date (original) 18-Mar-2020 * @@ -25,6 +25,7 @@ */ RangeRect { id: _root property real value : _progressRect.value + property real defaultValue : _root.minimum property real step : 1 property bool stepSnap : false @@ -57,6 +58,8 @@ signal handleSelected() signal sliderSelected() + onDefaultValueChanged: refreshValue() + // this function shall be used in case that any external value is forced to be set for the slider // like the OFF switch wants to externally set the slider value and bypass slider controlls and checks. // same is used in the main treatment Blood,dialyzer sliders to be set to the current value when get in to adjustment screen. @@ -108,19 +111,29 @@ } } - onIsActiveChanged: { - setActiveVisuals(isActive) - + /* + refreshValue() re-evaluates the _root.value and _progressRect.value based on the + current active state. This function is used when the defaultValue property or + isActive property changes. + */ + function refreshValue() { // value is assigned a different value based on active-ness of the slider // This is to resolve the use of slider with a switch and arrows enabled. // It allows correct behavior when using arrow on a first initialize increment of // the slider when the slider has inActiveZero to true. if(!isActive) { - _root.value = inActiveZero ? 0 : minimum + _root.value = inActiveZero ? 0 : _root.defaultValue } else { - _root.value = _progressRect.value = minimum + _root.value = _root.defaultValue } + // need to set the value of progressRect to reflect handle position + _progressRect.value = _root.defaultValue + } + + onIsActiveChanged: { + setActiveVisuals(isActive) + refreshValue () // re-evaluate values activeChanged() // emit } @@ -176,7 +189,9 @@ let mMinimum = Number(_root.minimum.toFixed(decimal)) let mMaximum = Number(_root.maximum.toFixed(decimal)) - if(x < _handler.width) { + // the center of the handler is aligned on the snap point and half width shall be used to set as min not the entire width. + // also half of the hadler is out of slider min position when set on min, which proves the same as above. + if(x < ( _handler.width / 2 ) ) { // The outside of the slider, lower bound case return mMinimum }