qtdeclarative/examples/quick/pointerhandlers/components/LeftDrawer.qml

77 lines
1.8 KiB
QML
Raw Normal View History

// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import Qt.labs.animation
Item {
id: root
objectName: "LeftHandlerDrawer"
width: 100
height: 400
property real stickout: 4
property real xOpen: rect.radius * -2
property real xClosed: stickout - width
x: xClosed
y: 10
function close() {
openCloseAnimation.to = xClosed
openCloseAnimation.start()
}
function open() {
openCloseAnimation.to = xOpen
openCloseAnimation.start()
}
DragHandler {
id: dragHandler
yAxis.enabled: false
xAxis.minimum: -1000
margin: 20
onActiveChanged:
if (!active) {
if (xbr.returnToBounds())
return;
Add DragHandler.activeTranslation and persistentTranslation If you want to set target: null and then bind translation to some object's x and y properties directly (perhaps an Item, a Qt Quick 3D Model object, etc.), it's a lot less trouble to use a translation property that does not keep changing back to 0,0 every time a gesture begins. In hindsight, the translation property should have been the persistent one (for consistency with the fix for QTBUG-68941, in which we made PinchHandler.scale persistent and added activeScale: b4d31c9ff5f0c5821ea127c663532d9fc2cae43e). But for several years, the translation property has been restarting with each gesture; so now we add a persistentTranslation property. The new activeTranslation property has the same value as the translation property (which is deprecated). Also, the persistentTranslation property is settable, because in some UIs there may be multiple ways to move the same object, and there needs to be a way to sync them up. Also fixed a bug: when minimumPointCount == 2, QQuickMultiPointHandler::wantsPointerEvent() doesn't initialize d->currentPoints until two points are pressed. But often, one point is pressed, and in the next event, the second point is pressed while the first is held Stationary. So QQuickHandlerPoint::reset() needs to set pressPosition and scenePressPosition on both points at the same time, because it is called on each HandlerPoint in d->currentPoints at that time when both points are pressed. So if any point is pressed, act as if they all were freshly pressed. Without this fix, the centroid's scenePressPosition is wrong (based on the average of 0,0 and the second point), therefore a "jump" was occurring when persistentTranslation is used to directly drive a binding (like the tilt in map.qml). [ChangeLog][QtQuick][Event Handlers] DragHandler.activeTranslation now holds the amount of movement since the drag gesture began. DragHandler.persistentTranslation holds the accumulated sum of movement that has occurred during subsequent drag gestures, and can be set to arbitrary values between gestures. Task-number: QTBUG-94168 Change-Id: I1b2f8ea31d0f6ff55ccffe393bc9ba28c1a71d09 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
2021-06-02 15:31:25 +00:00
if (activeTranslation.x > 0)
open()
Add DragHandler.activeTranslation and persistentTranslation If you want to set target: null and then bind translation to some object's x and y properties directly (perhaps an Item, a Qt Quick 3D Model object, etc.), it's a lot less trouble to use a translation property that does not keep changing back to 0,0 every time a gesture begins. In hindsight, the translation property should have been the persistent one (for consistency with the fix for QTBUG-68941, in which we made PinchHandler.scale persistent and added activeScale: b4d31c9ff5f0c5821ea127c663532d9fc2cae43e). But for several years, the translation property has been restarting with each gesture; so now we add a persistentTranslation property. The new activeTranslation property has the same value as the translation property (which is deprecated). Also, the persistentTranslation property is settable, because in some UIs there may be multiple ways to move the same object, and there needs to be a way to sync them up. Also fixed a bug: when minimumPointCount == 2, QQuickMultiPointHandler::wantsPointerEvent() doesn't initialize d->currentPoints until two points are pressed. But often, one point is pressed, and in the next event, the second point is pressed while the first is held Stationary. So QQuickHandlerPoint::reset() needs to set pressPosition and scenePressPosition on both points at the same time, because it is called on each HandlerPoint in d->currentPoints at that time when both points are pressed. So if any point is pressed, act as if they all were freshly pressed. Without this fix, the centroid's scenePressPosition is wrong (based on the average of 0,0 and the second point), therefore a "jump" was occurring when persistentTranslation is used to directly drive a binding (like the tilt in map.qml). [ChangeLog][QtQuick][Event Handlers] DragHandler.activeTranslation now holds the amount of movement since the drag gesture began. DragHandler.persistentTranslation holds the accumulated sum of movement that has occurred during subsequent drag gestures, and can be set to arbitrary values between gestures. Task-number: QTBUG-94168 Change-Id: I1b2f8ea31d0f6ff55ccffe393bc9ba28c1a71d09 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
2021-06-02 15:31:25 +00:00
if (activeTranslation.x < 0)
close()
}
}
BoundaryRule on x {
id: xbr
minimum: xClosed
maximum: xOpen
minimumOvershoot: rect.radius
maximumOvershoot: rect.radius
}
NumberAnimation on x {
id: openCloseAnimation
duration: 300
easing { type: Easing.OutBounce; overshoot: 5 }
}
// TODO this was supposed to be RectangularGlow but we lost QtGraphicalEffects in Qt 6
Rectangle {
id: effect
anchors.fill: parent
border.width: dragHandler.margin
border.color: "cyan"
opacity: 0.2
radius: rect.radius + dragHandler.margin
}
Rectangle {
id: rect
anchors.fill: parent
anchors.margins: 3
color: "#333"
border.color: "cyan"
border.width: 2
radius: 10
antialiasing: true
}
}