aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-03-26 16:50:40 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2020-06-23 17:44:03 +0200
commitd0ae3a312a03c118a1aa25a4c6c0352375d569fc (patch)
tree01df3e8ea22c8a1ecd969a6e9e6d7014c635da9f
parentd5d6a56809032796444fe63c220a2e940ce237c0 (diff)
Remove QQuickPointerDevice in favor of QPointingDevice
...and generally deal with changes immediately required after adding QInputDevice and QPointingDevice. Also fixed a few usages of deprecated accessors that weren't taken care of in 212c2bffbb041aee0e3c9a7f0551ef151ed2d3ad. Task-number: QTBUG-46412 Task-number: QTBUG-69433 Task-number: QTBUG-72167 Change-Id: I93a2643162878afa216556f10808fd92e0b20071 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-rw-r--r--src/imports/testlib/TestCase.qml4
-rw-r--r--src/imports/testlib/quicktestevent.cpp11
-rw-r--r--src/imports/testlib/quicktestevent_p.h2
-rw-r--r--src/quick/handlers/qquickhoverhandler.cpp2
-rw-r--r--src/quick/handlers/qquickpointerdevicehandler.cpp14
-rw-r--r--src/quick/handlers/qquickpointerdevicehandler_p.h12
-rw-r--r--src/quick/handlers/qquickpointerdevicehandler_p_p.h4
-rw-r--r--src/quick/handlers/qquickpointerhandler.cpp13
-rw-r--r--src/quick/handlers/qquickpointerhandler_p_p.h2
-rw-r--r--src/quick/handlers/qquicktaphandler.cpp2
-rw-r--r--src/quick/handlers/qquickwheelhandler.cpp4
-rw-r--r--src/quick/items/qquickevents.cpp265
-rw-r--r--src/quick/items/qquickevents_p_p.h139
-rw-r--r--src/quick/items/qquickflickable.cpp7
-rw-r--r--src/quick/items/qquickitem.cpp6
-rw-r--r--src/quick/items/qquickitemsmodule_p.h19
-rw-r--r--src/quick/items/qquickmultipointtoucharea.cpp2
-rw-r--r--src/quick/items/qquickmultipointtoucharea_p.h2
-rw-r--r--src/quick/items/qquickwindow.cpp118
-rw-r--r--src/quick/items/qquickwindow_p.h8
-rw-r--r--tests/auto/quick/pointerhandlers/flickableinterop/tst_flickableinterop.cpp2
-rw-r--r--tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp9
-rw-r--r--tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp11
-rw-r--r--tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp18
-rw-r--r--tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp17
-rw-r--r--tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp6
-rw-r--r--tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp10
-rw-r--r--tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp3
-rw-r--r--tests/auto/quick/qquickflickable/tst_qquickflickable.cpp3
-rw-r--r--tests/auto/quick/qquickitem/tst_qquickitem.cpp7
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp5
-rw-r--r--tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp14
-rw-r--r--tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp12
-rw-r--r--tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp15
-rw-r--r--tests/auto/quick/qquickwindow/tst_qquickwindow.cpp26
-rw-r--r--tests/auto/quick/touchmouse/tst_touchmouse.cpp13
-rw-r--r--tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp2
-rw-r--r--tests/manual/pointer/inputinspector.cpp16
-rw-r--r--tests/manual/pointer/inputinspector.h4
39 files changed, 270 insertions, 559 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index 380b7e38d7..7aab7ef612 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -1614,7 +1614,7 @@ Item {
\since 5.9
- Begins a sequence of touch events through a simulated QTouchDevice::TouchScreen.
+ Begins a sequence of touch events through a simulated touchscreen (QPointingDevice).
Events are delivered to the window containing \a item.
The returned object is used to enumerate events to be delivered through a single
@@ -1649,7 +1649,7 @@ Item {
}
\endcode
- \sa TouchEventSequence::press(), TouchEventSequence::move(), TouchEventSequence::release(), TouchEventSequence::stationary(), TouchEventSequence::commit(), QTouchDevice::TouchScreen
+ \sa TouchEventSequence::press(), TouchEventSequence::move(), TouchEventSequence::release(), TouchEventSequence::stationary(), TouchEventSequence::commit(), QInputDevice::DeviceType::TouchScreen
*/
function touchEvent(item) {
diff --git a/src/imports/testlib/quicktestevent.cpp b/src/imports/testlib/quicktestevent.cpp
index f2d7f93d26..b2693de234 100644
--- a/src/imports/testlib/quicktestevent.cpp
+++ b/src/imports/testlib/quicktestevent.cpp
@@ -443,14 +443,15 @@ QObject *QQuickTouchEventSequence::commit()
\internal
*/
-QTouchDevice *QuickTestEvent::touchDevice()
+QPointingDevice *QuickTestEvent::touchDevice()
{
- static QTouchDevice *device(nullptr);
+ static QPointingDevice *device(nullptr);
if (!device) {
- device = new QTouchDevice;
- device->setType(QTouchDevice::TouchScreen);
- QWindowSystemInterface::registerTouchDevice(device);
+ device = new QPointingDevice(QLatin1String("test touchscreen"), 42,
+ QInputDevice::DeviceType::TouchScreen, QPointingDevice::PointerType::Finger,
+ QInputDevice::Capability::Position, 10, 0);
+ QWindowSystemInterface::registerInputDevice(device);
}
return device;
}
diff --git a/src/imports/testlib/quicktestevent_p.h b/src/imports/testlib/quicktestevent_p.h
index 0bbae8434f..4e63a2e47e 100644
--- a/src/imports/testlib/quicktestevent_p.h
+++ b/src/imports/testlib/quicktestevent_p.h
@@ -122,7 +122,7 @@ public Q_SLOTS:
private:
QWindow *eventWindow(QObject *item = nullptr);
QWindow *activeWindow();
- QTouchDevice *touchDevice();
+ QPointingDevice *touchDevice();
Qt::MouseButtons m_pressedButtons;
diff --git a/src/quick/handlers/qquickhoverhandler.cpp b/src/quick/handlers/qquickhoverhandler.cpp
index b12d85784a..76e5bc0605 100644
--- a/src/quick/handlers/qquickhoverhandler.cpp
+++ b/src/quick/handlers/qquickhoverhandler.cpp
@@ -116,7 +116,7 @@ void QQuickHoverHandler::handleEventPoint(QQuickEventPoint *point)
{
bool hovered = true;
if (point->state() == QQuickEventPoint::Released &&
- point->pointerEvent()->device()->pointerType() == QQuickPointerDevice::Finger)
+ point->pointerEvent()->device()->pointerType() == QPointingDevice::PointerType::Finger)
hovered = false;
else if (point->pointerEvent()->asPointerTabletEvent())
m_hoveredTablet = true;
diff --git a/src/quick/handlers/qquickpointerdevicehandler.cpp b/src/quick/handlers/qquickpointerdevicehandler.cpp
index 90f31bf9fd..592abb6660 100644
--- a/src/quick/handlers/qquickpointerdevicehandler.cpp
+++ b/src/quick/handlers/qquickpointerdevicehandler.cpp
@@ -67,13 +67,13 @@ QQuickPointerDeviceHandler::QQuickPointerDeviceHandler(QQuickPointerDeviceHandle
{
}
-QQuickPointerDevice::DeviceTypes QQuickPointerDeviceHandler::acceptedDevices() const
+QPointingDevice::DeviceTypes QQuickPointerDeviceHandler::acceptedDevices() const
{
Q_D(const QQuickPointerDeviceHandler);
return d->acceptedDevices;
}
-QQuickPointerDevice::PointerTypes QQuickPointerDeviceHandler::acceptedPointerTypes() const
+QPointingDevice::PointerTypes QQuickPointerDeviceHandler::acceptedPointerTypes() const
{
Q_D(const QQuickPointerDeviceHandler);
return d->acceptedPointerTypes;
@@ -156,7 +156,7 @@ Qt::KeyboardModifiers QQuickPointerDeviceHandler::acceptedModifiers() const
}
\endqml
*/
-void QQuickPointerDeviceHandler::setAcceptedDevices(QQuickPointerDevice::DeviceTypes acceptedDevices)
+void QQuickPointerDeviceHandler::setAcceptedDevices(QPointingDevice::DeviceTypes acceptedDevices)
{
Q_D(QQuickPointerDeviceHandler);
if (d->acceptedDevices == acceptedDevices)
@@ -195,7 +195,7 @@ void QQuickPointerDeviceHandler::setAcceptedDevices(QQuickPointerDevice::DeviceT
}
\endqml
*/
-void QQuickPointerDeviceHandler::setAcceptedPointerTypes(QQuickPointerDevice::PointerTypes acceptedPointerTypes)
+void QQuickPointerDeviceHandler::setAcceptedPointerTypes(QPointingDevice::PointerTypes acceptedPointerTypes)
{
Q_D(QQuickPointerDeviceHandler);
if (d->acceptedPointerTypes == acceptedPointerTypes)
@@ -299,14 +299,14 @@ bool QQuickPointerDeviceHandler::wantsPointerEvent(QQuickPointerEvent *event)
<< "checking device type" << d->acceptedDevices
<< "pointer type" << d->acceptedPointerTypes
<< "modifiers" << d->acceptedModifiers;
- if ((event->device()->type() & d->acceptedDevices) == 0)
+ if (!d->acceptedDevices.testFlag(event->device()->type()))
return false;
- if ((event->device()->pointerType() & d->acceptedPointerTypes) == 0)
+ if (!d->acceptedPointerTypes.testFlag(event->device()->pointerType()))
return false;
if (d->acceptedModifiers != Qt::KeyboardModifierMask && event->modifiers() != d->acceptedModifiers)
return false;
// HoverHandler sets acceptedButtons to Qt::NoButton to indicate that button state is irrelevant.
- if (event->device()->pointerType() != QQuickPointerDevice::Finger && acceptedButtons() != Qt::NoButton &&
+ if (event->device()->pointerType() != QPointingDevice::PointerType::Finger && acceptedButtons() != Qt::NoButton &&
(event->buttons() & acceptedButtons()) == 0 && (event->button() & acceptedButtons()) == 0
&& !event->asPointerScrollEvent())
return false;
diff --git a/src/quick/handlers/qquickpointerdevicehandler_p.h b/src/quick/handlers/qquickpointerdevicehandler_p.h
index bb15142824..28c88db2b7 100644
--- a/src/quick/handlers/qquickpointerdevicehandler_p.h
+++ b/src/quick/handlers/qquickpointerdevicehandler_p.h
@@ -59,22 +59,22 @@ class QQuickPointerDeviceHandlerPrivate;
class Q_QUICK_PRIVATE_EXPORT QQuickPointerDeviceHandler : public QQuickPointerHandler
{
Q_OBJECT
- Q_PROPERTY(QQuickPointerDevice::DeviceTypes acceptedDevices READ acceptedDevices WRITE setAcceptedDevices NOTIFY acceptedDevicesChanged)
- Q_PROPERTY(QQuickPointerDevice::PointerTypes acceptedPointerTypes READ acceptedPointerTypes WRITE setAcceptedPointerTypes NOTIFY acceptedPointerTypesChanged)
+ Q_PROPERTY(QPointingDevice::DeviceTypes acceptedDevices READ acceptedDevices WRITE setAcceptedDevices NOTIFY acceptedDevicesChanged)
+ Q_PROPERTY(QPointingDevice::PointerTypes acceptedPointerTypes READ acceptedPointerTypes WRITE setAcceptedPointerTypes NOTIFY acceptedPointerTypesChanged)
Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged)
Q_PROPERTY(Qt::KeyboardModifiers acceptedModifiers READ acceptedModifiers WRITE setAcceptedModifiers NOTIFY acceptedModifiersChanged)
public:
explicit QQuickPointerDeviceHandler(QQuickItem *parent = nullptr);
- QQuickPointerDevice::DeviceTypes acceptedDevices() const;
- QQuickPointerDevice::PointerTypes acceptedPointerTypes() const;
+ QPointingDevice::DeviceTypes acceptedDevices() const;
+ QPointingDevice::PointerTypes acceptedPointerTypes() const;
Qt::MouseButtons acceptedButtons() const;
Qt::KeyboardModifiers acceptedModifiers() const;
public Q_SLOTS:
- void setAcceptedDevices(QQuickPointerDevice::DeviceTypes acceptedDevices);
- void setAcceptedPointerTypes(QQuickPointerDevice::PointerTypes acceptedPointerTypes);
+ void setAcceptedDevices(QPointingDevice::DeviceTypes acceptedDevices);
+ void setAcceptedPointerTypes(QPointingDevice::PointerTypes acceptedPointerTypes);
void setAcceptedButtons(Qt::MouseButtons buttons);
void setAcceptedModifiers(Qt::KeyboardModifiers acceptedModifiers);
diff --git a/src/quick/handlers/qquickpointerdevicehandler_p_p.h b/src/quick/handlers/qquickpointerdevicehandler_p_p.h
index 03272d9f69..a7cc951e98 100644
--- a/src/quick/handlers/qquickpointerdevicehandler_p_p.h
+++ b/src/quick/handlers/qquickpointerdevicehandler_p_p.h
@@ -64,8 +64,8 @@ public:
static QQuickPointerDeviceHandlerPrivate* get(QQuickPointerDeviceHandler *q) { return q->d_func(); }
static const QQuickPointerDeviceHandlerPrivate* get(const QQuickPointerDeviceHandler *q) { return q->d_func(); }
- QQuickPointerDevice::DeviceTypes acceptedDevices = QQuickPointerDevice::AllDevices;
- QQuickPointerDevice::PointerTypes acceptedPointerTypes = QQuickPointerDevice::AllPointerTypes;
+ QPointingDevice::DeviceTypes acceptedDevices = QPointingDevice::DeviceType::AllDevices;
+ QPointingDevice::PointerTypes acceptedPointerTypes = QPointingDevice::PointerType::AllPointerTypes;
Qt::MouseButtons acceptedButtons = Qt::LeftButton;
Qt::KeyboardModifiers acceptedModifiers = Qt::KeyboardModifierMask;
};
diff --git a/src/quick/handlers/qquickpointerhandler.cpp b/src/quick/handlers/qquickpointerhandler.cpp
index adb753e000..2a02511402 100644
--- a/src/quick/handlers/qquickpointerhandler.cpp
+++ b/src/quick/handlers/qquickpointerhandler.cpp
@@ -40,6 +40,7 @@
#include "qquickpointerhandler_p.h"
#include "qquickpointerhandler_p_p.h"
#include <QtQuick/private/qquickitem_p.h>
+#include <QtGui/private/qinputdevice_p.h>
QT_BEGIN_NAMESPACE
@@ -598,7 +599,7 @@ void QQuickPointerHandler::handlePointerEvent(QQuickPointerEvent *event)
pt->cancelExclusiveGrab();
}
}
- event->device()->eventDeliveryTargets().append(this);
+ QQuickPointerHandlerPrivate::deviceDeliveryTargets(event->device()).append(this);
}
bool QQuickPointerHandler::wantsPointerEvent(QQuickPointerEvent *event)
@@ -715,4 +716,14 @@ bool QQuickPointerHandlerPrivate::dragOverThreshold(const QQuickEventPoint *poin
dragOverThreshold(delta.y(), Qt::YAxis, point));
}
+QVector<QObject *> &QQuickPointerHandlerPrivate::deviceDeliveryTargets(const QInputDevice *device)
+{
+ QInputDevicePrivate *devPriv = QInputDevicePrivate::get(const_cast<QInputDevice *>(device));
+ if (devPriv->qqExtra)
+ return *static_cast<QVector<QObject *>*>(devPriv->qqExtra);
+ auto targets = new QVector<QObject *>;
+ devPriv->qqExtra = targets;
+ return *targets;
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/handlers/qquickpointerhandler_p_p.h b/src/quick/handlers/qquickpointerhandler_p_p.h
index db053fb6b4..03b36c6dae 100644
--- a/src/quick/handlers/qquickpointerhandler_p_p.h
+++ b/src/quick/handlers/qquickpointerhandler_p_p.h
@@ -74,6 +74,8 @@ public:
bool dragOverThreshold(QVector2D delta) const;
bool dragOverThreshold(const QQuickEventPoint *point) const;
+ static QVector<QObject *> &deviceDeliveryTargets(const QInputDevice *device);
+
QQuickPointerEvent *currentEvent = nullptr;
QQuickItem *target = nullptr;
qreal m_margin = 0;
diff --git a/src/quick/handlers/qquicktaphandler.cpp b/src/quick/handlers/qquicktaphandler.cpp
index f3674d6fa9..2fabd39709 100644
--- a/src/quick/handlers/qquicktaphandler.cpp
+++ b/src/quick/handlers/qquicktaphandler.cpp
@@ -280,7 +280,7 @@ void QQuickTapHandler::setPressed(bool press, bool cancel, QQuickEventPoint *poi
qreal ts = point->pointerEvent()->timestamp() / 1000.0;
if (ts - m_lastTapTimestamp < m_multiTapInterval &&
QVector2D(point->scenePosition() - m_lastTapPos).lengthSquared() <
- (point->pointerEvent()->device()->type() == QQuickPointerDevice::Mouse ?
+ (point->pointerEvent()->device()->type() == QInputDevice::DeviceType::Mouse ?
m_mouseMultiClickDistanceSquared : m_touchMultiTapDistanceSquared))
++m_tapCount;
else
diff --git a/src/quick/handlers/qquickwheelhandler.cpp b/src/quick/handlers/qquickwheelhandler.cpp
index 16f38af962..64bf5bc540 100644
--- a/src/quick/handlers/qquickwheelhandler.cpp
+++ b/src/quick/handlers/qquickwheelhandler.cpp
@@ -95,7 +95,7 @@ Q_LOGGING_CATEGORY(lcWheelHandler, "qt.quick.handler.wheel")
QQuickWheelHandler::QQuickWheelHandler(QQuickItem *parent)
: QQuickSinglePointHandler(*(new QQuickWheelHandlerPrivate), parent)
{
- setAcceptedDevices(QQuickPointerDevice::Mouse);
+ setAcceptedDevices(QInputDevice::DeviceType::Mouse);
}
/*!
@@ -367,7 +367,7 @@ bool QQuickWheelHandler::wantsPointerEvent(QQuickPointerEvent *event)
QQuickPointerScrollEvent *scroll = event->asPointerScrollEvent();
if (!scroll)
return false;
- if (!acceptedDevices().testFlag(QQuickPointerDevice::DeviceType::TouchPad)
+ if (!acceptedDevices().testFlag(QPointingDevice::DeviceType::TouchPad)
&& scroll->synthSource() != Qt::MouseEventNotSynthesized)
return false;
if (!active()) {
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp
index 80f572d3b5..7c376d7edf 100644
--- a/src/quick/items/qquickevents.cpp
+++ b/src/quick/items/qquickevents.cpp
@@ -40,10 +40,11 @@
#include "qquickevents_p_p.h"
#include <QtCore/qmap.h>
#include <QtGui/private/qguiapplication_p.h>
-#include <QtGui/private/qtouchdevice_p.h>
+#include <QtGui/private/qinputdevice_p.h>
#include <QtGui/private/qevent_p.h>
#include <QtQuick/private/qquickitem_p.h>
#include <QtQuick/private/qquickpointerhandler_p.h>
+#include <QtQuick/private/qquickpointerhandler_p_p.h>
#include <QtQuick/private/qquickwindow_p.h>
#include <private/qdebug_p.h>
@@ -471,7 +472,7 @@ Item {
/*!
\qmltype PointerDevice
- \instantiates QQuickPointerDevice
+ \instantiates QPointingDevice
\inqmlmodule QtQuick
\ingroup qtquick-input-events
@@ -491,7 +492,7 @@ Item {
Valid values are:
- \value DeviceType.UnknownDevice
+ \value DeviceType.Unknown
the device cannot be identified
\value DeviceType.Mouse
a mouse
@@ -511,7 +512,7 @@ Item {
\value DeviceType.AllDevices
any of the above; used as a default value for construction
- \sa QTouchDevice::DeviceType
+ \sa QPointingDevice::DeviceType
*/
/*!
@@ -529,7 +530,7 @@ Item {
Valid values are:
- \value PointerDevice.GenericPointer
+ \value PointerDevice.Generic
a mouse or something acting like a mouse (the core pointer on X11)
\value PointerDevice.Finger
the user's finger
@@ -543,7 +544,6 @@ Item {
any of the above (used as a default value in constructors)
*/
-
/*!
\readonly
\qmlproperty enumeration QtQuick::PointerDevice::capabilities
@@ -554,59 +554,33 @@ Item {
Valid values are:
- \value CapabilityFlag.Position
+ \value Capability.Position
the \l {QtQuick::EventPoint::position}{position} and
\l {QtQuick::EventPoint::scenePosition}{scenePosition} properties
- \value CapabilityFlag.Area
+ \value Capability.Area
the \l {QtQuick::EventTouchPoint::ellipseDiameters}{ellipseDiameters} property
- \value CapabilityFlag.Pressure
+ \value Capability.Pressure
the \l {QtQuick::EventTouchPoint::pressure}{pressure} property
- \value CapabilityFlag.Velocity
+ \value Capability.Velocity
the \l {QtQuick::EventPoint::velocity}{velocity} property
- \value CapabilityFlag.Scroll
+ \value Capability.Scroll
a \l {QtQuick::PointerDevice::type}{Mouse} has a wheel, or the
operating system recognizes scroll gestures on a
\l {QtQuick::PointerDevice::type}{TouchPad}
- \value CapabilityFlag.Hover
+ \value Capability.Hover
events are sent even when no button is pressed, or the finger or stylus
is not in contact with the surface
- \value CapabilityFlag.Rotation
+ \value Capability.Rotation
the \l {QtQuick::EventTouchPoint::rotation}{rotation} property
- \value CapabilityFlag.XTilt
+ \value Capability.XTilt
horizontal angle between a stylus and the axis perpendicular to the surface
- \value CapabilityFlag.YTilt
+ \value Capability.YTilt
vertical angle between a stylus and the axis perpendicular to the surface
- \sa QTouchDevice::capabilities
+ \sa QPointingDevice::capabilities
*/
-struct ConstructableQQuickPointerDevice : public QQuickPointerDevice
-{
- ConstructableQQuickPointerDevice(DeviceType devType, PointerType pType, Capabilities caps,
- int maxPoints, int buttonCount, const QString &name,
- qint64 uniqueId = 0)
- : QQuickPointerDevice(devType, pType, caps, maxPoints, buttonCount, name, uniqueId) {}
-
-};
-
-template<typename Key>
-struct PointerDeviceHash : public QHash<Key, ConstructableQQuickPointerDevice *>
-{
- ~PointerDeviceHash() { qDeleteAll(*this); }
-};
-using PointerDeviceForTouchDeviceHash = PointerDeviceHash<const QTouchDevice *>;
-Q_GLOBAL_STATIC(PointerDeviceForTouchDeviceHash, g_touchDevices)
-Q_GLOBAL_STATIC_WITH_ARGS(ConstructableQQuickPointerDevice, g_genericMouseDevice,
- (QQuickPointerDevice::Mouse,
- QQuickPointerDevice::GenericPointer,
- QQuickPointerDevice::Position | QQuickPointerDevice::Scroll | QQuickPointerDevice::Hover,
- 1, 3, QLatin1String("core pointer"), 0))
-#if QT_CONFIG(tabletevent)
-using PointerDeviceForDeviceIdHash = PointerDeviceHash<qint64>;
-Q_GLOBAL_STATIC(PointerDeviceForDeviceIdHash, g_tabletDevices)
-#endif
-
// debugging helpers
static const char *pointStateString(const QQuickEventPoint *point)
{
@@ -622,130 +596,6 @@ static const QString pointDeviceName(const QQuickEventPoint *point)
return deviceName;
}
-
-QQuickPointerDevice *QQuickPointerDevice::touchDevice(const QTouchDevice *d)
-{
- if (g_touchDevices->contains(d))
- return g_touchDevices->value(d);
-
- QQuickPointerDevice::DeviceType type = QQuickPointerDevice::TouchScreen;
- QString name;
- int maximumTouchPoints = 10;
- QQuickPointerDevice::Capabilities caps = QQuickPointerDevice::Capabilities(QTouchDevice::Position);
- if (d) {
- caps = static_cast<QQuickPointerDevice::Capabilities>(static_cast<int>(d->capabilities()) & 0xFF);
- if (d->type() == QTouchDevice::TouchPad) {
- type = QQuickPointerDevice::TouchPad;
- caps |= QQuickPointerDevice::Scroll;
- }
- name = d->name();
- maximumTouchPoints = d->maximumTouchPoints();
- } else {
- qWarning() << "QQuickWindowPrivate::touchDevice: creating touch device from nullptr device in QTouchEvent";
- }
-
- ConstructableQQuickPointerDevice *dev = new ConstructableQQuickPointerDevice(
- type, QQuickPointerDevice::Finger, caps, maximumTouchPoints, 0, name, 0);
- g_touchDevices->insert(d, dev);
- return dev;
-}
-
-const QTouchDevice *QQuickPointerDevice::qTouchDevice() const
-{
- for (auto it = g_touchDevices->constBegin(), end = g_touchDevices->constEnd(); it != end; ++it) {
- if (it.value() == this)
- return it.key();
- }
- return nullptr;
-}
-
-QList<QQuickPointerDevice*> QQuickPointerDevice::touchDevices()
-{
- QList<QQuickPointerDevice *> result;
- result.reserve(g_touchDevices->size());
- for (auto device : *g_touchDevices)
- result.append(device);
- return result;
-}
-
-QQuickPointerDevice *QQuickPointerDevice::genericMouseDevice()
-{
- return g_genericMouseDevice;
-}
-
-#if QT_CONFIG(tabletevent)
-QQuickPointerDevice *QQuickPointerDevice::tabletDevice(const QTabletEvent *event)
-{
- // QTabletEvent::uniqueId() is the same for the pointy end and the eraser end of the stylus.
- // We need to make those unique. QTabletEvent::PointerType only needs 2 bits' worth of storage.
- // The key into g_tabletDevices just needs to be unique; we don't need to extract uniqueId
- // back out of it, because QQuickPointerDevice stores that separately anyway.
- // So the shift-and-add can be thought of as a sort of hash function, even though
- // most of the time the result will be recognizable because the uniqueId MSBs are often 0.
- qint64 key = event->uniqueId() + (qint64(event->pointerType()) << 60);
- auto it = g_tabletDevices->find(key);
- if (it != g_tabletDevices->end())
- return it.value();
-
- DeviceType type = UnknownDevice;
- int buttonCount = 0;
- Capabilities caps = Position | Pressure | Hover;
- // TODO Qt 6: we can't know for sure about XTilt or YTilt until we have a
- // QTabletDevice populated with capabilities provided by QPA plugins
-
- switch (event->deviceType()) {
- case QTabletEvent::Stylus:
- type = QQuickPointerDevice::Stylus;
- buttonCount = 3;
- break;
- case QTabletEvent::RotationStylus:
- type = QQuickPointerDevice::Stylus;
- caps |= QQuickPointerDevice::Rotation;
- buttonCount = 1;
- break;
- case QTabletEvent::Airbrush:
- type = QQuickPointerDevice::Airbrush;
- buttonCount = 2;
- break;
- case QTabletEvent::Puck:
- type = QQuickPointerDevice::Puck;
- buttonCount = 3;
- break;
- case QTabletEvent::FourDMouse:
- type = QQuickPointerDevice::Mouse;
- caps |= QQuickPointerDevice::Rotation;
- buttonCount = 3;
- break;
- default:
- type = QQuickPointerDevice::UnknownDevice;
- break;
- }
-
- PointerType ptype = GenericPointer;
- switch (event->pointerType()) {
- case QTabletEvent::Pen:
- ptype = Pen;
- break;
- case QTabletEvent::Eraser:
- ptype = Eraser;
- break;
- case QTabletEvent::Cursor:
- ptype = Cursor;
- break;
- case QTabletEvent::UnknownPointer:
- break;
- }
-
- ConstructableQQuickPointerDevice *device = new ConstructableQQuickPointerDevice(
- type, ptype, caps, 1, buttonCount,
- QLatin1String("tablet tool ") + QString::number(event->uniqueId()),
- event->uniqueId());
-
- g_tabletDevices->insert(key, device);
- return device;
-}
-#endif
-
/*!
\qmltype EventPoint
\qmlabstract
@@ -1362,7 +1212,7 @@ QVector2D QQuickEventPoint::estimatedVelocity() const
QQuickPointerEvent::~QQuickPointerEvent()
{}
-QQuickPointerMouseEvent::QQuickPointerMouseEvent(QObject *parent, QQuickPointerDevice *device)
+QQuickPointerMouseEvent::QQuickPointerMouseEvent(QObject *parent, const QPointingDevice *device)
: QQuickSinglePointEvent(parent, device)
{
m_point = new QQuickEventPoint(this);
@@ -1375,8 +1225,7 @@ QQuickPointerEvent *QQuickPointerMouseEvent::reset(QEvent *event)
if (!event)
return this;
- m_device = QQuickPointerDevice::genericMouseDevice();
- m_device->eventDeliveryTargets().clear();
+ QQuickPointerHandlerPrivate::deviceDeliveryTargets(ev->device()).clear();
m_button = ev->button();
m_pressedButtons = ev->buttons();
Qt::TouchPointState state = Qt::TouchPointStationary;
@@ -1396,7 +1245,8 @@ QQuickPointerEvent *QQuickPointerMouseEvent::reset(QEvent *event)
default:
break;
}
- m_point->reset(state, ev->scenePosition(), quint64(1) << 24, ev->timestamp()); // mouse has device ID 1
+ // for now, reuse the device ID as the point ID; TODO use ev->point(0).id when it becomes possible
+ m_point->reset(state, ev->scenePosition(), int(ev->device()->id()), ev->timestamp());
return this;
}
@@ -1412,8 +1262,7 @@ QQuickPointerEvent *QQuickPointerTouchEvent::reset(QEvent *event)
if (!event)
return this;
- m_device = QQuickPointerDevice::touchDevice(ev->device());
- m_device->eventDeliveryTargets().clear();
+ QQuickPointerHandlerPrivate::deviceDeliveryTargets(ev->device()).clear();
m_button = Qt::NoButton;
m_pressedButtons = Qt::NoButton;
@@ -1482,7 +1331,7 @@ void QQuickPointerTouchEvent::localize(QQuickItem *target)
}
#if QT_CONFIG(gestures)
-QQuickPointerNativeGestureEvent::QQuickPointerNativeGestureEvent(QObject *parent, QQuickPointerDevice *device)
+QQuickPointerNativeGestureEvent::QQuickPointerNativeGestureEvent(QObject *parent, const QPointingDevice *device)
: QQuickSinglePointEvent(parent, device)
{
m_point = new QQuickEventPoint(this);
@@ -1495,8 +1344,7 @@ QQuickPointerEvent *QQuickPointerNativeGestureEvent::reset(QEvent *event)
if (!event)
return this;
- m_device = QQuickPointerDevice::touchDevice(ev->device());
- m_device->eventDeliveryTargets().clear();
+ QQuickPointerHandlerPrivate::deviceDeliveryTargets(ev->device()).clear();
Qt::TouchPointState state = Qt::TouchPointMoved;
switch (type()) {
case Qt::BeginNativeGesture:
@@ -1508,7 +1356,7 @@ QQuickPointerEvent *QQuickPointerNativeGestureEvent::reset(QEvent *event)
default:
break;
}
- quint64 deviceId = QTouchDevicePrivate::get(const_cast<QTouchDevice *>(ev->device()))->id; // a bit roundabout since QTouchDevice::mTouchDeviceId is protected
+ quint64 deviceId = QInputDevicePrivate::get(ev->device())->id;
m_point->reset(state, ev->scenePosition(), deviceId << 24, ev->timestamp());
return this;
}
@@ -1650,7 +1498,7 @@ QQuickEventPoint *QQuickSinglePointEvent::point(int i) const
\note Many platforms provide no such information. On such platforms,
\c inverted always returns false.
*/
-QQuickPointerScrollEvent::QQuickPointerScrollEvent(QObject *parent, QQuickPointerDevice *device)
+QQuickPointerScrollEvent::QQuickPointerScrollEvent(QObject *parent, const QPointingDevice *device)
: QQuickSinglePointEvent(parent, device)
{
m_point = new QQuickEventPoint(this);
@@ -1658,14 +1506,13 @@ QQuickPointerScrollEvent::QQuickPointerScrollEvent(QObject *parent, QQuickPointe
QQuickPointerEvent *QQuickPointerScrollEvent::reset(QEvent *event)
{
- m_event = static_cast<QInputEvent*>(event);
+ m_event = static_cast<QPointerEvent*>(event);
if (!event)
return this;
#if QT_CONFIG(wheelevent)
if (event->type() == QEvent::Wheel) {
auto ev = static_cast<QWheelEvent*>(event);
- m_device = QQuickPointerDevice::genericMouseDevice();
- m_device->eventDeliveryTargets().clear();
+ QQuickPointerHandlerPrivate::deviceDeliveryTargets(ev->device()).clear();
// m_button = Qt::NoButton;
m_pressedButtons = ev->buttons();
m_angleDelta = QVector2D(ev->angleDelta());
@@ -1923,21 +1770,17 @@ QMouseEvent *QQuickPointerTouchEvent::syntheticMouseEvent(int pointID, QQuickIte
p->scenePosition(), p->globalPosition(), Qt::LeftButton, buttons, m_event->modifiers());
m_synthMouseEvent.setAccepted(true);
m_synthMouseEvent.setTimestamp(m_event->timestamp());
- // In the future we will try to always have valid velocity in every QQuickEventPoint.
- // QQuickFlickablePrivate::handleMouseMoveEvent() checks for QTouchDevice::Velocity
- // and if it is set, then it does not need to do its own velocity calculations.
- // That's probably the only usecase for this, so far. Some day Flickable should handle
- // pointer events, and then passing touchpoint velocity via QMouseEvent will be obsolete.
- // Conveniently (by design), QTouchDevice::Velocity == QQuickPointerDevice.Velocity
- // so that we don't need to convert m_device->capabilities().
- if (m_device)
- QGuiApplicationPrivate::setMouseEventCapsAndVelocity(&m_synthMouseEvent, m_device->capabilities(), p->velocity());
+ // ### Qt 6: try to always have valid velocity in every QEventPoint (either from the platform, or synthesized in QtGui).
+ // QQuickFlickablePrivate::handleMouseMoveEvent() checks for QInputDevice::Capability::Velocity
+ // and if it is set, then it does not need to do its own velocity calculations. So we keep faking it this way for now.
+ if (device())
+ QGuiApplicationPrivate::setMouseEventCapsAndVelocity(&m_synthMouseEvent, device()->capabilities(), p->velocity());
QGuiApplicationPrivate::setMouseEventSource(&m_synthMouseEvent, Qt::MouseEventSynthesizedByQt);
return &m_synthMouseEvent;
}
#if QT_CONFIG(tabletevent)
-QQuickPointerTabletEvent::QQuickPointerTabletEvent(QObject *parent, QQuickPointerDevice *device)
+QQuickPointerTabletEvent::QQuickPointerTabletEvent(QObject *parent, const QPointingDevice *device)
: QQuickSinglePointEvent(parent, device)
{
m_point = new QQuickEventTabletPoint(this);
@@ -1950,8 +1793,7 @@ QQuickPointerEvent *QQuickPointerTabletEvent::reset(QEvent *event)
if (!event)
return this;
- Q_ASSERT(m_device == QQuickPointerDevice::tabletDevice(ev));
- m_device->eventDeliveryTargets().clear();
+ QQuickPointerHandlerPrivate::deviceDeliveryTargets(ev->device()).clear();
m_button = ev->button();
m_pressedButtons = ev->buttons();
static_cast<QQuickEventTabletPoint *>(m_point)->reset(ev);
@@ -2206,13 +2048,10 @@ QTouchEvent *QQuickPointerTouchEvent::touchEventForItem(QQuickItem *item, bool i
break;
}
- QTouchEvent *touchEvent = new QTouchEvent(eventType);
+ QTouchEvent *touchEvent = new QTouchEvent(eventType, event.pointingDevice(),
+ event.modifiers(), eventStates, touchPoints);
touchEvent->setWindow(event.window());
touchEvent->setTarget(item);
- touchEvent->setDevice(event.device());
- touchEvent->setModifiers(event.modifiers());
- touchEvent->setTouchPoints(touchPoints);
- touchEvent->setTouchPointStates(eventStates);
touchEvent->setTimestamp(event.timestamp());
touchEvent->accept();
return touchEvent;
@@ -2225,29 +2064,6 @@ QTouchEvent *QQuickPointerTouchEvent::asTouchEvent() const
#ifndef QT_NO_DEBUG_STREAM
-Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug dbg, const QQuickPointerDevice *dev)
-{
- QDebugStateSaver saver(dbg);
- dbg.nospace();
- if (!dev) {
- dbg << "QQuickPointerDevice(0)";
- return dbg;
- }
- dbg << "QQuickPointerDevice("<< dev->name() << ' ';
- QtDebugUtils::formatQEnum(dbg, dev->type());
- dbg << ' ';
- QtDebugUtils::formatQEnum(dbg, dev->pointerType());
- dbg << " caps:";
- QtDebugUtils::formatQFlags(dbg, dev->capabilities());
- if (dev->type() == QQuickPointerDevice::TouchScreen ||
- dev->type() == QQuickPointerDevice::TouchPad)
- dbg << " maxTouchPoints:" << dev->maximumTouchPoints();
- else
- dbg << " buttonCount:" << dev->buttonCount();
- dbg << ')';
- return dbg;
-}
-
Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug dbg, const QQuickPointerEvent *event)
{
QDebugStateSaver saver(dbg);
@@ -2258,8 +2074,13 @@ Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug dbg, const QQuickPointerEvent *e
}
dbg << "QQuickPointerEvent(";
dbg << event->timestamp();
- dbg << " dev:";
- QtDebugUtils::formatQEnum(dbg, event->device()->type());
+ if (event->device()) {
+ dbg << " dev:";
+ QtDebugUtils::formatQEnum(dbg, event->device()->type());
+ dbg << " " << event->device()->name();
+ } else {
+ dbg << " dev: null";
+ }
if (event->buttons() != Qt::NoButton) {
dbg << " buttons:";
QtDebugUtils::formatQEnum(dbg, event->buttons());
diff --git a/src/quick/items/qquickevents_p_p.h b/src/quick/items/qquickevents_p_p.h
index b1d8b52372..52ae1bab94 100644
--- a/src/quick/items/qquickevents_p_p.h
+++ b/src/quick/items/qquickevents_p_p.h
@@ -57,7 +57,7 @@
#include <QtCore/qobject.h>
#include <QtCore/qpointer.h>
#include <QtGui/qevent.h>
-#include <QtGui/qtouchdevice.h>
+#include <QtGui/qpointingdevice.h>
#include <QtGui/qvector2d.h>
#include <QtQuick/qquickitem.h>
@@ -67,7 +67,7 @@
QT_BEGIN_NAMESPACE
-class QQuickPointerDevice;
+class QPointingDevice;
class QQuickPointerEvent;
class QQuickPointerMouseEvent;
#if QT_CONFIG(gestures)
@@ -405,7 +405,7 @@ private:
class Q_QUICK_PRIVATE_EXPORT QQuickPointerEvent : public QObject
{
Q_OBJECT
- Q_PROPERTY(QQuickPointerDevice *device READ device CONSTANT)
+ Q_PROPERTY(QPointingDevice *device READ device CONSTANT)
Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers CONSTANT)
Q_PROPERTY(Qt::MouseButtons button READ button CONSTANT)
Q_PROPERTY(Qt::MouseButtons buttons READ buttons CONSTANT)
@@ -415,7 +415,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPointerEvent : public QObject
QML_ADDED_IN_VERSION(2, 12)
public:
- QQuickPointerEvent(QObject *parent = nullptr, QQuickPointerDevice *device = nullptr)
+ QQuickPointerEvent(QObject *parent = nullptr, const QPointingDevice *device = nullptr)
: QObject(parent)
, m_device(device)
, m_pressedButtons(Qt::NoButton)
@@ -424,7 +424,8 @@ public:
~QQuickPointerEvent() override;
public: // property accessors
- QQuickPointerDevice *device() const { return m_device; }
+ // non-const only because of QML engine limitations (similar to QTBUG-61749)
+ QPointingDevice *device() const { return const_cast<QPointingDevice *>(m_device); }
Qt::KeyboardModifiers modifiers() const { return m_event ? m_event->modifiers() : Qt::NoModifier; }
Qt::MouseButton button() const { return m_button; }
Qt::MouseButtons buttons() const { return m_pressedButtons; }
@@ -468,8 +469,8 @@ public: // helpers for C++ only (during event delivery)
ulong timestamp() const { return m_event ? m_event->timestamp() : 0; }
protected:
- QQuickPointerDevice *m_device;
- QInputEvent *m_event = nullptr; // original event as received by QQuickWindow
+ const QPointingDevice *m_device = nullptr;
+ QPointerEvent *m_event = nullptr; // original event as received by QQuickWindow
Qt::MouseButton m_button = Qt::NoButton;
Qt::MouseButtons m_pressedButtons;
@@ -482,7 +483,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickSinglePointEvent : public QQuickPointerEvent
{
Q_OBJECT
public:
- QQuickSinglePointEvent(QObject *parent, QQuickPointerDevice *device)
+ QQuickSinglePointEvent(QObject *parent, const QPointingDevice *device)
: QQuickPointerEvent(parent, device) { }
void localize(QQuickItem *target) override;
@@ -511,7 +512,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPointerMouseEvent : public QQuickSinglePointE
QML_ADDED_IN_VERSION(2, 12)
public:
- QQuickPointerMouseEvent(QObject *parent, QQuickPointerDevice *device);
+ QQuickPointerMouseEvent(QObject *parent, const QPointingDevice *device);
QQuickPointerEvent *reset(QEvent *) override;
bool isPressEvent() const override;
@@ -535,7 +536,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPointerTouchEvent : public QQuickPointerEvent
QML_ADDED_IN_VERSION(2, 12)
public:
- QQuickPointerTouchEvent(QObject *parent = nullptr, QQuickPointerDevice *device = nullptr)
+ QQuickPointerTouchEvent(QObject *parent = nullptr, const QPointingDevice *device = nullptr)
: QQuickPointerEvent(parent, device)
, m_synthMouseEvent(QEvent::MouseMove, QPointF(), Qt::NoButton, Qt::NoButton, Qt::NoModifier)
{}
@@ -611,7 +612,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPointerTabletEvent : public QQuickSinglePoint
{
Q_OBJECT
public:
- QQuickPointerTabletEvent(QObject *parent, QQuickPointerDevice *device);
+ QQuickPointerTabletEvent(QObject *parent, const QPointingDevice *device);
QQuickPointerEvent *reset(QEvent *) override;
bool isPressEvent() const override;
@@ -635,7 +636,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPointerNativeGestureEvent : public QQuickSing
Q_PROPERTY(qreal value READ value CONSTANT)
public:
- QQuickPointerNativeGestureEvent(QObject *parent, QQuickPointerDevice *device);
+ QQuickPointerNativeGestureEvent(QObject *parent, const QPointingDevice *device);
QQuickPointerEvent *reset(QEvent *) override;
bool isPressEvent() const override;
@@ -664,7 +665,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPointerScrollEvent : public QQuickSinglePoint
QML_ADDED_IN_VERSION(2, 14)
public:
- QQuickPointerScrollEvent(QObject *parent, QQuickPointerDevice *device);
+ QQuickPointerScrollEvent(QObject *parent, const QPointingDevice *device);
QQuickPointerEvent *reset(QEvent *) override;
void localize(QQuickItem *target) override;
@@ -681,8 +682,7 @@ public:
Qt::ScrollPhase phase() const { return m_phase; }
private:
- // TODO add QQuickPointerDevice source() whenever QInputEvent is extended to have a source device
- // then maybe Qt::MouseEventSource synthSource() will be obsolete... that's why it's not public now
+ // TODO remove this if it's obsolete
Qt::MouseEventSource synthSource() const { return m_synthSource; }
private:
@@ -698,113 +698,6 @@ private:
Q_DISABLE_COPY(QQuickPointerScrollEvent)
};
-
-// ### Qt 6: move this to qtbase, replace QTouchDevice and the enums in QTabletEvent
-class Q_QUICK_PRIVATE_EXPORT QQuickPointerDevice : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(DeviceType type READ type CONSTANT)
- Q_PROPERTY(PointerType pointerType READ pointerType CONSTANT)
- Q_PROPERTY(Capabilities capabilities READ capabilities CONSTANT)
- Q_PROPERTY(int maximumTouchPoints READ maximumTouchPoints CONSTANT)
- Q_PROPERTY(int buttonCount READ buttonCount CONSTANT)
- Q_PROPERTY(QString name READ name CONSTANT)
- Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId CONSTANT)
-
- QML_NAMED_ELEMENT(PointerDevice)
- QML_UNCREATABLE("PointerDevice is only available as a property of PointerEvent.")
- QML_ADDED_IN_VERSION(2, 12)
-
-public:
- enum DeviceType : qint16 {
- UnknownDevice = 0x0000,
- Mouse = 0x0001,
- TouchScreen = 0x0002,
- TouchPad = 0x0004,
- Puck = 0x0008,
- Stylus = 0x0010,
- Airbrush = 0x0020,
- AllDevices = 0x7FFF
- };
- Q_DECLARE_FLAGS(DeviceTypes, DeviceType)
- Q_FLAG(DeviceTypes)
-
- enum PointerType : qint16 {
- GenericPointer = 0x0001,
- Finger = 0x0002,
- Pen = 0x0004,
- Eraser = 0x0008,
- Cursor = 0x0010,
- AllPointerTypes = 0x7FFF
- };
- Q_DECLARE_FLAGS(PointerTypes, PointerType)
- Q_FLAG(PointerTypes)
-
- enum CapabilityFlag : qint16 {
- Position = QTouchDevice::Position,
- Area = QTouchDevice::Area,
- Pressure = QTouchDevice::Pressure,
- Velocity = QTouchDevice::Velocity,
- MouseEmulation = QTouchDevice::MouseEmulation,
- // some bits reserved in case we need more of QTouchDevice::Capabilities
- Scroll = 0x0100, // mouse has a wheel, or there is OS-level scroll gesture recognition (dubious?)
- Hover = 0x0200,
- Rotation = 0x0400,
- XTilt = 0x0800,
- YTilt = 0x1000
- };
- Q_DECLARE_FLAGS(Capabilities, CapabilityFlag)
- Q_FLAG(Capabilities)
-
- DeviceType type() const { return m_deviceType; }
- PointerType pointerType() const { return m_pointerType; }
- Capabilities capabilities() const { return static_cast<Capabilities>(m_capabilities); }
- bool hasCapability(CapabilityFlag cap) { return m_capabilities & cap; }
- int maximumTouchPoints() const { return m_maximumTouchPoints; }
- int buttonCount() const { return m_buttonCount; }
- QString name() const { return m_name; }
- QPointingDeviceUniqueId uniqueId() const { return m_uniqueId; }
- const QTouchDevice *qTouchDevice() const;
-
- static QQuickPointerDevice *touchDevice(const QTouchDevice *d);
- static QList<QQuickPointerDevice *> touchDevices();
- static QQuickPointerDevice *genericMouseDevice();
-#if QT_CONFIG(tabletevent)
- static QQuickPointerDevice *tabletDevice(const QTabletEvent *event);
-#endif
-
- QVector<QQuickPointerHandler *> &eventDeliveryTargets() { return m_eventDeliveryTargets; }
-
-private:
- QQuickPointerDevice(DeviceType devType, PointerType pType, Capabilities caps, int maxPoints, int buttonCount, const QString &name, qint64 uniqueId = 0)
- : m_deviceType(devType), m_pointerType(pType), m_capabilities(static_cast<qint16>(caps))
- , m_maximumTouchPoints(static_cast<qint8>(maxPoints)), m_buttonCount(static_cast<qint8>(buttonCount)), m_name(name)
- , m_uniqueId(QPointingDeviceUniqueId::fromNumericId(uniqueId))
- {
- }
- ~QQuickPointerDevice() override { }
-
-private:
- // begin 64-bit field
- DeviceType m_deviceType;
- PointerType m_pointerType;
- qint16 m_capabilities;
- qint8 m_maximumTouchPoints;
- qint8 m_buttonCount;
- // end 64-bit field
- QString m_name;
- QPointingDeviceUniqueId m_uniqueId;
- QVector<QQuickPointerHandler *> m_eventDeliveryTargets; // during delivery, handlers which have already seen the event
-
- Q_DISABLE_COPY(QQuickPointerDevice)
- friend struct ConstructableQQuickPointerDevice;
-};
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPointerDevice::DeviceTypes)
-Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPointerDevice::PointerTypes)
-Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPointerDevice::Capabilities)
-
-Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickPointerDevice *);
Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickPointerEvent *);
Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickEventPoint *);
//Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug, const QQuickEventTouchPoint *); TODO maybe
@@ -815,7 +708,7 @@ QML_DECLARE_TYPE(QQuickKeyEvent)
QML_DECLARE_TYPE(QQuickMouseEvent)
QML_DECLARE_TYPE(QQuickWheelEvent)
QML_DECLARE_TYPE(QQuickCloseEvent)
-QML_DECLARE_TYPE(QQuickPointerDevice)
+QML_DECLARE_TYPE(QPointingDevice)
QML_DECLARE_TYPE(QPointingDeviceUniqueId)
QML_DECLARE_TYPE(QQuickPointerEvent)
Q_DECLARE_METATYPE(QQuickEventPoint::GrabTransition)
diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp
index 0d9183315d..bd7242e99f 100644
--- a/src/quick/items/qquickflickable.cpp
+++ b/src/quick/items/qquickflickable.cpp
@@ -1322,7 +1322,8 @@ void QQuickFlickablePrivate::handleMouseMoveEvent(QMouseEvent *event)
bool overThreshold = false;
QVector2D velocity = QGuiApplicationPrivate::mouseEventVelocity(event);
// TODO guarantee that events always have velocity so that it never needs to be computed here
- if (!(QGuiApplicationPrivate::mouseEventCaps(event) & QTouchDevice::Velocity)) {
+ // TODO use event->device->caps()
+ if (!(QGuiApplicationPrivate::mouseEventCaps(event) & int(QInputDevice::Capability::Velocity))) {
qint64 lastTimestamp = (lastPos.isNull() ? lastPressTime : lastPosTime);
if (currentTimestamp == lastTimestamp)
return; // events are too close together: velocity would be infinite
@@ -1362,7 +1363,7 @@ void QQuickFlickablePrivate::handleMouseReleaseEvent(QMouseEvent *event)
qreal vVelocity = 0;
if (elapsed < 100 && vData.velocity != 0.) {
- vVelocity = (QGuiApplicationPrivate::mouseEventCaps(event) & QTouchDevice::Velocity)
+ vVelocity = (QGuiApplicationPrivate::mouseEventCaps(event) & int(QInputDevice::Capability::Velocity))
? QGuiApplicationPrivate::mouseEventVelocity(event).y() : vData.velocity;
}
if ((vData.atBeginning && vVelocity > 0.) || (vData.atEnd && vVelocity < 0.)) {
@@ -1377,7 +1378,7 @@ void QQuickFlickablePrivate::handleMouseReleaseEvent(QMouseEvent *event)
qreal hVelocity = 0;
if (elapsed < 100 && hData.velocity != 0.) {
- hVelocity = (QGuiApplicationPrivate::mouseEventCaps(event) & QTouchDevice::Velocity)
+ hVelocity = (QGuiApplicationPrivate::mouseEventCaps(event) & int(QInputDevice::Capability::Velocity))
? QGuiApplicationPrivate::mouseEventVelocity(event).x() : hData.velocity;
}
if ((hData.atBeginning && hVelocity > 0.) || (hData.atEnd && hVelocity < 0.)) {
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 620f6fe798..9598fb1c8e 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -54,6 +54,7 @@
#include <QtGui/qguiapplication.h>
#include <QtGui/qstylehints.h>
#include <QtGui/private/qguiapplication_p.h>
+#include <QtGui/private/qpointingdevice_p.h>
#include <QtGui/qinputmethod.h>
#include <QtCore/qcoreevent.h>
#include <QtCore/private/qnumeric_p.h>
@@ -69,6 +70,7 @@
#include <QtQuick/private/qquickaccessibleattached_p.h>
#include <QtQuick/private/qquickhoverhandler_p.h>
#include <QtQuick/private/qquickpointerhandler_p.h>
+#include <QtQuick/private/qquickpointerhandler_p_p.h>
#include <private/qv4engine_p.h>
#include <private/qv4object_p.h>
@@ -5260,7 +5262,7 @@ bool QQuickItemPrivate::anyPointerHandlerWants(QQuickEventPoint *point) const
bool QQuickItemPrivate::handlePointerEvent(QQuickPointerEvent *event, bool avoidExclusiveGrabber)
{
bool delivered = false;
- QVector<QQuickPointerHandler *> &eventDeliveryTargets = event->device()->eventDeliveryTargets();
+ QVector<QObject *> &eventDeliveryTargets = QQuickPointerHandlerPrivate::deviceDeliveryTargets(event->device());
if (extra.isAllocated()) {
for (QQuickPointerHandler *handler : extra->pointerHandlers) {
if ((!avoidExclusiveGrabber || !event->hasExclusiveGrabber(handler)) && !eventDeliveryTargets.contains(handler)) {
@@ -7633,7 +7635,7 @@ void QQuickItem::grabMouse()
bool fromTouch = windowPriv->isDeliveringTouchAsMouse();
auto point = fromTouch ?
windowPriv->pointerEventInstance(windowPriv->touchMouseDevice)->pointById(windowPriv->touchMouseId) :
- windowPriv->pointerEventInstance(QQuickPointerDevice::genericMouseDevice())->point(0);
+ windowPriv->pointerEventInstance(QPointingDevice::primaryPointingDevice())->point(0);
if (point)
point->setGrabberItem(this);
}
diff --git a/src/quick/items/qquickitemsmodule_p.h b/src/quick/items/qquickitemsmodule_p.h
index f7081f6ece..73bd8c6b69 100644
--- a/src/quick/items/qquickitemsmodule_p.h
+++ b/src/quick/items/qquickitemsmodule_p.h
@@ -53,6 +53,7 @@
#include <private/qtquickglobal_p.h>
#include <QtGui/qevent.h>
+#include <QtGui/qpointingdevice.h>
#include <qqml.h>
QT_BEGIN_NAMESPACE
@@ -63,6 +64,24 @@ public:
static void defineModule();
};
+struct QInputDeviceForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QInputDevice)
+ QML_NAMED_ELEMENT(InputDevice)
+ QML_ADDED_IN_VERSION(6, 0)
+ QML_UNCREATABLE("InputDevice is only available via read-only properties.")
+};
+
+struct QPointingDeviceForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QPointingDevice)
+ QML_NAMED_ELEMENT(PointerDevice)
+ QML_ADDED_IN_VERSION(6, 0)
+ QML_UNCREATABLE("PointerDevice is only available via read-only properties.")
+};
+
struct QPointingDeviceUniqueIdForeign
{
Q_GADGET
diff --git a/src/quick/items/qquickmultipointtoucharea.cpp b/src/quick/items/qquickmultipointtoucharea.cpp
index 35e458fa52..9570ab873e 100644
--- a/src/quick/items/qquickmultipointtoucharea.cpp
+++ b/src/quick/items/qquickmultipointtoucharea.cpp
@@ -587,7 +587,7 @@ void QQuickMultiPointTouchArea::updateTouchData(QEvent *event)
break;
case QEvent::MouseButtonPress:
_mouseQpaTouchPoint = QTouchEvent::TouchPoint(windowPriv->touchMouseId);
- _touchMouseDevice = windowPriv->touchMouseDevice->qTouchDevice();
+ _touchMouseDevice = windowPriv->touchMouseDevice;
Q_FALLTHROUGH();
case QEvent::MouseMove:
case QEvent::MouseButtonRelease: {
diff --git a/src/quick/items/qquickmultipointtoucharea_p.h b/src/quick/items/qquickmultipointtoucharea_p.h
index d37cc6df7e..1df4912585 100644
--- a/src/quick/items/qquickmultipointtoucharea_p.h
+++ b/src/quick/items/qquickmultipointtoucharea_p.h
@@ -301,7 +301,7 @@ private:
QVector<int> _lastFilterableTouchPointIds;
QPointer<QQuickTouchPoint> _mouseTouchPoint; // exists when mouse button is down and _mouseEnabled is true; null otherwise
QTouchEvent::TouchPoint _mouseQpaTouchPoint; // synthetic QPA touch point to hold state and position of the mouse
- const QTouchDevice *_touchMouseDevice;
+ const QPointingDevice *_touchMouseDevice;
QPointF _mousePos;
bool _stealMouse;
bool _mouseEnabled;
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index 54926c3e9b..3f14b277ae 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -57,6 +57,7 @@
#include <private/qsgrhisupport_p.h>
#include <private/qquickrendercontrol_p.h>
#include <private/qquickanimatorcontroller_p.h>
+#include <private/qquickpointerhandler_p_p.h>
#include <private/qquickprofiler_p.h>
#include <private/qguiapplication_p.h>
@@ -67,6 +68,7 @@
#include <QtGui/qpainter.h>
#include <QtGui/qevent.h>
#include <QtGui/qmatrix4x4.h>
+#include <QtGui/private/qpointingdevice_p.h>
#include <QtGui/qpa/qplatformtheme.h>
#include <QtCore/qvarlengtharray.h>
#include <QtCore/qabstractanimation.h>
@@ -866,7 +868,7 @@ static QMouseEvent *touchToMouseEvent(QEvent::Type type, const QTouchEvent::Touc
QMatrix4x4 transformMatrix(itemPrivate->windowToItemTransform());
transformedVelocity = transformMatrix.mapVector(p.velocity()).toVector2D();
}
- QGuiApplicationPrivate::setMouseEventCapsAndVelocity(me, event->device()->capabilities(), transformedVelocity);
+ QGuiApplicationPrivate::setMouseEventCapsAndVelocity(me, event->pointingDevice()->capabilities(), transformedVelocity);
QGuiApplicationPrivate::setMouseEventSource(me, Qt::MouseEventSynthesizedByQt);
return me;
}
@@ -911,7 +913,7 @@ bool QQuickWindowPrivate::deliverTouchAsMouse(QQuickItem *item, QQuickPointerEve
auto device = pointerEvent->device();
// A touch event from a trackpad is likely to be followed by a mouse or gesture event, so mouse event synth is redundant
- if (device->type() == QQuickPointerDevice::TouchPad && device->capabilities().testFlag(QQuickPointerDevice::MouseEmulation)) {
+ if (device->type() == QInputDevice::DeviceType::TouchPad && device->capabilities().testFlag(QInputDevice::Capability::MouseEmulation)) {
qCDebug(DBG_TOUCH_TARGET) << "skipping delivery of synth-mouse event from" << device;
return false;
}
@@ -1057,9 +1059,11 @@ void QQuickWindowPrivate::grabTouchPoints(QObject *grabber, const QVector<int> &
}
}
// search all devices for a QQuickPointerEvent instance that is delivering the point with id
- const auto touchDevices = QQuickPointerDevice::touchDevices();
- for (auto device : touchDevices) {
- QQuickPointerEvent *pev = pointerEventInstance(device);
+ const auto devs = QPointingDevice::devices();
+ for (auto device : devs) {
+ if (device->type() != QInputDevice::DeviceType::TouchScreen)
+ continue;
+ QQuickPointerEvent *pev = pointerEventInstance(static_cast<const QPointingDevice *>(device));
auto point = pev->pointById(id);
if (point) {
ev = pev;
@@ -1087,7 +1091,7 @@ void QQuickWindowPrivate::removeGrabber(QQuickItem *grabber, bool mouse, bool to
bool fromTouch = isDeliveringTouchAsMouse();
auto point = fromTouch ?
pointerEventInstance(touchMouseDevice)->pointById(touchMouseId) :
- pointerEventInstance(QQuickPointerDevice::genericMouseDevice())->point(0);
+ pointerEventInstance(QPointingDevice::primaryPointingDevice())->point(0);
QQuickItem *oldGrabber = point->grabberItem();
qCDebug(DBG_MOUSE_TARGET) << "removeGrabber" << oldGrabber << "-> null";
point->setGrabberItem(nullptr);
@@ -1095,9 +1099,11 @@ void QQuickWindowPrivate::removeGrabber(QQuickItem *grabber, bool mouse, bool to
}
if (Q_LIKELY(touch)) {
bool ungrab = false;
- const auto touchDevices = QQuickPointerDevice::touchDevices();
+ const auto touchDevices = QPointingDevice::devices();
for (auto device : touchDevices) {
- if (auto pointerEvent = queryPointerEventInstance(device)) {
+ if (device->type() != QInputDevice::DeviceType::TouchScreen)
+ continue;
+ if (auto pointerEvent = queryPointerEventInstance(static_cast<const QPointingDevice *>(device))) {
for (int i = 0; i < pointerEvent->pointCount(); ++i) {
if (pointerEvent->point(i)->exclusiveGrabber() == grabber) {
pointerEvent->point(i)->setGrabberItem(nullptr);
@@ -1871,6 +1877,7 @@ QObject *QQuickWindow::focusObject() const
/*!
Returns the item which currently has the mouse grab.
*/
+// TODO deprecate this, or take seat name as an argument
QQuickItem *QQuickWindow::mouseGrabberItem() const
{
Q_D(const QQuickWindow);
@@ -1880,9 +1887,21 @@ QQuickItem *QQuickWindow::mouseGrabberItem() const
auto point = event->pointById(d->touchMouseId);
return point ? point->grabberItem() : nullptr;
}
- } else if (QQuickPointerEvent *event = d->queryPointerEventInstance(QQuickPointerDevice::genericMouseDevice())) {
- Q_ASSERT(event->pointCount());
- return event->point(0)->grabberItem();
+ } else {
+ const QPointingDevice *mouse = QPointingDevice::primaryPointingDevice();
+ if (mouse->type() != QInputDevice::DeviceType::Mouse) {
+ // TODO don't assume the first mouse is the core pointer (but so far there is normally only one)
+ for (const auto *dev : QInputDevice::devices()) {
+ if (dev->type() == QInputDevice::DeviceType::Mouse) {
+ mouse = static_cast<const QPointingDevice *>(dev);
+ break;
+ }
+ }
+ }
+ if (QQuickPointerEvent *event = d->queryPointerEventInstance(mouse)) {
+ Q_ASSERT(event->pointCount());
+ return event->point(0)->grabberItem();
+ }
}
return nullptr;
}
@@ -1903,8 +1922,9 @@ bool QQuickWindowPrivate::clearHover(ulong timestamp)
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
if (itemPrivate->hasPointerHandlers()) {
pos = q->mapFromGlobal(QCursor::pos());
- QQuickPointerEvent *pointerEvent = pointerEventInstance(QQuickPointerDevice::genericMouseDevice(), QEvent::MouseMove);
- pointerEvent->point(0)->reset(Qt::TouchPointMoved, pos, quint64(1) << 24 /* mouse has device ID 1 */, timestamp, QVector2D());
+ const auto dev = QPointingDevice::primaryPointingDevice();
+ QQuickPointerEvent *pointerEvent = pointerEventInstance(dev, QEvent::MouseMove);
+ pointerEvent->point(0)->reset(Qt::TouchPointMoved, pos, int(dev->id()), timestamp, QVector2D());
pointerEvent->point(0)->setAccepted(true);
pointerEvent->localize(item);
for (QQuickPointerHandler *h : itemPrivate->extra->pointerHandlers)
@@ -1946,9 +1966,9 @@ bool QQuickWindow::event(QEvent *e)
return false;
QEnterEvent *enter = static_cast<QEnterEvent*>(e);
bool accepted = enter->isAccepted();
- bool delivered = d->deliverHoverEvent(d->contentItem, enter->windowPos(), d->lastMousePosition,
+ bool delivered = d->deliverHoverEvent(d->contentItem, enter->scenePosition(), d->lastMousePosition,
QGuiApplication::keyboardModifiers(), 0L, accepted);
- d->lastMousePosition = enter->windowPos();
+ d->lastMousePosition = enter->scenePosition();
enter->setAccepted(accepted);
#if QT_CONFIG(cursor)
d->updateCursor(mapFromGlobal(QCursor::pos()));
@@ -2092,7 +2112,8 @@ QMouseEvent *QQuickWindowPrivate::cloneMouseEvent(QMouseEvent *event, QPointF *t
void QQuickWindowPrivate::deliverToPassiveGrabbers(const QVector<QPointer <QQuickPointerHandler> > &passiveGrabbers,
QQuickPointerEvent *pointerEvent)
{
- const QVector<QQuickPointerHandler *> &eventDeliveryTargets = pointerEvent->device()->eventDeliveryTargets();
+ const QVector<QObject *> &eventDeliveryTargets =
+ QQuickPointerHandlerPrivate::deviceDeliveryTargets(pointerEvent->device());
QVarLengthArray<QPair<QQuickItem *, bool>, 4> sendFilteredPointerEventResult;
hasFiltered.clear();
for (auto handler : passiveGrabbers) {
@@ -2173,7 +2194,7 @@ void QQuickWindowPrivate::deliverMouseEvent(QQuickPointerMouseEvent *pointerEven
if (pointerEvent->isPressEvent()) {
// send initial press
delivered = deliverPressOrReleaseEvent(pointerEvent);
- } else if (pointerEvent->device()->type() == QQuickPointerDevice::Mouse) {
+ } else if (pointerEvent->device()->type() == QInputDevice::DeviceType::Mouse) {
// if this is an update or release from an actual mouse,
// and the point wasn't grabbed, deliver only to PointerHandlers:
// passive grabbers first, then the rest
@@ -2250,8 +2271,9 @@ bool QQuickWindowPrivate::deliverHoverEvent(QQuickItem *item, const QPointF &sce
}
if (itemPrivate->hasPointerHandlers()) {
- QQuickPointerEvent *pointerEvent = pointerEventInstance(QQuickPointerDevice::genericMouseDevice(), QEvent::MouseMove);
- pointerEvent->point(0)->reset(Qt::TouchPointMoved, scenePos, quint64(1) << 24 /* mouse has device ID 1 */, timestamp, QVector2D());
+ const auto dev = QPointingDevice::primaryPointingDevice();
+ QQuickPointerEvent *pointerEvent = pointerEventInstance(dev, QEvent::MouseMove);
+ pointerEvent->point(0)->reset(Qt::TouchPointMoved, scenePos, dev->id(), timestamp, QVector2D());
pointerEvent->point(0)->setAccepted(true);
pointerEvent->localize(item);
for (QQuickPointerHandler *h : itemPrivate->extra->pointerHandlers)
@@ -2345,7 +2367,7 @@ bool QQuickWindowPrivate::deliverSinglePointEventUntilAccepted(QQuickPointerEven
#endif
#if QT_CONFIG(gestures)
if (QQuickPointerNativeGestureEvent *pnge = event->asPointerNativeGestureEvent()) {
- QNativeGestureEvent nge(pnge->type(), pnge->device()->qTouchDevice(), point->position(), point->scenePosition(), g,
+ QNativeGestureEvent nge(pnge->type(), pnge->device(), point->position(), point->scenePosition(), g,
pnge->value(), 0L, 0L); // TODO can't copy things I can't access
nge.accept();
QCoreApplication::sendEvent(item, &nge);
@@ -2403,7 +2425,7 @@ bool QQuickWindowPrivate::deliverTouchCancelEvent(QTouchEvent *event)
// A TouchCancel event will typically not contain any points.
// Deliver it to all items and handlers that have active touches.
- QQuickPointerEvent *pointerEvent = pointerEventInstance(QQuickPointerDevice::touchDevice(event->device()));
+ QQuickPointerEvent *pointerEvent = pointerEventInstance(event->pointingDevice());
for (int i = 0; i < pointerEvent->pointCount(); ++i)
pointerEvent->point(i)->cancelExclusiveGrabImpl(event);
@@ -2432,7 +2454,7 @@ bool QQuickWindowPrivate::compressTouchEvent(QTouchEvent *event)
}
if (!delayedTouch) {
- delayedTouch.reset(new QTouchEvent(event->type(), event->device(), event->modifiers(), event->touchPointStates(), event->touchPoints()));
+ delayedTouch.reset(new QTouchEvent(event->type(), event->pointingDevice(), event->modifiers(), event->touchPointStates(), event->touchPoints()));
delayedTouch->setTimestamp(event->timestamp());
if (renderControl)
QQuickRenderControlPrivate::get(renderControl)->maybeUpdate();
@@ -2480,7 +2502,8 @@ bool QQuickWindowPrivate::compressTouchEvent(QTouchEvent *event)
// merging wasn't possible, so deliver the delayed event first, and then delay this one
deliverDelayedTouchEvent();
- delayedTouch.reset(new QTouchEvent(event->type(), event->device(), event->modifiers(), event->touchPointStates(), event->touchPoints()));
+ delayedTouch.reset(new QTouchEvent(event->type(), event->pointingDevice(),
+ event->modifiers(), event->touchPointStates(), event->touchPoints()));
delayedTouch->setTimestamp(event->timestamp());
return true;
}
@@ -2567,17 +2590,17 @@ void QQuickWindowPrivate::handleMouseEvent(QMouseEvent *event)
if (allowDoubleClick)
deliverPointerEvent(pointerEventInstance(event));
break;
- case QEvent::MouseMove:
+ case QEvent::MouseMove: {
Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMouseMove,
- event->position().x(), event->localPos().y());
+ event->position().x(), event->position().y());
qCDebug(DBG_HOVER_TRACE) << this;
#if QT_CONFIG(cursor)
updateCursor(event->scenePosition());
#endif
-
- if (!pointerEventInstance(QQuickPointerDevice::genericMouseDevice())->point(0)->exclusiveGrabber()) {
+ auto pointerEvent = pointerEventInstance(event->pointingDevice());
+ if (!pointerEvent->pointCount() || !pointerEvent->point(0)->exclusiveGrabber()) {
QPointF last = lastMousePosition.isNull() ? event->scenePosition() : lastMousePosition;
lastMousePosition = event->scenePosition();
@@ -2591,6 +2614,7 @@ void QQuickWindowPrivate::handleMouseEvent(QMouseEvent *event)
}
deliverPointerEvent(pointerEventInstance(event));
break;
+ }
default:
Q_ASSERT(false);
break;
@@ -2624,7 +2648,7 @@ void QQuickWindowPrivate::flushFrameSynchronousEvents()
}
}
-QQuickPointerEvent *QQuickWindowPrivate::queryPointerEventInstance(QQuickPointerDevice *device, QEvent::Type eventType) const
+QQuickPointerEvent *QQuickWindowPrivate::queryPointerEventInstance(const QPointingDevice *device, QEvent::Type eventType) const
{
// Search for a matching reusable event object.
for (QQuickPointerEvent *e : pointerEventInstances) {
@@ -2645,24 +2669,24 @@ QQuickPointerEvent *QQuickWindowPrivate::queryPointerEventInstance(QQuickPointer
return nullptr;
}
-QQuickPointerEvent *QQuickWindowPrivate::pointerEventInstance(QQuickPointerDevice *device, QEvent::Type eventType) const
+QQuickPointerEvent *QQuickWindowPrivate::pointerEventInstance(const QPointingDevice *device, QEvent::Type eventType) const
{
QQuickPointerEvent *ev = queryPointerEventInstance(device, eventType);
if (ev)
return ev;
QQuickWindow *q = const_cast<QQuickWindow*>(q_func());
switch (device->type()) {
- case QQuickPointerDevice::Mouse:
+ case QInputDevice::DeviceType::Mouse:
// QWindowSystemInterface::handleMouseEvent() does not take a device parameter:
// we assume all mouse events come from one mouse (the "core pointer").
- // So when the event is a mouse event, device == QQuickPointerDevice::genericMouseDevice()
+ // So when the event is a mouse event, device == QPointingDevice::primaryPointingDevice()
if (eventType == QEvent::Wheel)
ev = new QQuickPointerScrollEvent(q, device);
else
ev = new QQuickPointerMouseEvent(q, device);
break;
- case QQuickPointerDevice::TouchPad:
- case QQuickPointerDevice::TouchScreen:
+ case QInputDevice::DeviceType::TouchPad:
+ case QInputDevice::DeviceType::TouchScreen:
#if QT_CONFIG(gestures)
if (eventType == QEvent::NativeGesture)
ev = new QQuickPointerNativeGestureEvent(q, device);
@@ -2671,9 +2695,9 @@ QQuickPointerEvent *QQuickWindowPrivate::pointerEventInstance(QQuickPointerDevic
ev = new QQuickPointerTouchEvent(q, device);
break;
#if QT_CONFIG(tabletevent)
- case QQuickPointerDevice::Stylus:
- case QQuickPointerDevice::Airbrush:
- case QQuickPointerDevice::Puck:
+ case QInputDevice::DeviceType::Stylus:
+ case QPointingDevice::DeviceType::Airbrush:
+ case QPointingDevice::DeviceType::Puck:
ev = new QQuickPointerTabletEvent(q, device);
break;
#endif
@@ -2688,40 +2712,34 @@ QQuickPointerEvent *QQuickWindowPrivate::pointerEventInstance(QQuickPointerDevic
\internal
Returns a QQuickPointerEvent instance suitable for wrapping and delivering \a event.
- There is a unique instance per QQuickPointerDevice, which is determined
+ There is a unique instance per QPointingDevice, which is determined
from \a event's device.
*/
QQuickPointerEvent *QQuickWindowPrivate::pointerEventInstance(QEvent *event) const
{
- QQuickPointerDevice *dev = nullptr;
+ const QPointingDevice *dev = nullptr;
switch (event->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
case QEvent::MouseMove:
case QEvent::Wheel:
- dev = QQuickPointerDevice::genericMouseDevice();
- break;
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
case QEvent::TouchCancel:
- dev = QQuickPointerDevice::touchDevice(static_cast<QTouchEvent *>(event)->device());
- break;
#if QT_CONFIG(tabletevent)
case QEvent::TabletPress:
case QEvent::TabletMove:
case QEvent::TabletRelease:
case QEvent::TabletEnterProximity:
case QEvent::TabletLeaveProximity:
- dev = QQuickPointerDevice::tabletDevice(static_cast<QTabletEvent *>(event));
- break;
#endif
#if QT_CONFIG(gestures)
case QEvent::NativeGesture:
- dev = QQuickPointerDevice::touchDevice(static_cast<QNativeGestureEvent *>(event)->device());
- break;
#endif
+ dev = static_cast<QPointerEvent *>(event)->pointingDevice();
+ break;
default:
break;
}
@@ -3356,8 +3374,8 @@ bool QQuickWindowPrivate::sendFilteredPointerEventImpl(QQuickPointerEvent *event
bool acceptsTouchEvents = false;
#endif
auto device = pte->device();
- if (device->type() == QQuickPointerDevice::TouchPad &&
- device->capabilities().testFlag(QQuickPointerDevice::MouseEmulation)) {
+ if (device->type() == QInputDevice::DeviceType::TouchPad &&
+ device->capabilities().testFlag(QInputDevice::Capability::MouseEmulation)) {
qCDebug(DBG_TOUCH_TARGET) << "skipping filtering of synth-mouse event from" << device;
} else if (acceptsTouchEvents || receiver->acceptedMouseButtons()) {
// get a touch event customized for delivery to filteringParent
@@ -3403,7 +3421,7 @@ bool QQuickWindowPrivate::sendFilteredPointerEventImpl(QQuickPointerEvent *event
// touchMouseId and touchMouseDevice must be set, even if it's only temporarily and isn't grabbed.
touchMouseId = tp.id();
touchMouseDevice = event->device();
- QQuickPointerDevice *dev = touchMouseDevice;
+ const QPointingDevice *dev = touchMouseDevice;
if (filteringParent->childMouseEventFilter(receiver, mouseEvent.data())) {
qCDebug(DBG_TOUCH) << "touch event intercepted as synth mouse event by childMouseEventFilter of " << filteringParent;
skipDelivery.append(filteringParent);
@@ -3460,7 +3478,7 @@ bool QQuickWindowPrivate::dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent
{
QStyleHints *styleHints = QGuiApplication::styleHints();
int caps = QGuiApplicationPrivate::mouseEventCaps(event);
- bool dragVelocityLimitAvailable = (caps & QTouchDevice::Velocity)
+ bool dragVelocityLimitAvailable = (caps & int(QInputDevice::Capability::Velocity))
&& styleHints->startDragVelocity();
bool overThreshold = qAbs(d) > (startDragThreshold >= 0 ? startDragThreshold : styleHints->startDragDistance());
if (dragVelocityLimitAvailable) {
diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h
index 703e29d160..643e7db9a2 100644
--- a/src/quick/items/qquickwindow_p.h
+++ b/src/quick/items/qquickwindow_p.h
@@ -76,7 +76,7 @@ class QOpenGLContext;
class QQuickAnimatorController;
class QQuickDragGrabber;
class QQuickItemPrivate;
-class QQuickPointerDevice;
+class QPointingDevice;
class QQuickRenderControl;
class QQuickWindowIncubationController;
class QQuickWindowPrivate;
@@ -150,7 +150,7 @@ public:
QQuickDragGrabber *dragGrabber;
#endif
int touchMouseId;
- QQuickPointerDevice *touchMouseDevice;
+ const QPointingDevice *touchMouseDevice;
bool checkIfDoubleTapped(ulong newPressEventTimestamp, QPoint newPressPos);
ulong touchMousePressTimestamp;
QPoint touchMousePressPos; // in screen coordiantes
@@ -181,8 +181,8 @@ public:
// the device-specific event instances which are reused during event delivery
mutable QVector<QQuickPointerEvent *> pointerEventInstances;
- QQuickPointerEvent *queryPointerEventInstance(QQuickPointerDevice *device, QEvent::Type eventType = QEvent::None) const;
- QQuickPointerEvent *pointerEventInstance(QQuickPointerDevice *device, QEvent::Type eventType = QEvent::None) const;
+ QQuickPointerEvent *queryPointerEventInstance(const QPointingDevice *device, QEvent::Type eventType = QEvent::None) const;
+ QQuickPointerEvent *pointerEventInstance(const QPointingDevice *device, QEvent::Type eventType = QEvent::None) const;
// delivery of pointer events:
QQuickPointerEvent *pointerEventInstance(QEvent *ev) const;
diff --git a/tests/auto/quick/pointerhandlers/flickableinterop/tst_flickableinterop.cpp b/tests/auto/quick/pointerhandlers/flickableinterop/tst_flickableinterop.cpp
index f4ed051e1f..2cdbaf3bf6 100644
--- a/tests/auto/quick/pointerhandlers/flickableinterop/tst_flickableinterop.cpp
+++ b/tests/auto/quick/pointerhandlers/flickableinterop/tst_flickableinterop.cpp
@@ -82,7 +82,7 @@ private slots:
private:
void createView(QScopedPointer<QQuickView> &window, const char *fileName);
- QTouchDevice *touchDevice;
+ QPointingDevice *touchDevice;
};
void tst_FlickableInterop::createView(QScopedPointer<QQuickView> &window, const char *fileName)
diff --git a/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp b/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp
index 794562fea0..26b6e0540b 100644
--- a/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp
+++ b/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp
@@ -45,8 +45,6 @@ class tst_MouseAreaInterop : public QQmlDataTest
Q_OBJECT
public:
tst_MouseAreaInterop()
- : touchDevice(QTest::createTouchDevice())
- , touchPointerDevice(QQuickPointerDevice::touchDevice(touchDevice))
{}
private slots:
@@ -56,8 +54,7 @@ private slots:
private:
void createView(QScopedPointer<QQuickView> &window, const char *fileName);
- QTouchDevice *touchDevice;
- QQuickPointerDevice *touchPointerDevice;
+ QPointingDevice *touchDevice = QTest::createTouchDevice();
};
void tst_MouseAreaInterop::createView(QScopedPointer<QQuickView> &window, const char *fileName)
@@ -79,7 +76,7 @@ void tst_MouseAreaInterop::dragHandlerInSiblingStealingGrabFromMouseAreaViaMouse
QScopedPointer<QQuickView> windowPtr;
createView(windowPtr, "dragTakeOverFromSibling.qml");
QQuickView * window = windowPtr.data();
- auto pointerEvent = QQuickWindowPrivate::get(window)->pointerEventInstance(QQuickPointerDevice::genericMouseDevice());
+ auto pointerEvent = QQuickWindowPrivate::get(window)->pointerEventInstance(QPointingDevice::primaryPointingDevice());
QPointer<QQuickPointerHandler> handler = window->rootObject()->findChild<QQuickPointerHandler*>();
QVERIFY(handler);
@@ -127,7 +124,7 @@ void tst_MouseAreaInterop::dragHandlerInSiblingStealingGrabFromMouseAreaViaTouch
QScopedPointer<QQuickView> windowPtr;
createView(windowPtr, "dragTakeOverFromSibling.qml");
QQuickView * window = windowPtr.data();
- auto pointerEvent = QQuickWindowPrivate::get(window)->pointerEventInstance(touchPointerDevice);
+ auto pointerEvent = QQuickWindowPrivate::get(window)->pointerEventInstance(touchDevice);
QPointer<QQuickPointerHandler> handler = window->rootObject()->findChild<QQuickPointerHandler*>();
QVERIFY(handler);
diff --git a/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp b/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp
index 4a7a132be2..82e9b4e71f 100644
--- a/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp
+++ b/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp
@@ -46,8 +46,6 @@ class tst_MptaInterop : public QQmlDataTest
Q_OBJECT
public:
tst_MptaInterop()
- : touchDevice(QTest::createTouchDevice())
- , touchPointerDevice(QQuickPointerDevice::touchDevice(touchDevice))
{}
private slots:
@@ -60,8 +58,7 @@ private slots:
private:
void createView(QScopedPointer<QQuickView> &window, const char *fileName);
- QTouchDevice *touchDevice;
- QQuickPointerDevice *touchPointerDevice;
+ QPointingDevice *touchDevice = QTest::createTouchDevice();
};
void tst_MptaInterop::createView(QScopedPointer<QQuickView> &window, const char *fileName)
@@ -111,7 +108,7 @@ void tst_MptaInterop::touchDrag()
QPoint p1 = mpta->mapToScene(QPointF(20, 20)).toPoint();
touch.press(1, p1).commit();
QQuickTouchUtils::flush(window);
- auto pointerEvent = QQuickWindowPrivate::get(window)->pointerEventInstance(touchPointerDevice);
+ auto pointerEvent = QQuickWindowPrivate::get(window)->pointerEventInstance(touchDevice);
QCOMPARE(tp.at(0)->property("pressed").toBool(), true);
QTRY_VERIFY(pointerEvent->point(0)->passiveGrabbers().contains(drag));
@@ -153,7 +150,7 @@ void tst_MptaInterop::touchesThenPinch()
QSignalSpy mptaReleasedSpy(mpta, SIGNAL(released(QList<QObject*>)));
QSignalSpy mptaCanceledSpy(mpta, SIGNAL(canceled(QList<QObject*>)));
QTest::QTouchEventSequence touch = QTest::touchEvent(window, touchDevice);
- auto pointerEvent = QQuickWindowPrivate::get(window)->pointerEventInstance(touchPointerDevice);
+ auto pointerEvent = QQuickWindowPrivate::get(window)->pointerEventInstance(touchDevice);
// Press one touchpoint:
// DragHandler gets a passive grab
@@ -307,7 +304,7 @@ void tst_MptaInterop::dragHandlerInParentStealingGrabFromItem() // QTBUG-75025
QScopedPointer<QQuickView> windowPtr;
createView(windowPtr, "dragParentOfMPTA.qml");
QQuickView * window = windowPtr.data();
- auto pointerEvent = QQuickWindowPrivate::get(window)->pointerEventInstance(QQuickPointerDevice::genericMouseDevice());
+ auto pointerEvent = QQuickWindowPrivate::get(window)->pointerEventInstance(QPointingDevice::primaryPointingDevice());
QPointer<QQuickPointerHandler> handler = window->rootObject()->findChild<QQuickPointerHandler*>();
QVERIFY(handler);
diff --git a/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp b/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp
index 47cfd27817..f6faa97b37 100644
--- a/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp
@@ -72,7 +72,7 @@ private slots:
private:
void createView(QScopedPointer<QQuickView> &window, const char *fileName);
QSet<QQuickPointerHandler *> passiveGrabbers(QQuickWindow *window, int pointId = 0);
- QTouchDevice *touchDevice;
+ QPointingDevice *touchDevice;
};
void tst_DragHandler::createView(QScopedPointer<QQuickView> &window, const char *fileName)
@@ -92,15 +92,13 @@ QSet<QQuickPointerHandler*> tst_DragHandler::passiveGrabbers(QQuickWindow *windo
{
QSet<QQuickPointerHandler*> result;
QQuickWindowPrivate *winp = QQuickWindowPrivate::get(window);
- if (QQuickPointerDevice* device = QQuickPointerDevice::touchDevice(touchDevice)) {
- QQuickPointerEvent *pointerEvent = winp->pointerEventInstance(device);
- for (int i = 0; i < pointerEvent->pointCount(); ++i) {
- QQuickEventPoint *eventPoint = pointerEvent->point(i);
- QVector<QPointer <QQuickPointerHandler> > passives = eventPoint->passiveGrabbers();
- if (!pointId || eventPoint->pointId() == pointId) {
- for (auto it = passives.constBegin(); it != passives.constEnd(); ++it)
- result << it->data();
- }
+ QQuickPointerEvent *pointerEvent = winp->pointerEventInstance(touchDevice);
+ for (int i = 0; i < pointerEvent->pointCount(); ++i) {
+ QQuickEventPoint *eventPoint = pointerEvent->point(i);
+ QVector<QPointer <QQuickPointerHandler> > passives = eventPoint->passiveGrabbers();
+ if (!pointId || eventPoint->pointId() == pointId) {
+ for (auto it = passives.constBegin(); it != passives.constEnd(); ++it)
+ result << it->data();
}
}
return result;
diff --git a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
index 19fdae3b44..0c300cfd4e 100644
--- a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp
@@ -43,9 +43,8 @@ class tst_QQuickPinchHandler: public QQmlDataTest
{
Q_OBJECT
public:
- tst_QQuickPinchHandler() : device(0) { }
+ tst_QQuickPinchHandler() { }
private slots:
- void initTestCase();
void cleanupTestCase();
void pinchProperties();
void scale();
@@ -60,17 +59,8 @@ private slots:
private:
QQuickView *createView();
- QTouchDevice *device;
+ QPointingDevice *device = QTest::createTouchDevice();
};
-void tst_QQuickPinchHandler::initTestCase()
-{
- QQmlDataTest::initTestCase();
- if (!device) {
- device = new QTouchDevice;
- device->setType(QTouchDevice::TouchScreen);
- QWindowSystemInterface::registerTouchDevice(device);
- }
-}
void tst_QQuickPinchHandler::cleanupTestCase()
{
@@ -677,8 +667,7 @@ void tst_QQuickPinchHandler::cancel()
QSKIP("cancel is not supported atm");
- QTouchEvent cancelEvent(QEvent::TouchCancel);
- cancelEvent.setDevice(device);
+ QTouchEvent cancelEvent(QEvent::TouchCancel, device);
QCoreApplication::sendEvent(window, &cancelEvent);
QQuickTouchUtils::flush(window);
diff --git a/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp
index 7bfaac318f..cb20168c1d 100644
--- a/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp
@@ -230,7 +230,7 @@ class tst_PointerHandlers : public QQmlDataTest
Q_OBJECT
public:
tst_PointerHandlers()
- :touchDevice(QTest::createTouchDevice())
+ : touchDevice(QTest::createTouchDevice())
{}
private slots:
@@ -271,7 +271,7 @@ protected:
private:
void createView(QScopedPointer<QQuickView> &window, const char *fileName);
- QTouchDevice *touchDevice;
+ QPointingDevice *touchDevice;
QList<Event> filteredEventList;
};
@@ -343,7 +343,7 @@ void tst_PointerHandlers::touchEventDelivery()
QCOMPARE(eventItem1->eventList.size(), 2);
QCOMPARE_EVENT(0, Event::HandlerDestination, QEvent::Pointer, Qt::TouchPointPressed, NoGrab);
QCOMPARE_EVENT(1, Event::TouchDestination, QEvent::TouchBegin, Qt::TouchPointPressed, QQuickEventPoint::GrabExclusive);
- auto pointerEvent = QQuickWindowPrivate::get(window)->pointerEventInstance(QQuickPointerDevice::touchDevices().at(0));
+ auto pointerEvent = QQuickWindowPrivate::get(window)->pointerEventInstance(touchDevice);
QCOMPARE(pointerEvent->point(0)->exclusiveGrabber(), eventItem1);
p1 += QPoint(10, 0);
QTest::touchEvent(window, touchDevice).move(0, p1, window);
diff --git a/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp
index ca6463f365..900202f132 100644
--- a/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp
@@ -62,7 +62,7 @@ private slots:
private:
void createView(QScopedPointer<QQuickView> &window, const char *fileName);
- QTouchDevice *touchDevice;
+ QPointingDevice *touchDevice;
};
void tst_PointHandler::createView(QScopedPointer<QQuickView> &window, const char *fileName)
@@ -145,7 +145,7 @@ void tst_PointHandler::tabletStylus()
QQuickView * window = windowPtr.data();
QQuickPointHandler *handler = window->rootObject()->findChild<QQuickPointHandler *>("pointHandler");
QVERIFY(handler);
- handler->setAcceptedDevices(QQuickPointerDevice::Stylus);
+ handler->setAcceptedDevices(QInputDevice::DeviceType::Stylus);
QSignalSpy activeSpy(handler, SIGNAL(activeChanged()));
QSignalSpy pointSpy(handler, SIGNAL(pointChanged()));
@@ -155,7 +155,7 @@ void tst_PointHandler::tabletStylus()
const qint64 stylusId = 1234567890;
QWindowSystemInterface::handleTabletEvent(window, point, window->mapToGlobal(point),
- QTabletEvent::Stylus, QTabletEvent::Pen, Qt::LeftButton, 0.5, 25, 35, 0.6, 12.3, 3, stylusId, Qt::NoModifier);
+ int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), Qt::LeftButton, 0.5, 25, 35, 0.6, 12.3, 3, stylusId, Qt::NoModifier);
QTRY_COMPARE(handler->active(), true);
QCOMPARE(activeSpy.count(), 1);
QCOMPARE(pointSpy.count(), 1);
@@ -170,7 +170,7 @@ void tst_PointHandler::tabletStylus()
point += QPoint(10, 10);
QWindowSystemInterface::handleTabletEvent(window, point, window->mapToGlobal(point),
- QTabletEvent::Stylus, QTabletEvent::Pen, Qt::LeftButton, 0.45, 23, 33, 0.57, 15.6, 3.4, stylusId, Qt::NoModifier);
+ int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), Qt::LeftButton, 0.45, 23, 33, 0.57, 15.6, 3, stylusId, Qt::NoModifier);
QTRY_COMPARE(pointSpy.count(), 2);
QCOMPARE(handler->active(), true);
QCOMPARE(activeSpy.count(), 1);
@@ -188,7 +188,7 @@ void tst_PointHandler::tabletStylus()
QCOMPARE(translationSpy.count(), 2);
QWindowSystemInterface::handleTabletEvent(window, point, window->mapToGlobal(point),
- QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, stylusId, Qt::NoModifier);
+ int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), Qt::NoButton, 0, 0, 0, 0, 0, 0, stylusId, Qt::NoModifier);
QTRY_COMPARE(handler->active(), false);
QCOMPARE(activeSpy.count(), 2);
QCOMPARE(pointSpy.count(), 3);
diff --git a/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp b/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp
index 419afed3ac..32a68293c2 100644
--- a/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp
+++ b/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp
@@ -51,7 +51,6 @@ class tst_TapHandler : public QQmlDataTest
Q_OBJECT
public:
tst_TapHandler()
- :touchDevice(QTest::createTouchDevice())
{}
private slots:
@@ -74,7 +73,7 @@ private slots:
private:
void createView(QScopedPointer<QQuickView> &window, const char *fileName);
- QTouchDevice *touchDevice;
+ QPointingDevice *touchDevice = QTest::createTouchDevice();
};
void tst_TapHandler::createView(QScopedPointer<QQuickView> &window, const char *fileName)
diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
index 9f7cfa842e..dcf5a0b09e 100644
--- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
+++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
@@ -149,7 +149,6 @@ class tst_qquickflickable : public QQmlDataTest
Q_OBJECT
public:
tst_qquickflickable()
- : touchDevice(QTest::createTouchDevice())
{}
private slots:
@@ -209,7 +208,7 @@ private slots:
private:
void flickWithTouch(QQuickWindow *window, const QPoint &from, const QPoint &to);
- QTouchDevice *touchDevice;
+ QPointingDevice *touchDevice = QTest::createTouchDevice();
};
void tst_qquickflickable::initTestCase()
diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp
index 77f183ad2a..924a1d2c4e 100644
--- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp
@@ -1337,12 +1337,7 @@ void tst_qquickitem::touchEventAcceptIgnore()
item->setParentItem(window.contentItem());
item->acceptIncomingTouchEvents = itemSupportsTouch;
- static QTouchDevice* device = nullptr;
- if (!device) {
- device =new QTouchDevice;
- device->setType(QTouchDevice::TouchScreen);
- QWindowSystemInterface::registerTouchDevice(device);
- }
+ static QPointingDevice* device = QTest::createTouchDevice();
// Send Begin, Update & End touch sequence
{
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
index 56c3f370d2..4f504103d4 100644
--- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
@@ -352,7 +352,7 @@ private:
QQuickView *m_view;
QString testForView;
- QTouchDevice *touchDevice = QTest::createTouchDevice();
+ QPointingDevice *touchDevice = QTest::createTouchDevice();
};
class TestObject : public QObject
@@ -9673,8 +9673,7 @@ void tst_QQuickListView::touchCancel() // QTBUG-74679
// and because Flickable filtered it, QQuickFlickablePrivate::pressed
// should be true, but it's not easily tested here
- QTouchEvent cancelEvent(QEvent::TouchCancel);
- cancelEvent.setDevice(touchDevice);
+ QTouchEvent cancelEvent(QEvent::TouchCancel, touchDevice);
QCoreApplication::sendEvent(window.data(), &cancelEvent);
// now QQuickWindowPrivate::sendUngrabEvent() will be called, Flickable will filter it,
// QQuickFlickablePrivate::pressed will be set to false, and that will allow setCurrentIndex() to make it move
diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
index 5879fc6897..1d22680261 100644
--- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
+++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
@@ -94,14 +94,12 @@ class tst_QQuickMouseArea: public QQmlDataTest
Q_OBJECT
public:
tst_QQuickMouseArea()
- : device(nullptr)
{
qmlRegisterType<CircleMask>("Test", 1, 0, "CircleMask");
qmlRegisterType<EventSender>("Test", 1, 0, "EventSender");
}
private slots:
- void initTestCase() override;
void dragProperties();
void resetDrag();
void dragging_data() { acceptedButton_data(); }
@@ -166,22 +164,12 @@ private:
}
void acceptedButton_data();
void rejectedButton_data();
- QTouchDevice *device;
+ QPointingDevice *device = QTest::createTouchDevice();
};
Q_DECLARE_METATYPE(Qt::MouseButton)
Q_DECLARE_METATYPE(Qt::MouseButtons)
-void tst_QQuickMouseArea::initTestCase()
-{
- QQmlDataTest::initTestCase();
- if (!device) {
- device = new QTouchDevice;
- device->setType(QTouchDevice::TouchScreen);
- QWindowSystemInterface::registerTouchDevice(device);
- }
-}
-
void tst_QQuickMouseArea::acceptedButton_data()
{
QTest::addColumn<Qt::MouseButtons>("acceptedButtons");
diff --git a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp
index c18a220996..04a44a2c10 100644
--- a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp
+++ b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp
@@ -47,14 +47,6 @@ public:
tst_QQuickMultiPointTouchArea() { }
private slots:
- void initTestCase() {
- QQmlDataTest::initTestCase();
- if (!device) {
- device = new QTouchDevice;
- device->setType(QTouchDevice::TouchScreen);
- QWindowSystemInterface::registerTouchDevice(device);
- }
- }
void cleanupTestCase() {}
void properties();
@@ -80,7 +72,7 @@ private slots:
private:
QQuickView *createAndShowView(const QString &file);
- QTouchDevice *device = nullptr;
+ QPointingDevice *device = QTest::createTouchDevice();
};
void tst_QQuickMultiPointTouchArea::properties()
@@ -838,7 +830,7 @@ void tst_QQuickMultiPointTouchArea::inFlickableWithPressDelay() // QTBUG-78818
QTest::touchEvent(window.data(), device).press(0, p1);
QQuickTouchUtils::flush(window.data());
QTRY_COMPARE(point11->pressed(), true);
- auto pointerEvent = windowPriv->pointerEventInstance(QQuickPointerDevice::touchDevices().at(0));
+ auto pointerEvent = windowPriv->pointerEventInstance(device);
QCOMPARE(pointerEvent->point(0)->exclusiveGrabber(), mpta);
// release: MPTA receives TouchEnd (which is asymmetric with mouse press); does NOT emit canceled.
diff --git a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp
index 5b7108d96b..3213d49dd5 100644
--- a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp
+++ b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp
@@ -43,7 +43,6 @@ class tst_QQuickPinchArea: public QQmlDataTest
public:
tst_QQuickPinchArea() { }
private slots:
- void initTestCase();
void cleanupTestCase();
void pinchProperties();
void scale();
@@ -55,17 +54,8 @@ private slots:
private:
QQuickView *createView();
- QTouchDevice *device = nullptr;
+ QPointingDevice *device = QTest::createTouchDevice();
};
-void tst_QQuickPinchArea::initTestCase()
-{
- QQmlDataTest::initTestCase();
- if (!device) {
- device = new QTouchDevice;
- device->setType(QTouchDevice::TouchScreen);
- QWindowSystemInterface::registerTouchDevice(device);
- }
-}
void tst_QQuickPinchArea::cleanupTestCase()
{
@@ -510,8 +500,7 @@ void tst_QQuickPinchArea::cancel()
QCOMPARE(root->property("center").toPointF(), QPointF(40, 40)); // blackrect is at 50,50
QCOMPARE(blackRect->scale(), 1.5);
- QTouchEvent cancelEvent(QEvent::TouchCancel);
- cancelEvent.setDevice(device);
+ QTouchEvent cancelEvent(QEvent::TouchCancel, device);
QCoreApplication::sendEvent(window, &cancelEvent);
QQuickTouchUtils::flush(window);
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
index c957d2d702..39cb911647 100644
--- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
+++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
@@ -171,7 +171,7 @@ public:
lastVelocity = lastVelocityFromMouseMove = QVector2D();
lastMousePos = QPointF();
- lastMouseCapabilityFlags = 0;
+ lastMouseCapabilityFlags = {};
touchEventCount = 0;
mouseMoveCount = 0;
mouseUngrabEventCount = 0;
@@ -199,7 +199,7 @@ public:
QVector2D lastVelocity;
QVector2D lastVelocityFromMouseMove;
QPointF lastMousePos;
- int lastMouseCapabilityFlags;
+ QInputDevice::Capabilities lastMouseCapabilityFlags;
void touchEvent(QTouchEvent *event) {
if (!acceptTouchEvents) {
@@ -208,7 +208,7 @@ public:
}
++touchEventCount;
lastEvent = makeTouchData(event->type(), event->window(), event->touchPointStates(), event->touchPoints());
- if (event->device()->capabilities().testFlag(QTouchDevice::Velocity) && !event->touchPoints().isEmpty()) {
+ if (event->device()->capabilities().testFlag(QPointingDevice::Capability::Velocity) && !event->touchPoints().isEmpty()) {
lastVelocity = event->touchPoints().first().velocity();
} else {
lastVelocity = QVector2D();
@@ -225,7 +225,7 @@ public:
}
mousePressCount = ++mousePressNum;
lastMousePos = e->position().toPoint();
- lastMouseCapabilityFlags = QGuiApplicationPrivate::mouseEventCaps(e);
+ lastMouseCapabilityFlags = e->device()->capabilities();
}
void mouseMoveEvent(QMouseEvent *e) {
@@ -235,7 +235,7 @@ public:
}
mouseMoveCount = ++mouseMoveNum;
lastVelocityFromMouseMove = QGuiApplicationPrivate::mouseEventVelocity(e);
- lastMouseCapabilityFlags = QGuiApplicationPrivate::mouseEventCaps(e);
+ lastMouseCapabilityFlags = e->device()->capabilities();
lastMousePos = e->position().toPoint();
}
@@ -246,7 +246,7 @@ public:
}
++mouseReleaseNum;
lastMousePos = e->position().toPoint();
- lastMouseCapabilityFlags = QGuiApplicationPrivate::mouseEventCaps(e);
+ lastMouseCapabilityFlags = e->device()->capabilities();
}
void mouseUngrabEvent() {
@@ -382,10 +382,10 @@ class tst_qquickwindow : public QQmlDataTest
public:
tst_qquickwindow()
: touchDevice(QTest::createTouchDevice())
- , touchDeviceWithVelocity(QTest::createTouchDevice())
+ , touchDeviceWithVelocity(QTest::createTouchDevice(QInputDevice::DeviceType::TouchScreen,
+ QInputDevice::Capability::Position | QPointingDevice::Capability::Velocity))
{
QQuickWindow::setDefaultAlphaBuffer(true);
- touchDeviceWithVelocity->setCapabilities(QTouchDevice::Position | QTouchDevice::Velocity);
}
private slots:
@@ -501,8 +501,8 @@ private slots:
void rendererInterfaceWithRenderControl();
private:
- QTouchDevice *touchDevice;
- QTouchDevice *touchDeviceWithVelocity;
+ QPointingDevice *touchDevice;
+ QPointingDevice *touchDeviceWithVelocity;
};
#if QT_CONFIG(opengl)
@@ -1185,7 +1185,7 @@ void tst_qquickwindow::mouseFromTouch_basic()
QCOMPARE(item->mouseReleaseNum, 1);
QCOMPARE(item->lastMousePos.toPoint(), item->mapFromScene(points[0].position()).toPoint());
QCOMPARE(item->lastVelocityFromMouseMove, velocity);
- QVERIFY((item->lastMouseCapabilityFlags & QTouchDevice::Velocity) != 0);
+// QVERIFY(item->lastMouseCapabilityFlags.testFlag(QInputDevice::Capability::Velocity)); // TODO
// Now the same with a transformation.
item->setRotation(90); // clockwise
@@ -2850,7 +2850,7 @@ void tst_qquickwindow::pointerEventTypeAndPointCount()
QList<QTouchEvent::TouchPoint>() << QTouchEvent::TouchPoint(1));
- QQuickPointerMouseEvent pme(nullptr, QQuickPointerDevice::genericMouseDevice());
+ QQuickPointerMouseEvent pme(nullptr, QPointingDevice::primaryPointingDevice());
pme.reset(&me);
QCOMPARE(pme.asMouseEvent(localPosition), &me);
QVERIFY(pme.asPointerMouseEvent());
@@ -2862,7 +2862,7 @@ void tst_qquickwindow::pointerEventTypeAndPointCount()
QCOMPARE(pme.asMouseEvent(localPosition)->position(), localPosition);
QCOMPARE(pme.asMouseEvent(localPosition)->globalPosition(), screenPosition);
- QQuickPointerTouchEvent pte(nullptr, QQuickPointerDevice::touchDevice(touchDevice));
+ QQuickPointerTouchEvent pte(nullptr, touchDevice);
pte.reset(&te);
QCOMPARE(pte.asTouchEvent(), &te);
QVERIFY(!pte.asPointerMouseEvent());
diff --git a/tests/auto/quick/touchmouse/tst_touchmouse.cpp b/tests/auto/quick/touchmouse/tst_touchmouse.cpp
index b0d31e9121..9117df812a 100644
--- a/tests/auto/quick/touchmouse/tst_touchmouse.cpp
+++ b/tests/auto/quick/touchmouse/tst_touchmouse.cpp
@@ -173,7 +173,6 @@ class tst_TouchMouse : public QQmlDataTest
Q_OBJECT
public:
tst_TouchMouse()
- :device(QTest::createTouchDevice())
{}
private slots:
@@ -218,7 +217,7 @@ protected:
private:
QQuickView *createView();
- QTouchDevice *device;
+ QPointingDevice *device = QTest::createTouchDevice();
QList<Event> filteredEventList;
};
@@ -613,7 +612,7 @@ void tst_TouchMouse::buttonOnFlickable()
QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window.data());
QVERIFY(windowPriv->touchMouseId != -1);
- auto pointerEvent = windowPriv->pointerEventInstance(QQuickPointerDevice::touchDevices().at(0));
+ auto pointerEvent = windowPriv->pointerEventInstance(device);
QCOMPARE(pointerEvent->point(0)->exclusiveGrabber(), eventItem1);
QCOMPARE(window->mouseGrabberItem(), eventItem1);
@@ -674,7 +673,7 @@ void tst_TouchMouse::touchButtonOnFlickable()
QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window.data());
QVERIFY(windowPriv->touchMouseId == -1);
- auto pointerEvent = windowPriv->pointerEventInstance(QQuickPointerDevice::touchDevices().at(0));
+ auto pointerEvent = windowPriv->pointerEventInstance(device);
QCOMPARE(pointerEvent->point(0)->grabberItem(), eventItem2);
QCOMPARE(window->mouseGrabberItem(), nullptr);
@@ -808,7 +807,7 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable()
// for the touchMouseId to the new grabber.
QCOMPARE(window->mouseGrabberItem(), flickable);
QVERIFY(windowPriv->touchMouseId != -1);
- auto pointerEvent = windowPriv->pointerEventInstance(QQuickPointerDevice::touchDevices().at(0));
+ auto pointerEvent = windowPriv->pointerEventInstance(device);
QCOMPARE(pointerEvent->point(0)->grabberItem(), flickable);
}
@@ -1464,10 +1463,6 @@ void tst_TouchMouse::touchPointDeliveryOrder()
void tst_TouchMouse::hoverEnabled()
{
- // QTouchDevice *device = new QTouchDevice;
- // device->setType(QTouchDevice::TouchScreen);
- // QWindowSystemInterface::registerTouchDevice(device);
-
QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("hoverMouseAreas.qml"));
QQuickViewTestUtil::centerOnScreen(window.data());
diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
index 3f67006554..e205d2e8f2 100644
--- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
+++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
@@ -146,7 +146,7 @@ private slots:
void resizeOverlay();
private:
- QTouchDevice *device = QTest::createTouchDevice();
+ QPointingDevice *device = QTest::createTouchDevice();
const QRect m_availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
};
diff --git a/tests/manual/pointer/inputinspector.cpp b/tests/manual/pointer/inputinspector.cpp
index 82d814b848..ff921fab0f 100644
--- a/tests/manual/pointer/inputinspector.cpp
+++ b/tests/manual/pointer/inputinspector.cpp
@@ -122,11 +122,17 @@ void InputInspector::timerEvent(QTimerEvent *event)
update();
}
-QQuickPointerDevice *InputInspector::pointerDevice() const
+const QPointingDevice *InputInspector::pointerDevice() const
{
- QQuickPointerDevice *device = QQuickPointerDevice::touchDevices().value(0);
+ const QPointingDevice *device = nullptr;
+ for (const auto dev : QInputDevice::devices()) {
+ if (dev->type() == QInputDevice::DeviceType::TouchScreen) {
+ device = static_cast<const QPointingDevice *>(dev);
+ break;
+ }
+ }
if (!device)
- device = QQuickPointerDevice::genericMouseDevice();
+ device = QPointingDevice::primaryPointingDevice();
return device;
}
@@ -134,7 +140,7 @@ QVector<QObject*> InputInspector::passiveGrabbers_helper(int pointId /*= 0*/) co
{
QVector<QObject*> result;
QSet<QObject*> visited;
- QQuickPointerDevice *device = pointerDevice();
+ const QPointingDevice *device = pointerDevice();
if (device && source()) {
QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(source());
QQuickPointerEvent *pointerEvent = winPriv->pointerEventInstance(device);
@@ -161,7 +167,7 @@ QVector<QObject*> InputInspector::exclusiveGrabbers_helper(int pointId /*= 0*/)
{
QVector<QObject*> result;
QSet<QObject*> visited;
- QQuickPointerDevice *device = pointerDevice();
+ const QPointingDevice *device = pointerDevice();
if (device && source()) {
QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(source());
QQuickPointerEvent *pointerEvent = winPriv->pointerEventInstance(device);
diff --git a/tests/manual/pointer/inputinspector.h b/tests/manual/pointer/inputinspector.h
index 66a053d0c3..0ef0a96987 100644
--- a/tests/manual/pointer/inputinspector.h
+++ b/tests/manual/pointer/inputinspector.h
@@ -32,7 +32,7 @@
#include <QObject>
class QQuickWindow;
class QQuickPointerHandler;
-class QQuickPointerDevice;
+class QPointingDevice;
class InputInspector : public QObject
{
@@ -62,7 +62,7 @@ private:
QVector<QObject*> passiveGrabbers_helper(int pointId = 0) const;
QVector<QObject*> exclusiveGrabbers_helper(int pointId = 0) const;
static QString objectIdentifier(QObject *o);
- QQuickPointerDevice *pointerDevice() const;
+ const QPointingDevice *pointerDevice() const;
QString vectorStringJoin(const QVector<QObject*> &arr) const;
private: