Index: sources/gui/qml/components/Slider.qml =================================================================== diff -u -r38cb7a4ff6d12878d078fb10c8d6915a31dc1df9 -ra070e7cd1dc7dcb4ba7fc5906c195357fe95d2f9 --- sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision 38cb7a4ff6d12878d078fb10c8d6915a31dc1df9) +++ sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision a070e7cd1dc7dcb4ba7fc5906c195357fe95d2f9) @@ -1,16 +1,16 @@ /*! - * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * + * Copyright (c) 2020-2023 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) Peter Lucia - * \date (last) 15-Oct-2020 - * \author (original) Behrouz NematiPour - * \date (original) 18-Mar-2020 - * + * + * \file Slider.qml + * \author (last) Behrouz NematiPour + * \date (last) 10-Feb-2023 + * \author (original) Behrouz NematiPour + * \date (original) 18-Mar-2020 + * */ // Qt @@ -36,10 +36,13 @@ property alias handler : _handler property alias handlerColor : _handler.color + property alias handlerVisible : _handler.visible property alias diameter : _handler.diameter property bool isActive : true + property bool inActiveZero : false // if inActiveZero:true, when is not active (inActive or active:false) sets to zero instead of minimum + property alias progressRectMargin : _progressRect.margin property int tickMarksThickness : 2 @@ -48,6 +51,43 @@ signal progressRectDragged() signal activeChanged() + function incrementValue (vInStepSegments) { + // in case the slider is not yet activated, activate + if (!isActive) { + setActive(true) + } + updateValue(vInStepSegments, true) + } + + function decrementValue (vInStepSegments) { + // in case the slider is not yet activated, activate + if (!isActive) { + setActive(true) + } + updateValue(vInStepSegments, false) + } + + function updateValue(vInStepSegments, vIsIncrement) { + let amountChanged = 1 + if (vInStepSegments) { + amountChanged = step + } + + let newValue = Number.NaN + if(vIsIncrement) { + newValue = _root.value + amountChanged + } else { + newValue = _root.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)) + } + function setActive(active) { if (active) { color = Colors.createTreatmentActive @@ -66,7 +106,7 @@ onIsActiveChanged: { setActive(isActive) if (!isActive) { - value = minimum + value = inActiveZero ? 0 : minimum } activeChanged() } @@ -104,22 +144,34 @@ return ( x * ( maximum - minimum ) ) / width + minimum } + function update(vValue) { + _root.value = vValue + } + function setValue(x) { - if ( x < 0 ) { value = minimum; return; } - if ( x > width ) { value = maximum; return; } + let mValue = 0 + let mMinimum = Number(_root.minimum.toFixed(decimal)) + let mMaximum = Number(_root.maximum.toFixed(decimal)) + if ( x < 0 ) { mValue = mMinimum; update(mValue); return; } + if ( x > width ) { mValue = mMaximum; update(mValue); return; } - value = getValueOfX(x) + mValue = getValueOfX(x) - if ( step === 1 ) { value = parseInt(value); return; } + if ( step === 1 ) { mValue = parseInt(mValue); update(mValue); return; } - var start = 0 - if ( ! stepSnap ) start = minimum - value = Math.round((value - start) / step) * step + start + let start = 0 + if ( ! stepSnap ) start = mMinimum + mValue = Math.round((mValue - start) / step) * step + start + let decimals = Math.round(-Math.log10(step)) - if (decimals > 0) value = value.toFixed(decimals) + if (decimals > 0) { + mValue = mValue.toFixed(decimals) + } - if ( value < minimum ) { value = minimum; return; } - if ( value > maximum ) { value = maximum; return; } + if ( mValue < mMinimum ) { mValue = mMinimum; update(mValue); return; } + if ( mValue > mMaximum ) { mValue = mMaximum; update(mValue); return; } + + update(mValue); return; } function setHandlerPosition() { @@ -203,7 +255,7 @@ radius : diameter color : Colors.highlightProgressBar border { - width: 4 + width: Variables.progressbarHandlerBorderWidth color: Colors.textMain } }