Index: sources/gui/qml/components/Slider.qml =================================================================== diff -u -r5e03d3f26ea0c88562e430c4b8192dd745fa1011 -ra070e7cd1dc7dcb4ba7fc5906c195357fe95d2f9 --- sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision 5e03d3f26ea0c88562e430c4b8192dd745fa1011) +++ sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision a070e7cd1dc7dcb4ba7fc5906c195357fe95d2f9) @@ -1,13 +1,13 @@ /*! * - * Copyright (c) 2020-2022 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) Behrouz NematiPour - * \date (last) 22-Jul-2022 + * \date (last) 10-Feb-2023 * \author (original) Behrouz NematiPour * \date (original) 18-Mar-2020 * @@ -51,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 @@ -113,24 +150,28 @@ function setValue(x) { let mValue = 0 - if ( x < 0 ) { mValue = minimum; update(mValue); return; } - if ( x > width ) { mValue = maximum; update(mValue); return; } + 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; } mValue = getValueOfX(x) - if ( step === 1 ) { mValue = parseInt(mValue); update(mValue); return; } + if ( step === 1 ) { mValue = parseInt(mValue); update(mValue); return; } let start = 0 - if ( ! stepSnap ) start = minimum + if ( ! stepSnap ) start = mMinimum mValue = Math.round((mValue - start) / step) * step + start let decimals = Math.round(-Math.log10(step)) - if (decimals > 0) mValue = mValue.toFixed(decimals) + if (decimals > 0) { + mValue = mValue.toFixed(decimals) + } - if ( mValue < minimum ) { mValue = minimum; update(mValue); return; } - if ( mValue > maximum ) { mValue = maximum; update(mValue); return; } + if ( mValue < mMinimum ) { mValue = mMinimum; update(mValue); return; } + if ( mValue > mMaximum ) { mValue = mMaximum; update(mValue); return; } - update(mValue); return; + update(mValue); return; } function setHandlerPosition() {