Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4// This file is included from qnsview.mm, and only used to organize the code
5
6#ifndef QT_NO_GESTURES
7
8Q_LOGGING_CATEGORY(lcQpaGestures, "qt.qpa.input.gestures")
9
10@implementation QNSView (Gestures)
11
12- (bool)handleGestureAsBeginEnd:(NSEvent *)event
13{
15 return false;
16
17 if ([event phase] == NSEventPhaseBegan) {
18 [self beginGestureWithEvent:event];
19 return true;
20 }
21
22 if ([event phase] == NSEventPhaseEnded) {
23 [self endGestureWithEvent:event];
24 return true;
25 }
26
27 return false;
28}
29- (void)magnifyWithEvent:(NSEvent *)event
30{
31 if (!m_platformWindow)
32 return;
33
34 if ([self handleGestureAsBeginEnd:event])
35 return;
36
37 qCDebug(lcQpaGestures) << "magnifyWithEvent" << [event magnification] << "from device" << Qt::hex << [event deviceID];
38 const NSTimeInterval timestamp = [event timestamp];
39 QPointF windowPoint;
40 QPointF screenPoint;
41 [self convertFromScreen:[self screenMousePoint:event] toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
42 QWindowSystemInterface::handleGestureEventWithRealValue(m_platformWindow->window(), timestamp,
44 Qt::ZoomNativeGesture, [event magnification], windowPoint, screenPoint);
45}
46
47- (void)smartMagnifyWithEvent:(NSEvent *)event
48{
49 if (!m_platformWindow)
50 return;
51
52 static bool zoomIn = true;
53 qCDebug(lcQpaGestures) << "smartMagnifyWithEvent" << zoomIn << "from device" << Qt::hex << [event deviceID];
54 const NSTimeInterval timestamp = [event timestamp];
55 QPointF windowPoint;
56 QPointF screenPoint;
57 [self convertFromScreen:[self screenMousePoint:event] toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
58 QWindowSystemInterface::handleGestureEventWithRealValue(m_platformWindow->window(), timestamp,
60 Qt::SmartZoomNativeGesture, zoomIn ? 1.0f : 0.0f, windowPoint, screenPoint);
61 zoomIn = !zoomIn;
62}
63
64- (void)rotateWithEvent:(NSEvent *)event
65{
66 if (!m_platformWindow)
67 return;
68
69 if ([self handleGestureAsBeginEnd:event])
70 return;
71
72 const NSTimeInterval timestamp = [event timestamp];
73 QPointF windowPoint;
74 QPointF screenPoint;
75 [self convertFromScreen:[self screenMousePoint:event] toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
76 QWindowSystemInterface::handleGestureEventWithRealValue(m_platformWindow->window(), timestamp,
78 Qt::RotateNativeGesture, -[event rotation], windowPoint, screenPoint);
79}
80
81- (void)swipeWithEvent:(NSEvent *)event
82{
83 if (!m_platformWindow)
84 return;
85
86 qCDebug(lcQpaGestures) << "swipeWithEvent" << [event deltaX] << [event deltaY] << "from device" << Qt::hex << [event deviceID];
87 const NSTimeInterval timestamp = [event timestamp];
88 QPointF windowPoint;
89 QPointF screenPoint;
90 [self convertFromScreen:[self screenMousePoint:event] toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
91
92 qreal angle = 0.0f;
93 if ([event deltaX] == 1)
94 angle = 180.0f;
95 else if ([event deltaX] == -1)
96 angle = 0.0f;
97 else if ([event deltaY] == 1)
98 angle = 90.0f;
99 else if ([event deltaY] == -1)
100 angle = 270.0f;
101
102 QWindowSystemInterface::handleGestureEventWithRealValue(m_platformWindow->window(), timestamp,
104 Qt::SwipeNativeGesture, angle, windowPoint, screenPoint, 3);
105}
106
107- (void)beginGestureWithEvent:(NSEvent *)event
108{
109 if (!m_platformWindow)
110 return;
111
112 const NSTimeInterval timestamp = [event timestamp];
113 QPointF windowPoint;
114 QPointF screenPoint;
115 [self convertFromScreen:[self screenMousePoint:event] toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
116 qCDebug(lcQpaGestures) << "beginGestureWithEvent @" << windowPoint << "from device" << Qt::hex << [event deviceID];
117 QWindowSystemInterface::handleGestureEvent(m_platformWindow->window(), timestamp,
119 Qt::BeginNativeGesture, windowPoint, screenPoint);
120}
121
122- (void)endGestureWithEvent:(NSEvent *)event
123{
124 if (!m_platformWindow)
125 return;
126
127 qCDebug(lcQpaGestures) << "endGestureWithEvent" << "from device" << Qt::hex << [event deviceID];
128 const NSTimeInterval timestamp = [event timestamp];
129 QPointF windowPoint;
130 QPointF screenPoint;
131 [self convertFromScreen:[self screenMousePoint:event] toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
132 QWindowSystemInterface::handleGestureEvent(m_platformWindow->window(), timestamp,
134 Qt::EndNativeGesture, windowPoint, screenPoint);
135}
136
137@end
138
139#endif // QT_NO_GESTURES
static QPointingDevice * getTouchDevice(QInputDevice::DeviceType type, quint64 id)
static Q_CORE_EXPORT QOperatingSystemVersionBase current()
static constexpr QOperatingSystemVersionBase OSXElCapitan
\variable QOperatingSystemVersion::OSXElCapitan
\inmodule QtCore\reentrant
Definition qpoint.h:217
static bool handleGestureEventWithRealValue(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::NativeGestureType type, qreal value, const QPointF &local, const QPointF &global, int fingerCount=2)
static bool handleGestureEvent(QWindow *window, ulong timestamp, const QPointingDevice *device, Qt::NativeGestureType type, const QPointF &local, const QPointF &global, int fingerCount=0)
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
@ RotateNativeGesture
@ ZoomNativeGesture
@ BeginNativeGesture
@ EndNativeGesture
@ SwipeNativeGesture
@ SmartZoomNativeGesture
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLfloat angle
struct _cl_event * event
double qreal
Definition qtypes.h:187