Index: sources/gui/qml/components/SliderCreateTreatment.qml =================================================================== diff -u -rb72d5c0a794796139351ac79747e00d658bad620 -r83b9d737cd495b34a7b42f5409962a9442f3b8f4 --- sources/gui/qml/components/SliderCreateTreatment.qml (.../SliderCreateTreatment.qml) (revision b72d5c0a794796139351ac79747e00d658bad620) +++ sources/gui/qml/components/SliderCreateTreatment.qml (.../SliderCreateTreatment.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 SliderCreateTreatment.qml * \author (last) Behrouz NematiPour - * \date (last) 21-Oct-2022 + * \date (last) 26-Jan-2024 * \author (original) Peter Lucia * \date (original) 07-Jul-2020 * @@ -27,12 +27,15 @@ Rectangle { id: _root property Flickable flickable: null + property var toggleSwich : null // it is the treatment slider custom Switch bu it will be defined outside of this component and the var type would suffice. + property bool adjustable : true property alias label : _label.text property alias decimal : _slider.decimal property alias minimum : _slider.minimum property alias maximum : _slider.maximum property alias value : _slider.value + property alias defaultValue : _slider.defaultValue property alias step : _slider.step property alias inActiveZero: _slider.inActiveZero @@ -42,38 +45,51 @@ property bool active : false property bool valid : true - property bool isUsingDisplayValue : true // indicate whether using the slider's actual value or displayedValue + property alias enableAdjustButtons : _sliderArrows.enabled signal pressed () signal released() height : Variables.createTreatmentSliderHeight width : Variables.createTreatmentSliderWidth - color : "transparent" + color : Colors.transparent anchors.horizontalCenter: parent.horizontalCenter - function setColor() { - let color = Colors.textDisableButton - if ( _root.active ) { - if ( _root.valid ) { - color = Colors.textMain - } - else { - color = Colors.createTreatmentInvalidParam - } + function clear() { + reset(defaultValue) + if ( toggleSwich ) { + toggleSwich.checked = false + toggleSwich.active = false } - return color + _root.active = false } + function reset(vValue) { + _slider.reset(vValue) + } + + function setColor() { + let color = Colors.textMain + if ( ! _root.valid ) { color = Colors.createTreatmentInvalidParam ; return color } + if ( ! _root.active ) { color = Colors.textDisableButton ; return color } + return color + } + function setValue() { + // The slider is not adjustable, implying it won't have a value change + if ( !adjustable && zeroLabel !== "") { + return _root.zeroLabel + } + let mValue = "__" let unit = " " + _root.unit + if ( _root.active ) { if ( _slider.value === 0 && zeroLabel !== "" ) { return _root.zeroLabel } - mValue = isUsingDisplayValue ? _slider.displayedValue : _slider.value + mValue = _slider.value.toFixed(decimal) } return mValue + unit } @@ -85,7 +101,7 @@ } function setActiveValid() { - _root.active = _root.valid = true + _root.active = true } Text { id: _label @@ -111,17 +127,52 @@ anchors.horizontalCenter: parent.horizontalCenter anchors.bottom : parent.bottom width : Variables.createTreatmentSliderWidth - diameter : Variables.sliderCircleDiameter + height : Variables.sliderDefaultBodyHeight + diameter : Variables.progressbarHandler touchMargin : Variables.createTreatmentSliderMargin - color : Colors.createTreatmentInactive handlerColor : Colors.createTreatmentInactive handlerVisible : _root.adjustable - height : Variables.progressbarFluidHeight isActive : _root.active ticks : true - onDragged : { setInteractive(false) ; ; setActiveValid( );} - onPressed : { setInteractive(false) ; _root.pressed ( ) ; } - onReleased : { setInteractive(true ) ; _root.released( ) ; } - onHandleSelected : { setActiveValid(); } + onDragged : { setInteractive(false) ; ; } + onPressed : { setInteractive(false) ; _root.pressed () ; } + onReleased : { setInteractive(true ) ; _root.released() ; } + onHandleSelected : { setActiveValid(); } + onSliderSelected : { setActiveValid(); } } + + SliderArrows{ id:_sliderArrows + anchors.verticalCenter : _slider.verticalCenter + anchors.left : _slider.right + anchors.leftMargin : Variables.sliderAdjustButtonLeftMargin + + // NOTE: @inActiveZero + // the slider which use inActiveZero are the once, with OFF button. + // these sliders have 0 as defalut to indicate OFF. + // when activated the first value they get is still the 0 ( OFF ). + // in that case we decrement once to get the correct minimum value. + // as example heparin dispensing after gets ON, firsrt decrement shows OFF ( 0 ). + // NOTE: if 0=defaultValue is in range (minimum < defaultValue < maximum), we still have problem, and needs more investigation + onIncrementValue : { + if ( _slider.isActive) { + _slider.incrementValue(true) + } else { + setActiveValid() + if ( inActiveZero ) { // NOTE: @inActiveZero + _slider.decrementValue() + } + } + } + onDecrementValue : { + if ( _slider.isActive) { + _slider.decrementValue(true) + } else { + setActiveValid() + if ( inActiveZero ) { // NOTE: @inActiveZero + _slider.decrementValue() + } + } + } + } + }