aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items
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 /src/quick/items
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>
Diffstat (limited to 'src/quick/items')
-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
9 files changed, 160 insertions, 406 deletions
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;