Debian Codegraph @

tests/manual/pointer/content/FakeFlickable.qml

raw
1 /****************************************************************************
2 **
3 ** Copyright (C) 2019 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the manual tests of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28
29 import QtQuick 2.14
30 import Qt.labs.animation 1.0
31
32 Item {
33 id: root
34 objectName: "viewport"
35 default property alias data: __contentItem.data
36 property alias velocity: anim.velocity
37 property alias contentX: __contentItem.x // sign is reversed compared to Flickable.contentX
38 property alias contentY: __contentItem.y // sign is reversed compared to Flickable.contentY
39 property alias contentWidth: __contentItem.width
40 property alias contentHeight: __contentItem.height
41 signal flickStarted
42 signal flickEnded
43
44 Item {
45 id: __contentItem
46 objectName: "__contentItem"
47 width: childrenRect.width
48 height: childrenRect.height
49
50 BoundaryRule on x {
51 id: xbr
52 minimum: root.width - __contentItem.width
53 maximum: 0
54 minimumOvershoot: 100
55 maximumOvershoot: 100
56 overshootFilter: BoundaryRule.Peak
57 }
58
59 BoundaryRule on y {
60 id: ybr
61 minimum: root.height - __contentItem.height
62 maximum: 0
63 minimumOvershoot: 100
64 maximumOvershoot: 100
65 overshootFilter: BoundaryRule.Peak
66 }
67
68 DragHandler {
69 id: dragHandler
70 onActiveChanged:
71 if (active) {
72 anim.stop()
73 root.flickStarted()
74 } else {
75 var vel = centroid.velocity
76 if (xbr.returnToBounds())
77 vel.x = 0
78 if (ybr.returnToBounds())
79 vel.y = 0
80 if (vel.x !== 0 || vel.y !== 0)
81 anim.restart(vel)
82 else
83 root.flickEnded()
84 }
85 }
86 WheelHandler {
87 rotationScale: 15
88 property: "x"
89 orientation: Qt.Horizontal
90 acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
91 onActiveChanged:
92 // emitting signals in both instances is redundant but hard to avoid
93 // when the touchpad is flicking along both axes
94 if (active) {
95 anim.stop()
96 root.flickStarted()
97 } else {
98 xbr.returnToBounds()
99 root.flickEnded()
100 }
101 }
102 WheelHandler {
103 rotationScale: 15
104 property: "y"
105 orientation: Qt.Vertical
106 acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
107 onActiveChanged:
108 if (active) {
109 anim.stop()
110 root.flickStarted()
111 } else {
112 ybr.returnToBounds()
113 root.flickEnded()
114 }
115 }
116 MomentumAnimation {
117 id: anim
118 target: __contentItem
119 onStarted: root.flickStarted()
120 onStopped: {
121 xbr.returnToBounds()
122 ybr.returnToBounds()
123 root.flickEnded()
124 }
125 }
126 }
127 }