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