Index: sources/gui/qml/components/Slider.qml =================================================================== diff -u -rccb91da4becded9a7ad409b758bba96784d9feba -ra070e7cd1dc7dcb4ba7fc5906c195357fe95d2f9 --- sources/gui/qml/components/Slider.qml (.../Slider.qml) (revision ccb91da4becded9a7ad409b758bba96784d9feba) +++ 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,16 +36,58 @@ 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 + signal progressRectClicked() 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 @@ -64,7 +106,7 @@ onIsActiveChanged: { setActive(isActive) if (!isActive) { - value = minimum + value = inActiveZero ? 0 : minimum } activeChanged() } @@ -102,24 +144,48 @@ 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() { + if ( _progressRect.width <= 0 ) { + _handler.x = 0 - _root.tickMarksThickness + } else + if ( _progressRect.width >= _root.width - _root.tickMarksThickness ) { + _handler.x = _root.width - _handler.width + _root.tickMarksThickness + } + else { + _handler.x = _progressRect.width - _handler.width / 2 + } + } + ProgressRect { id: _progressRect color : Colors.highlightProgressBar decimal : _root.decimal @@ -143,6 +209,10 @@ setValue(vMouseEvent.x) _root.released(vMouseEvent) } + onWidthChanged: { + // TODO: DEN-5603 : Still has some issues on high resolution sliders [ handler jumps to the 0 ]. + // setHandlerPosition() + } } // used loader for performance since it may not always be required. @@ -151,6 +221,7 @@ active : ticks anchors.fill : parent sourceComponent : TickMarks { + thickness : _root.tickMarksThickness decimal : _root.decimal minimum : _root.minimum maximum : _root.maximum @@ -184,8 +255,8 @@ radius : diameter color : Colors.highlightProgressBar border { - width: 4 - color: "white" + width: Variables.progressbarHandlerBorderWidth + color: Colors.textMain } } }