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_touch.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@implementation QNSView (Touch)
8
9- (bool)shouldSendSingleTouch
10{
11 if (!m_platformWindow)
12 return true;
13
14 // QtWidgets expects single-point touch events, QtDeclarative does not.
15 // Until there is an API we solve this by looking at the window class type.
16 return m_platformWindow->window()->inherits("QWidgetWindow");
17}
18
19- (void)touchesBeganWithEvent:(NSEvent *)event
20{
21 if (!m_platformWindow)
22 return;
23
24 const NSTimeInterval timestamp = [event timestamp];
25 const QList<QWindowSystemInterface::TouchPoint> points = QCocoaTouch::getCurrentTouchPointList(event, [self shouldSendSingleTouch]);
26 qCDebug(lcQpaTouch) << "touchesBeganWithEvent" << points << "from device" << Qt::hex << [event deviceID];
27 QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(
28 m_platformWindow->window(), timestamp * 1000,
29 QCocoaTouch::getTouchDevice(QInputDevice::DeviceType::TouchPad, [event deviceID]),
30 points);
31}
32
33- (void)touchesMovedWithEvent:(NSEvent *)event
34{
35 if (!m_platformWindow)
36 return;
37
38 const NSTimeInterval timestamp = [event timestamp];
39
40 QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
41 nativeDrag->setLastInputEvent(event, self);
42
43 const QList<QWindowSystemInterface::TouchPoint> points = QCocoaTouch::getCurrentTouchPointList(event, [self shouldSendSingleTouch]);
44 qCDebug(lcQpaTouch) << "touchesMovedWithEvent" << points << "from device" << Qt::hex << [event deviceID];
45 QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(
46 m_platformWindow->window(), timestamp * 1000,
47 QCocoaTouch::getTouchDevice(QInputDevice::DeviceType::TouchPad, [event deviceID]),
48 points);
49}
50
51- (void)touchesEndedWithEvent:(NSEvent *)event
52{
53 if (!m_platformWindow)
54 return;
55
56 const NSTimeInterval timestamp = [event timestamp];
57
58 QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
59 nativeDrag->setLastInputEvent(event, self);
60
61 const QList<QWindowSystemInterface::TouchPoint> points = QCocoaTouch::getCurrentTouchPointList(event, [self shouldSendSingleTouch]);
62 qCDebug(lcQpaTouch) << "touchesEndedWithEvent" << points << "from device" << Qt::hex << [event deviceID];
63 QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(
64 m_platformWindow->window(), timestamp * 1000,
65 QCocoaTouch::getTouchDevice(QInputDevice::DeviceType::TouchPad, [event deviceID]),
66 points);
67
68 m_platformWindow->updateAllowedTouchTypes();
69}
70
71- (void)touchesCancelledWithEvent:(NSEvent *)event
72{
73 if (!m_platformWindow)
74 return;
75
76 const NSTimeInterval timestamp = [event timestamp];
77
78 QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
79 nativeDrag->setLastInputEvent(event, self);
80
81 const QList<QWindowSystemInterface::TouchPoint> points = QCocoaTouch::getCurrentTouchPointList(event, [self shouldSendSingleTouch]);
82 qCDebug(lcQpaTouch) << "touchesCancelledWithEvent" << points << "from device" << Qt::hex << [event deviceID];
83 QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(
84 m_platformWindow->window(), timestamp * 1000,
85 QCocoaTouch::getTouchDevice(QInputDevice::DeviceType::TouchPad, [event deviceID]),
86 points);
87
88 m_platformWindow->updateAllowedTouchTypes();
89}
90
91@end