Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qnsview_gestures.mm
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5// This file is included from qnsview.mm, and only used to organize the code
6
7#ifndef QT_NO_GESTURES
8
9Q_STATIC_LOGGING_CATEGORY(lcQpaGestures, "qt.qpa.input.gestures")
10
11@implementation QNSView (Gestures)
12
13- (bool)handleGestureAsBeginEnd:(NSEvent *)event
14{
15 if ([event phase] == NSEventPhaseBegan) {
16 [self beginGestureWithEvent:event];
17 return true;
18 }
19
20 if ([event phase] == NSEventPhaseEnded) {
21 [self endGestureWithEvent:event];
22 return true;
23 }
24
25 return false;
26}
27- (void)magnifyWithEvent:(NSEvent *)event
28{
29 if (!m_platformWindow)
30 return;
31
32 if ([self handleGestureAsBeginEnd:event])
33 return;
34
35 qCDebug(lcQpaGestures) << "magnifyWithEvent" << [event magnification] << "from device" << Qt::hex << [event deviceID];
36 const NSTimeInterval timestamp = [event timestamp];
37 QPointF windowPoint;
38 QPointF screenPoint;
39 [self convertFromScreen:[self screenMousePoint:event] toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
40 QWindowSystemInterface::handleGestureEventWithRealValue(m_platformWindow->window(), timestamp,
41 QCocoaTouch::getTouchDevice(QInputDevice::DeviceType::TouchPad, [event deviceID]),
42 Qt::ZoomNativeGesture, [event magnification], windowPoint, screenPoint);
43}
44
45- (void)smartMagnifyWithEvent:(NSEvent *)event
46{
47 if (!m_platformWindow)
48 return;
49
50 static bool zoomIn = true;
51 qCDebug(lcQpaGestures) << "smartMagnifyWithEvent" << zoomIn << "from device" << Qt::hex << [event deviceID];
52 const NSTimeInterval timestamp = [event timestamp];
53 QPointF windowPoint;
54 QPointF screenPoint;
55 [self convertFromScreen:[self screenMousePoint:event] toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
56 QWindowSystemInterface::handleGestureEventWithRealValue(m_platformWindow->window(), timestamp,
57 QCocoaTouch::getTouchDevice(QInputDevice::DeviceType::TouchPad, [event deviceID]),
58 Qt::SmartZoomNativeGesture, zoomIn ? 1.0f : 0.0f, windowPoint, screenPoint);
59 zoomIn = !zoomIn;
60}
61
62- (void)rotateWithEvent:(NSEvent *)event
63{
64 if (!m_platformWindow)
65 return;
66
67 if ([self handleGestureAsBeginEnd:event])
68 return;
69
70 const NSTimeInterval timestamp = [event timestamp];
71 QPointF windowPoint;
72 QPointF screenPoint;
73 [self convertFromScreen:[self screenMousePoint:event] toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
74 QWindowSystemInterface::handleGestureEventWithRealValue(m_platformWindow->window(), timestamp,
75 QCocoaTouch::getTouchDevice(QInputDevice::DeviceType::TouchPad, [event deviceID]),
76 Qt::RotateNativeGesture, -[event rotation], windowPoint, screenPoint);
77}
78
79- (void)swipeWithEvent:(NSEvent *)event
80{
81 if (!m_platformWindow)
82 return;
83
84 qCDebug(lcQpaGestures) << "swipeWithEvent" << [event deltaX] << [event deltaY] << "from device" << Qt::hex << [event deviceID];
85 const NSTimeInterval timestamp = [event timestamp];
86 QPointF windowPoint;
87 QPointF screenPoint;
88 [self convertFromScreen:[self screenMousePoint:event] toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
89
90 qreal angle = 0.0f;
91 if ([event deltaX] == 1)
92 angle = 180.0f;
93 else if ([event deltaX] == -1)
94 angle = 0.0f;
95 else if ([event deltaY] == 1)
96 angle = 90.0f;
97 else if ([event deltaY] == -1)
98 angle = 270.0f;
99
100 QWindowSystemInterface::handleGestureEventWithRealValue(m_platformWindow->window(), timestamp,
101 QCocoaTouch::getTouchDevice(QInputDevice::DeviceType::TouchPad, [event deviceID]),
102 Qt::SwipeNativeGesture, angle, windowPoint, screenPoint, 3);
103}
104
105- (void)beginGestureWithEvent:(NSEvent *)event
106{
107 if (!m_platformWindow)
108 return;
109
110 const NSTimeInterval timestamp = [event timestamp];
111 QPointF windowPoint;
112 QPointF screenPoint;
113 [self convertFromScreen:[self screenMousePoint:event] toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
114 qCDebug(lcQpaGestures) << "beginGestureWithEvent @" << windowPoint << "from device" << Qt::hex << [event deviceID];
115 QWindowSystemInterface::handleGestureEvent(m_platformWindow->window(), timestamp,
116 QCocoaTouch::getTouchDevice(QInputDevice::DeviceType::TouchPad, [event deviceID]),
117 Qt::BeginNativeGesture, windowPoint, screenPoint);
118}
119
120- (void)endGestureWithEvent:(NSEvent *)event
121{
122 if (!m_platformWindow)
123 return;
124
125 qCDebug(lcQpaGestures) << "endGestureWithEvent" << "from device" << Qt::hex << [event deviceID];
126 const NSTimeInterval timestamp = [event timestamp];
127 QPointF windowPoint;
128 QPointF screenPoint;
129 [self convertFromScreen:[self screenMousePoint:event] toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
130 QWindowSystemInterface::handleGestureEvent(m_platformWindow->window(), timestamp,
131 QCocoaTouch::getTouchDevice(QInputDevice::DeviceType::TouchPad, [event deviceID]),
132 Qt::EndNativeGesture, windowPoint, screenPoint);
133}
134
135@end
136
137#endif // QT_NO_GESTURES
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")