From 98a65a9c74e148758be1619b1fd3844f3f31c789 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 5 Apr 2018 11:25:43 +0200 Subject: RangeSlider: add valueAt() function This is necessary to e.g. show up-to-date values in tooltips for each handle when live is set to false. It's copied from Slider. [ChangeLog][Controls][RangeSlider] Added a valueAt() function to allow accessing each handle's value when the live property is set to false. Task-number: QTBUG-67317 Change-Id: I8d0ca1a914f983b6b950ece759a102c05c5dd2f0 Reviewed-by: J-P Nurmi --- src/quicktemplates2/qquickrangeslider.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/quicktemplates2/qquickrangeslider.cpp') diff --git a/src/quicktemplates2/qquickrangeslider.cpp b/src/quicktemplates2/qquickrangeslider.cpp index 075147a1..5b282f2c 100644 --- a/src/quicktemplates2/qquickrangeslider.cpp +++ b/src/quicktemplates2/qquickrangeslider.cpp @@ -688,6 +688,23 @@ void QQuickRangeSlider::resetTouchDragThreshold() setTouchDragThreshold(-1); } +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlmethod real QtQuick.Controls::RangeSlider::valueAt(real position) + + Returns the value for the given \a position. + + \sa first.value, second.value, first.position, second.position, live +*/ +qreal QQuickRangeSlider::valueAt(qreal position) const +{ + Q_D(const QQuickRangeSlider); + const qreal value = (d->to - d->from) * position; + if (qFuzzyIsNull(d->stepSize)) + return d->from + value; + return d->from + qRound(value / d->stepSize) * d->stepSize; +} + /*! \qmlpropertygroup QtQuick.Controls::RangeSlider::first \qmlproperty real QtQuick.Controls::RangeSlider::first.value -- cgit v1.2.3