Debian Codegraph @

tests/manual/planets-qml/AppleTVInput.qml

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 import QtQuick 2.7
5 import QtQuick.Window 2.2
6
7 Item {
8 id: appleTVInput
9
10 property real xThreshold: 500
11 property real yThreshold: 300
12
13 signal swipeLeft()
14 signal swipeRight()
15 signal swipeUp()
16 signal swipeDown()
17
18 onSwipeLeft: {
19 var focusedItem = Window.window.activeFocusItem
20 if (typeof(focusedItem.swipeLeft) === "function") {
21 focusedItem.swipeLeft()
22 }
23 }
24
25 onSwipeRight: {
26 var focusedItem = Window.window.activeFocusItem
27 if (typeof(focusedItem.swipeRight) === "function") {
28 focusedItem.swipeRight()
29 }
30 }
31
32 onSwipeUp: {
33 var focusedItem = Window.window.activeFocusItem
34 if (typeof(focusedItem.swipeUp) === "function") {
35 focusedItem.swipeUp()
36 }
37 }
38
39 onSwipeDown: {
40 var focusedItem = Window.window.activeFocusItem
41 if (typeof(focusedItem.swipeDown) === "function") {
42 focusedItem.swipeDown()
43 }
44 }
45
46 MultiPointTouchArea {
47 id: multiPointTouchArea
48
49 anchors.fill: parent
50
51 property int startX: 0
52 property int startY: 0
53
54 property int pointX: 0
55 property int pointY: 0
56
57 property int xIsIncreasing: -1 // 1 - true, 0 - false, -1 - undefined
58 property int yIsIncreasing: -1 // 1 - true, 0 - false, -1 - undefined
59
60 property bool pressed: false
61
62 touchPoints: [
63 TouchPoint {
64
65 onPressedChanged: {
66 if (pressed) {
67 multiPointTouchArea.startX = x
68 multiPointTouchArea.startY = y
69 multiPointTouchArea.pressed = true
70 } else {
71 multiPointTouchArea.pressed = false
72 multiPointTouchArea.xIsIncreasing = -1
73 multiPointTouchArea.yIsIncreasing = -1
74 multiPointTouchArea.startX = 0
75 multiPointTouchArea.startY = 0
76 }
77 }
78
79 onXChanged: {
80 if (multiPointTouchArea.pressed) {
81 var newValue = x - multiPointTouchArea.startX
82
83 var focusedItem = appleTVInput.Window.window.activeFocusItem
84
85 if (focusedItem.panningEnabled) {
86 if (multiPointTouchArea.xIsIncreasing === -1) {
87 multiPointTouchArea.xIsIncreasing = (newValue > multiPointTouchArea.startX) ? 1 : 0
88 } else {
89 if (multiPointTouchArea.xIsIncreasing === 1 && newValue < multiPointTouchArea.pointX) {
90 multiPointTouchArea.startX = x
91 multiPointTouchArea.xIsIncreasing = 0
92 multiPointTouchArea.pointX = newValue
93 } else if (multiPointTouchArea.xIsIncreasing === 0 && newValue > multiPointTouchArea.pointX) {
94 multiPointTouchArea.startX = x
95 multiPointTouchArea.xIsIncreasing = 1
96 multiPointTouchArea.pointX = newValue
97 } else {
98 multiPointTouchArea.pointX = newValue
99 focusedItem.pannedHorizontally(multiPointTouchArea.pointX / (multiPointTouchArea.width / 2))
100 }
101 }
102 } else {
103 multiPointTouchArea.pointX = newValue
104
105 if (multiPointTouchArea.pointX > xThreshold) {
106 multiPointTouchArea.startX = x
107 swipeRight()
108 } else if (multiPointTouchArea.pointX < -xThreshold) {
109 multiPointTouchArea.startX = x
110 swipeLeft()
111 }
112 }
113 }
114 }
115
116 onYChanged: {
117 if (multiPointTouchArea.pressed) {
118 var newValue = multiPointTouchArea.startY - y
119
120 var focusedItem = appleTVInput.Window.window.activeFocusItem
121
122 if (focusedItem.panningEnabled) {
123 if (multiPointTouchArea.yIsIncreasing === -1) {
124 multiPointTouchArea.yIsIncreasing = (newValue > multiPointTouchArea.startY) ? 1 : 0
125 } else {
126 if (multiPointTouchArea.yIsIncreasing === 1 && newValue < multiPointTouchArea.pointY) {
127 multiPointTouchArea.startY = y
128 multiPointTouchArea.yIsIncreasing = 0
129 multiPointTouchArea.pointY = newValue
130 } else if (multiPointTouchArea.yIsIncreasing === 0 && newValue > multiPointTouchArea.pointY) {
131 multiPointTouchArea.startY = y
132 multiPointTouchArea.yIsIncreasing = 1
133 multiPointTouchArea.pointY = newValue
134 } else {
135 multiPointTouchArea.pointY = newValue
136 focusedItem.pannedVertically(multiPointTouchArea.pointY / (multiPointTouchArea.height / 2))
137 }
138 }
139 } else {
140 multiPointTouchArea.pointY = newValue
141
142 if (multiPointTouchArea.pointY > yThreshold) {
143 multiPointTouchArea.startY = y
144 swipeUp()
145 } else if (multiPointTouchArea.pointY < -yThreshold) {
146 multiPointTouchArea.startY = y
147 swipeDown()
148 }
149 }
150 }
151 }
152 }
153 ]
154 }
155 }