2019-04-05 20:58:12 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2021-08-17 12:03:47 +00:00
|
|
|
** Copyright (C) 2021 The Qt Company Ltd.
|
2019-04-05 20:58:12 +00:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
**
|
2021-09-06 19:40:18 +00:00
|
|
|
** This file is part of the examples of the Qt Toolkit.
|
2019-04-05 20:58:12 +00:00
|
|
|
**
|
2021-09-06 19:40:18 +00:00
|
|
|
** $QT_BEGIN_LICENSE:BSD$
|
2019-04-05 20:58:12 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
2021-09-06 19:40:18 +00:00
|
|
|
** BSD License Usage
|
|
|
|
** Alternatively, you may use this file under the terms of the BSD license
|
|
|
|
** as follows:
|
|
|
|
**
|
|
|
|
** "Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions are
|
|
|
|
** met:
|
|
|
|
** * Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** * Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in
|
|
|
|
** the documentation and/or other materials provided with the
|
|
|
|
** distribution.
|
|
|
|
** * Neither the name of The Qt Company Ltd nor the names of its
|
|
|
|
** contributors may be used to endorse or promote products derived
|
|
|
|
** from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
2019-04-05 20:58:12 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
2021-08-17 12:03:47 +00:00
|
|
|
import QtQuick
|
|
|
|
import Qt.labs.animation
|
2019-04-05 20:58:12 +00:00
|
|
|
|
|
|
|
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)
|
2019-04-05 20:58:12 +00:00
|
|
|
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)
|
2019-04-05 20:58:12 +00:00
|
|
|
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 }
|
|
|
|
}
|
|
|
|
|
2021-08-17 12:03:47 +00:00
|
|
|
// TODO this was supposed to be RectangularGlow but we lost QtGraphicalEffects in Qt 6
|
|
|
|
Rectangle {
|
2019-04-05 20:58:12 +00:00
|
|
|
id: effect
|
|
|
|
anchors.fill: parent
|
2021-08-17 12:03:47 +00:00
|
|
|
border.width: dragHandler.margin
|
|
|
|
border.color: "cyan"
|
|
|
|
opacity: 0.2
|
|
|
|
radius: rect.radius + dragHandler.margin
|
2019-04-05 20:58:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: rect
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: 3
|
|
|
|
color: "#333"
|
|
|
|
border.color: "cyan"
|
|
|
|
border.width: 2
|
|
|
|
radius: 10
|
|
|
|
antialiasing: true
|
|
|
|
}
|
|
|
|
}
|