aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickrangeslider.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-04-04 08:56:17 +0200
committerMitch Curtis <mitch.curtis@qt.io>2018-04-05 09:12:02 +0000
commit583b7b0324a03337b8f21b5c2eacb6657c16ade7 (patch)
tree1f419c1de9c129e8b5120a97d5a11b2870854edc /src/quicktemplates2/qquickrangeslider.cpp
parent449ebc4fbc26db7b8ef4091f780163e3045b97c7 (diff)
RangeSlider: add first.moved() and second.moved() signals
This is necessary to respond to changes in values, as the documentation currently advises using onValuedChanged, which can result in binding loop errors and is generally not the right way to respond to input changes. [ChangeLog][Controls][RangeSlider] Added a moved() signal to each handle (similar to the Slider's moved() signal) to react to the values being interactively changed by the user. Task-number: QTBUG-67311 Change-Id: I4a026042855c69f22755415031bac8833cd566a9 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickrangeslider.cpp')
-rw-r--r--src/quicktemplates2/qquickrangeslider.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickrangeslider.cpp b/src/quicktemplates2/qquickrangeslider.cpp
index a33bddc5..075147a1 100644
--- a/src/quicktemplates2/qquickrangeslider.cpp
+++ b/src/quicktemplates2/qquickrangeslider.cpp
@@ -74,7 +74,7 @@ QT_BEGIN_NAMESPACE
use the following syntax:
\code
- first.onValueChanged: console.log("first.value changed to " + first.value)
+ first.onMoved: console.log("first.value changed to " + first.value)
\endcode
The \l {first.position} and \l {second.position} properties are expressed as
@@ -522,6 +522,7 @@ void QQuickRangeSliderPrivate::handleMove(const QPointF &point)
QQuickControlPrivate::handleMove(point);
QQuickRangeSliderNode *pressedNode = QQuickRangeSliderPrivate::pressedNode(touchId);
if (pressedNode) {
+ const qreal oldPos = pressedNode->position();
qreal pos = positionAt(q, pressedNode->handle(), point);
if (snapMode == QQuickRangeSlider::SnapAlways)
pos = snapPosition(q, pos);
@@ -529,6 +530,9 @@ void QQuickRangeSliderPrivate::handleMove(const QPointF &point)
pressedNode->setValue(valueAt(q, pos));
else
QQuickRangeSliderNodePrivate::get(pressedNode)->setPosition(pos);
+
+ if (!qFuzzyCompare(pressedNode->position(), oldPos))
+ emit pressedNode->moved();
}
}
@@ -544,6 +548,7 @@ void QQuickRangeSliderPrivate::handleRelease(const QPointF &point)
QQuickRangeSliderNodePrivate *pressedNodePrivate = QQuickRangeSliderNodePrivate::get(pressedNode);
if (q->keepMouseGrab() || q->keepTouchGrab()) {
+ const qreal oldPos = pressedNode->position();
qreal pos = positionAt(q, pressedNode->handle(), point);
if (snapMode != QQuickRangeSlider::NoSnap)
pos = snapPosition(q, pos);
@@ -554,6 +559,9 @@ void QQuickRangeSliderPrivate::handleRelease(const QPointF &point)
pressedNodePrivate->setPosition(pos);
q->setKeepMouseGrab(false);
q->setKeepTouchGrab(false);
+
+ if (!qFuzzyCompare(pressedNode->position(), oldPos))
+ emit pressedNode->moved();
}
pressedNode->setPressed(false);
pressedNodePrivate->touchId = -1;
@@ -688,6 +696,7 @@ void QQuickRangeSlider::resetTouchDragThreshold()
\qmlproperty Item QtQuick.Controls::RangeSlider::first.handle
\qmlproperty bool QtQuick.Controls::RangeSlider::first.pressed
\qmlproperty bool QtQuick.Controls::RangeSlider::first.hovered
+ \qmlsignal void QtQuick.Controls::RangeSlider::moved()
\table
\header
@@ -727,6 +736,12 @@ void QQuickRangeSlider::resetTouchDragThreshold()
\li hovered
\li This property holds whether the first handle is hovered.
This property was introduced in QtQuick.Controls 2.1.
+ \row
+ \li moved()
+ \li This signal is emitted when the first handle has been interactively moved
+ by the user by either touch, mouse, or keys.
+
+ This signal was introduced in QtQuick.Controls 2.5.
\endtable
\sa first.increase(), first.decrease()
@@ -745,6 +760,7 @@ QQuickRangeSliderNode *QQuickRangeSlider::first() const
\qmlproperty Item QtQuick.Controls::RangeSlider::second.handle
\qmlproperty bool QtQuick.Controls::RangeSlider::second.pressed
\qmlproperty bool QtQuick.Controls::RangeSlider::second.hovered
+ \qmlsignal void QtQuick.Controls::RangeSlider::moved()
\table
\header
@@ -784,6 +800,12 @@ QQuickRangeSliderNode *QQuickRangeSlider::first() const
\li hovered
\li This property holds whether the second handle is hovered.
This property was introduced in QtQuick.Controls 2.1.
+ \row
+ \li moved()
+ \li This signal is emitted when the second handle has been interactively moved
+ by the user by either touch, mouse, or keys.
+
+ This signal was introduced in QtQuick.Controls 2.5.
\endtable
\sa second.increase(), second.decrease()
@@ -1017,6 +1039,7 @@ void QQuickRangeSlider::keyPressEvent(QKeyEvent *event)
if (!focusNode)
return;
+ const qreal oldValue = focusNode->value();
if (d->orientation == Qt::Horizontal) {
if (event->key() == Qt::Key_Left) {
focusNode->setPressed(true);
@@ -1044,6 +1067,8 @@ void QQuickRangeSlider::keyPressEvent(QKeyEvent *event)
event->accept();
}
}
+ if (!qFuzzyCompare(focusNode->value(), oldValue))
+ emit focusNode->moved();
}
void QQuickRangeSlider::hoverEnterEvent(QHoverEvent *event)