diff options
| author | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-11-16 18:20:19 +0100 |
|---|---|---|
| committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-12-10 03:13:57 +0100 |
| commit | 7867a683fcb938939fb2837a26ac8e1941e3fe08 (patch) | |
| tree | 271faa101a68abdd55c5c88146ee8bc223a413a8 /src/quick/doc/snippets/pointerHandlers | |
| parent | f064497bd5021e5d28266cabbb703d548f6961b0 (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/doc/snippets/pointerHandlers')
| -rw-r--r-- | src/quick/doc/snippets/pointerHandlers/pinchHandlerAxisValueDeltas.qml | 29 | ||||
| -rw-r--r-- | src/quick/doc/snippets/pointerHandlers/rotateViaWheelOrDrag.qml | 32 |
2 files changed, 61 insertions, 0 deletions
diff --git a/src/quick/doc/snippets/pointerHandlers/pinchHandlerAxisValueDeltas.qml b/src/quick/doc/snippets/pointerHandlers/pinchHandlerAxisValueDeltas.qml new file mode 100644 index 0000000000..24d20537a3 --- /dev/null +++ b/src/quick/doc/snippets/pointerHandlers/pinchHandlerAxisValueDeltas.qml @@ -0,0 +1,29 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +//![0] +import QtQuick + +Rectangle { + width: 100; height: 100 + color: "lightsteelblue"; antialiasing: true + + PinchHandler { + id: handler + target: null + xAxis.onActiveValueChanged: (delta) => parent.radius -= delta + yAxis.onActiveValueChanged: (delta) => parent.border.width += delta + rotationAxis.onActiveValueChanged: (delta) => parent.rotation += delta // add + scaleAxis.onActiveValueChanged: (delta) => parent.scale *= delta // multiply + } + + WheelHandler { + acceptedModifiers: Qt.NoModifier + property: "rotation" + } + + WheelHandler { + acceptedModifiers: Qt.ControlModifier + property: "scale" + } +} +//![0] diff --git a/src/quick/doc/snippets/pointerHandlers/rotateViaWheelOrDrag.qml b/src/quick/doc/snippets/pointerHandlers/rotateViaWheelOrDrag.qml new file mode 100644 index 0000000000..721a038e5f --- /dev/null +++ b/src/quick/doc/snippets/pointerHandlers/rotateViaWheelOrDrag.qml @@ -0,0 +1,32 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +//![0] +import QtQuick + +Rectangle { + width: 50; height: 200 + + Rectangle { + id: knob + width: parent.width; height: width; radius: width / 2 + anchors.centerIn: parent + color: "lightsteelblue" + + Rectangle { + antialiasing: true + width: 4; height: 20 + x: parent.width / 2 - 2 + } + + WheelHandler { + property: "rotation" + } + } + + DragHandler { + target: null + dragThreshold: 0 + yAxis.onActiveValueChanged: (delta)=> { knob.rotation -= delta } + } +} +//![0] |
