iOS: Add QPointingDevice for Apple Pencil

For Apple Pencil 1st generation, it supports xTilt and yTilt
capabilities.

Task-number: QTBUG-128466
Change-Id: I572a303a4d213417004cacadbc7cef9c96334720
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
HIDAKA Takahiro 2024-09-11 03:56:49 +09:00 committed by Hidaka Takahiro
parent 0a017308cc
commit 38aa7f5fe7
3 changed files with 26 additions and 5 deletions

View File

@ -72,6 +72,9 @@ public:
QPlatformNativeInterface *nativeInterface() const override;
QPointingDevice *touchDevice();
#if QT_CONFIG(tabletevent)
QPointingDevice *pencilDevice();
#endif
#if QT_CONFIG(accessibility)
QPlatformAccessibility *accessibility() const override;
#endif
@ -109,6 +112,9 @@ private:
#endif
QPlatformInputContext *m_inputContext;
QPointingDevice *m_touchDevice;
#if QT_CONFIG(tabletevent)
QPointingDevice *m_pencilDevice = nullptr;
#endif
QIOSServices *m_platformServices;
mutable QPlatformAccessibility *m_accessibility;
QFactoryLoader *m_optionalPlugins;

View File

@ -104,6 +104,12 @@ void QIOSIntegration::initialize()
QWindowSystemInterface::registerInputDevice(m_touchDevice);
#if QT_CONFIG(tabletevent)
QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(false);
m_pencilDevice = new QPointingDevice(
"Apple Pencil", 0, QInputDevice::DeviceType::Stylus, QPointingDevice::PointerType::Pen,
QInputDevice::Capability::Position | QInputDevice::Capability::Pressure
| QInputDevice::Capability::XTilt | QInputDevice::Capability::YTilt,
1, 0);
QWindowSystemInterface::registerInputDevice(m_pencilDevice);
#endif
QMacMimeRegistry::initializeMimeTypes();
@ -271,6 +277,13 @@ QPointingDevice *QIOSIntegration::touchDevice()
return m_touchDevice;
}
#if QT_CONFIG(tabletevent)
QPointingDevice *QIOSIntegration::pencilDevice()
{
return m_pencilDevice;
}
#endif
#if QT_CONFIG(accessibility)
QPlatformAccessibility *QIOSIntegration::accessibility() const
{

View File

@ -387,13 +387,15 @@ inline ulong getTimeStamp(UIEvent *event)
qCDebug(lcQpaTablet) << i << ":" << timeStamp << localViewPosition << pressure << state << "azimuth" << azimuth.dx << azimuth.dy
<< "angle" << azimuthAngle << "altitude" << cTouch.altitudeAngle
<< "xTilt" << qBound(-60.0, altitudeAngle * azimuth.dx, 60.0) << "yTilt" << qBound(-60.0, altitudeAngle * azimuth.dy, 60.0);
QWindowSystemInterface::handleTabletEvent(self.platformWindow->window(), timeStamp, localViewPosition, globalScreenPosition,
// device, pointerType, buttons
int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), state == QEventPoint::State::Released ? Qt::NoButton : Qt::LeftButton,
QWindowSystemInterface::handleTabletEvent(self.platformWindow->window(), timeStamp,
// device, local, global
iosIntegration->pencilDevice(), localViewPosition, globalScreenPosition,
// buttons
state == QEventPoint::State::Released ? Qt::NoButton : Qt::LeftButton,
// pressure, xTilt, yTilt
pressure, qBound(-60.0, altitudeAngle * azimuth.dx, 60.0), qBound(-60.0, altitudeAngle * azimuth.dy, 60.0),
// tangentialPressure, rotation, z, uid, modifiers
0, azimuthAngle, 0, 0, Qt::NoModifier);
// tangentialPressure, rotation, z, modifiers
0, azimuthAngle, 0, Qt::NoModifier);
++i;
}
}