aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/handlers/qquickdraghandler.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-11-16 18:20:19 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2022-12-10 03:13:57 +0100
commit7867a683fcb938939fb2837a26ac8e1941e3fe08 (patch)
tree271faa101a68abdd55c5c88146ee8bc223a413a8 /src/quick/handlers/qquickdraghandler.cpp
parentf064497bd5021e5d28266cabbb703d548f6961b0 (diff)
Add PinchHandler.scaleAxis, rotationAxis; hold values in axes
Pointer Handlers that manipulate target item properties should now use QQuickDragAxis consistently to: - enforce minimum and maximum values - hold the persistent and active values - make those available via properties - emit a new activeValueChanged(delta) signal when the value changes, so that it's possible to incrementally update a target item property in JS (onValueDelta: target.property += delta) In the pinchHandler.qml example, you can use the PinchHandler to adjust 4 properties of one Rectangle independently (it requires coordination). m_boundedActiveValue controls whether m_activeValue will be kept between minimum and maximum. For rotation, tst_QQuickPinchHandler::scaleNativeGesture() expects it to be, although that seems questionable now, and may be addressed later. [ChangeLog][QtQuick][Event Handlers] PinchHandler now has scaleAxis and rotationAxis grouped properties, alongside the existing xAxis and yAxis; and all of these now have activeValue and persistentValue properties. The activeValueChanged signal includes a delta value, giving the incremental change since the previous activeValue. The persistentValue is settable, in case some target item property can be adjusted in multiple ways: the handler's stored value can then be synced up with the item property value after each external change. These features are also added to DragHandler's xAxis and yAxis properties. Task-number: QTBUG-68108 Task-number: QTBUG-76380 Task-number: QTBUG-76379 Task-number: QTBUG-94168 Change-Id: I78a5b43e9ba580448ef05054b6c4bc71b1834dd6 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/quick/handlers/qquickdraghandler.cpp')
-rw-r--r--src/quick/handlers/qquickdraghandler.cpp45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/quick/handlers/qquickdraghandler.cpp b/src/quick/handlers/qquickdraghandler.cpp
index c31eb13d98..b34ca0e7cf 100644
--- a/src/quick/handlers/qquickdraghandler.cpp
+++ b/src/quick/handlers/qquickdraghandler.cpp
@@ -120,7 +120,10 @@ void QQuickDragHandler::setSnapMode(QQuickDragHandler::SnapMode mode)
void QQuickDragHandler::onActiveChanged()
{
QQuickMultiPointHandler::onActiveChanged();
- if (active()) {
+ const bool curActive = active();
+ m_xAxis.onActiveChanged(curActive, 0);
+ m_yAxis.onActiveChanged(curActive, 0);
+ if (curActive) {
if (auto parent = parentItem()) {
if (QQuickDeliveryAgentPrivate::isTouchEvent(currentEvent()))
parent->setKeepTouchGrab(true);
@@ -129,7 +132,6 @@ void QQuickDragHandler::onActiveChanged()
// mouse grab too, whenever dragging occurs in an enabled direction
parent->setKeepMouseGrab(true);
}
- m_startTranslation = m_persistentTranslation;
} else {
m_pressTargetPos = QPointF();
m_pressedInsideTarget = false;
@@ -283,22 +285,25 @@ void QQuickDragHandler::enforceAxisConstraints(QPointF *localPos)
void QQuickDragHandler::setPersistentTranslation(const QVector2D &trans)
{
- if (trans == m_persistentTranslation)
+ if (trans == persistentTranslation())
return;
- m_persistentTranslation = trans;
+ m_xAxis.updateValue(m_xAxis.activeValue(), trans.x());
+ m_yAxis.updateValue(m_yAxis.activeValue(), trans.y());
emit translationChanged();
}
void QQuickDragHandler::setActiveTranslation(const QVector2D &trans)
{
- if (trans == m_activeTranslation)
+ if (trans == activeTranslation())
return;
- m_activeTranslation = trans;
- m_persistentTranslation = m_startTranslation + trans;
- qCDebug(lcDragHandler) << "translation: start" << m_startTranslation
- << "active" << m_activeTranslation << "accumulated" << m_persistentTranslation;
+ const QVector2D delta = trans - activeTranslation();
+ m_xAxis.updateValue(trans.x(), m_xAxis.persistentValue() + delta.x(), delta.x());
+ m_yAxis.updateValue(trans.y(), m_yAxis.persistentValue() + delta.y(), delta.y());
+
+ qCDebug(lcDragHandler) << "translation: delta" << delta
+ << "active" << trans << "accumulated" << persistentTranslation();
emit translationChanged();
}
@@ -307,6 +312,8 @@ void QQuickDragHandler::setActiveTranslation(const QVector2D &trans)
\qmlproperty real QtQuick::DragHandler::xAxis.minimum
\qmlproperty real QtQuick::DragHandler::xAxis.maximum
\qmlproperty bool QtQuick::DragHandler::xAxis.enabled
+ \qmlproperty real QtQuick::DragHandler::xAxis.activeValue
+ \qmlproperty real QtQuick::DragHandler::xAxis.persistentValue
\c xAxis controls the constraints for horizontal dragging.
@@ -315,13 +322,21 @@ void QQuickDragHandler::setActiveTranslation(const QVector2D &trans)
\c maximum is the maximum acceptable value of \l {Item::x}{x} to be
applied to the \l {PointerHandler::target} {target}.
If \c enabled is true, horizontal dragging is allowed.
- */
+ \c activeValue is the same as \l {QtQuick::DragHandler::activeTranslation}{activeTranslation.x}.
+ \c persistentValue is the same as \l {QtQuick::DragHandler::persistentTranslation}{persistentTranslation.x}.
+
+ The \c activeValueChanged signal is emitted when \c activeValue (and therefore
+ \c persistentValue) changes, to provide the increment by which it changed.
+ This is intended for incrementally adjusting one property via multiple handlers.
+*/
/*!
\qmlpropertygroup QtQuick::DragHandler::yAxis
\qmlproperty real QtQuick::DragHandler::yAxis.minimum
\qmlproperty real QtQuick::DragHandler::yAxis.maximum
\qmlproperty bool QtQuick::DragHandler::yAxis.enabled
+ \qmlproperty real QtQuick::DragHandler::yAxis.activeValue
+ \qmlproperty real QtQuick::DragHandler::yAxis.persistentValue
\c yAxis controls the constraints for vertical dragging.
@@ -330,7 +345,15 @@ void QQuickDragHandler::setActiveTranslation(const QVector2D &trans)
\c maximum is the maximum acceptable value of \l {Item::y}{y} to be
applied to the \l {PointerHandler::target} {target}.
If \c enabled is true, vertical dragging is allowed.
- */
+ \c activeValue is the same as \l {QtQuick::DragHandler::activeTranslation}{activeTranslation.y}.
+ \c persistentValue is the same as \l {QtQuick::DragHandler::persistentTranslation}{persistentTranslation.y}.
+
+ The \c activeValueChanged signal is emitted when \c activeValue (and therefore
+ \c persistentValue) changes, to provide the increment by which it changed.
+ This is intended for incrementally adjusting one property via multiple handlers:
+
+ \snippet pointerHandlers/rotateViaWheelOrDrag.qml 0
+*/
/*!
\readonly