summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-03-27 16:06:11 +0000
committerShawn Rutledge <shawn.rutledge@qt.io>2020-07-10 14:32:56 +0200
commit4e400369c08db251cd489fec1229398c224d02b4 (patch)
tree6279489dce7b0469d590461798deccf5d1193e29 /src/gui
parent773a6bffd78b363577d27604e17f4ee08ff07e77 (diff)
Refactor pointer event hierarchy
Some goals that have hopefully been achieved are: - make QPointerEvent and QEventPoint resemble their Qt Quick counterparts to such an extent that we can remove those wrappers and go back to delivering the original events in Qt Quick - make QEventPoint much smaller than QTouchEvent::TouchPoint, with no pimpl - remove most public setters - reduce the usage of complex constructors that take many arguments - don't repeat ourselves: move accessors and storage upwards rather than having redundant ones in subclasses - standardize the set of accessors in QPointerEvent - maintain source compatibility as much as possible: do not require modifying event-handling code in any QWidget subclass To avoid public setters we now introduce a few QMutable* subclasses. This is a bit like the Builder pattern except that it doesn't involve constructing a separate disposable object: the main event type can be cast to the mutable type at any time to enable modifications, iff the code is linked with gui-private. Therefore event classes can have less-"complete" constructors, because internal Qt code can use setters the same way it could use the ones in QTouchEvent before; and the event classes don't need many friends. Even some read-accessors can be kept private unless we are sure we want to expose them. Task-number: QTBUG-46266 Fixes: QTBUG-72173 Change-Id: I740e4e40165b7bc41223d38b200bbc2b403e07b6 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qevent.cpp952
-rw-r--r--src/gui/kernel/qevent.h445
-rw-r--r--src/gui/kernel/qevent_p.h142
-rw-r--r--src/gui/kernel/qguiapplication.cpp207
-rw-r--r--src/gui/kernel/qguiapplication_p.h12
-rw-r--r--src/gui/kernel/qinputdevice.h1
-rw-r--r--src/gui/kernel/qpointingdevice.cpp8
-rw-r--r--src/gui/kernel/qsimpledrag.cpp2
-rw-r--r--src/gui/kernel/qwindowsysteminterface.cpp68
-rw-r--r--src/gui/kernel/qwindowsysteminterface.h5
-rw-r--r--src/gui/kernel/qwindowsysteminterface_p.h63
11 files changed, 777 insertions, 1128 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 45e0f0f535..c77a6b23c6 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -79,12 +79,8 @@ QT_BEGIN_NAMESPACE
mouse cursor's position relative to the receiving widget or item,
window, and screen or desktop, respectively.
*/
-
-QEnterEvent::QEnterEvent(const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos)
- : QEvent(QEvent::Enter)
- , l(localPos)
- , s(scenePos)
- , g(globalPos)
+QEnterEvent::QEnterEvent(const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos, const QPointingDevice *device)
+ : QSinglePointEvent(QEvent::Enter, device, localPos, scenePos, globalPos)
{
}
@@ -164,18 +160,6 @@ QInputEvent::~QInputEvent()
{
}
-QPointerEvent::QPointerEvent(QEvent::Type type, const QPointingDevice *dev, Qt::KeyboardModifiers modifiers)
- : QInputEvent(type, dev, modifiers)
-{
-
-}
-
-const QPointingDevice *QPointerEvent::pointingDevice() const
-{
- return static_cast<const QPointingDevice *>(m_dev);
-}
-
-
/*!
\fn QInputDevice *QInputEvent::device() const
\since 6.0
@@ -188,6 +172,8 @@ const QPointingDevice *QPointerEvent::pointingDevice() const
Thus \c {mouseEvent.source()->type() != QInputDevice::DeviceType::Mouse}
is one possible replacement for the Qt 5 expression
\c {mouseEvent.source() == Qt::MouseEventSynthesizedByQt}.
+
+ \sa QPointerEvent::pointingDevice()
*/
/*!
@@ -228,6 +214,148 @@ const QPointingDevice *QPointerEvent::pointingDevice() const
*/
/*!
+ \internal
+ Constructs an invalid event point with the given \a id and \a parent.
+
+ This acts as a default constructor in usages like QMap<int, QEventPoint>,
+ as in qgraphicsscene_p.h.
+*/
+QEventPoint::QEventPoint(int id, const QPointerEvent *parent)
+ : m_parent(parent), m_pointId(id), m_state(State::Unknown), m_accept(false), m_stationaryWithModifiedProperty(false), m_reserved(0)
+{
+}
+
+QEventPoint::QEventPoint(int pointId, State state, const QPointF &scenePosition, const QPointF &globalPosition)
+ : m_scenePos(scenePosition), m_globalPos(globalPosition), m_pointId(pointId), m_state(state),
+ m_accept(false), m_stationaryWithModifiedProperty(false), m_reserved(0)
+{
+ if (state == QEventPoint::State::Released)
+ m_pressure = 0;
+}
+
+/*
+ Sets the accepted state of the point.
+
+ In widget-based applications, this function is not used so far, because
+ it's only meaningful for a widget to accept or reject a complete QInputEvent.
+
+ In Qt Quick however, it's normal for an Item or Event Handler to accept
+ only the individual points in a QTouchEvent that are actually participating
+ in a gesture, while other points can be delivered to other items or
+ handlers. For the sake of consistency, that applies to any QPointerEvent;
+ and delivery is done only when all points in a QPointerEvent have been
+ accepted.
+
+ \sa QEvent::setAccepted()
+*/
+void QEventPoint::setAccepted(bool accepted)
+{
+ m_accept = accepted;
+}
+
+/*
+ Informs the delivery logic that the given \a exclusiveGrabber is to
+ receive all future update events and the release event containing
+ this point, and that delivery to other items can be skipped.
+
+ It's mainly for use in Qt Quick at this time.
+*/
+void QEventPoint::setExclusiveGrabber(QObject *exclusiveGrabber)
+{
+ m_exclusiveGrabber = exclusiveGrabber;
+ m_globalGrabPos = m_globalPos;
+}
+
+/*
+ Informs the delivery logic that the given \a grabbers are to receive all
+ future update events and the release event containing this point,
+ regardless where else those events may be delivered.
+
+ It's mainly for use in Qt Quick at this time.
+*/
+void QEventPoint::setPassiveGrabbers(const QList<QPointer<QObject> > &grabbers)
+{
+ m_passiveGrabbers = grabbers;
+}
+
+void QEventPoint::clearPassiveGrabbers()
+{
+ m_passiveGrabbers.clear();
+}
+
+/*! \internal
+ void QMutableEventPoint::setPosition(const QPointF &pos)
+
+ Sets the localized position.
+
+ Often events need to be localized before delivery to specific widgets or
+ items. This can be done directly, or in a copy (for which we have a copy
+ constructor), depending on whether the original point needs to be retained.
+ Usually it's calculated by mapping scenePosition() to the target anyway.
+*/
+
+QPointF QEventPoint::normalizedPos() const
+{
+ auto geom = event()->device()->availableVirtualGeometry();
+ if (geom.isNull())
+ return QPointF();
+ return (globalPosition() - geom.topLeft()) / geom.width();
+}
+
+QPointF QEventPoint::startNormalizedPos() const
+{
+ auto geom = event()->device()->availableVirtualGeometry();
+ if (geom.isNull())
+ return QPointF();
+ return (globalPressPosition() - geom.topLeft()) / geom.width();
+}
+
+QPointF QEventPoint::lastNormalizedPos() const
+{
+ auto geom = event()->device()->availableVirtualGeometry();
+ if (geom.isNull())
+ return QPointF();
+ return (globalLastPosition() - geom.topLeft()) / geom.width();
+}
+
+QPointerEvent::QPointerEvent(QEvent::Type type, const QPointingDevice *dev, Qt::KeyboardModifiers modifiers)
+ : QInputEvent(type, dev, modifiers)
+{
+}
+
+QPointerEvent::~QPointerEvent()
+{
+}
+
+/*! \fn QPointingDevice* QPointerEvent::pointingDevice() const
+
+ Returns the source device from which this event originates.
+
+ This is the same as QInputEvent::device() but typecast for convenience.
+*/
+const QPointingDevice *QPointerEvent::pointingDevice() const
+{
+ return static_cast<const QPointingDevice *>(m_dev);
+}
+
+
+QSinglePointEvent::QSinglePointEvent(QEvent::Type type, const QPointingDevice *dev, const QPointF &localPos, const QPointF &scenePos,
+ const QPointF &globalPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
+ : QPointerEvent(type, dev, modifiers),
+ m_point(0, this),
+ m_button(button),
+ m_mouseState(buttons),
+ m_source(Qt::MouseEventNotSynthesized),
+ m_doubleClick(false),
+ m_reserved(0)
+{
+ QMutableEventPoint &mut = QMutableEventPoint::from(m_point);
+ mut.setPosition(localPos);
+ mut.setScenePosition(scenePos);
+ mut.setGlobalPosition(globalPos);
+}
+
+/*!
\fn QPointingDevice::PointerType QPointerEvent::pointerType() const
Returns the type of point that generated the event.
@@ -303,16 +431,17 @@ const QPointingDevice *QPointerEvent::pointingDevice() const
position explicitly.
*/
QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton button,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
- : QPointerEvent(type, QPointingDevice::primaryPointingDevice(), modifiers),
- l(localPos), w(localPos), b(button), mouseState(buttons), caps(0)
-{
-#ifndef QT_NO_CURSOR
- g = QCursor::pos();
+ Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, const QPointingDevice *device)
+ : QSinglePointEvent(type, device, localPos, localPos,
+#ifdef QT_NO_CURSOR
+ localPos,
+#else
+ QCursor::pos(),
#endif
+ button, buttons, modifiers)
+{
}
-
/*!
Constructs a mouse event object.
@@ -333,39 +462,12 @@ QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton but
*/
QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &globalPos,
Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers)
- : QMouseEvent(type, localPos, localPos, globalPos, button, buttons, modifiers)
-{}
-
-/*!
- Constructs a mouse event object.
-
- The \a type parameter must be QEvent::MouseButtonPress,
- QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
- or QEvent::MouseMove.
-
- The points \a localPos, \a scenePos and \a globalPos specify the
- mouse cursor's position relative to the receiving widget or item,
- window, and screen or desktop, respectively.
-
- The \a button that caused the event is
- given as a value from the \l Qt::MouseButton enum. If the event \a
- type is \l MouseMove, the appropriate button for this event is
- Qt::NoButton. \a buttons is the state of all buttons at the
- time of the event, \a modifiers the state of all keyboard
- modifiers.
-
-*/
-QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
- Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers)
- : QPointerEvent(type, QPointingDevice::primaryPointingDevice(), modifiers),
- l(localPos), w(scenePos), g(globalPos), b(button), mouseState(buttons), caps(0)
-{}
+ Qt::KeyboardModifiers modifiers, const QPointingDevice *device)
+ : QMouseEvent(type, localPos, localPos, globalPos, button, buttons, modifiers, device)
+{
+}
/*!
- \since 5.6
-
Constructs a mouse event object.
The \a type parameter must be QEvent::MouseButtonPress,
@@ -381,16 +483,22 @@ QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &scen
the appropriate button for this event is Qt::NoButton. \a buttons
is the state of all buttons at the time of the event, \a modifiers
is the state of all keyboard modifiers.
-
- The source of the event is specified by \a source.
-
*/
-QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
+QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF &localPos,
+ const QPointF &scenePos, const QPointF &globalPos,
Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source)
- : QMouseEvent(type, localPos, scenePos, globalPos, button, buttons, modifiers)
+ Qt::KeyboardModifiers modifiers, const QPointingDevice *device)
+ : QSinglePointEvent(type, device, localPos, scenePos, globalPos, button, buttons, modifiers)
{
- QGuiApplicationPrivate::setMouseEventSource(this, source);
+}
+
+QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF &localPos, const QPointF &windowPos,
+ const QPointF &globalPos, Qt::MouseButton button, Qt::MouseButtons buttons,
+ Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source,
+ const QPointingDevice *device)
+ : QSinglePointEvent(type, device, localPos, windowPos, globalPos, button, buttons, modifiers)
+{
+ m_source = source;
}
/*!
@@ -401,38 +509,43 @@ QMouseEvent::~QMouseEvent()
}
/*!
- \since 5.3
+ \since 5.3
+ \deprecated in 6.0: use pointingDevice()
- Returns information about the mouse event source.
+ Returns information about the mouse event source.
- The mouse event source can be used to distinguish between genuine
- and artificial mouse events. The latter are events that are
- synthesized from touch events by the operating system or Qt itself.
+ The mouse event source can be used to distinguish between genuine
+ and artificial mouse events. The latter are events that are
+ synthesized from touch events by the operating system or Qt itself.
+ This enum tells you from where it was synthesized; but often
+ it's more useful to know from which device it was synthesized,
+ so try to use pointingDevice() instead.
- \note Many platforms provide no such information. On such platforms
- \l Qt::MouseEventNotSynthesized is returned always.
+ \note Many platforms provide no such information. On such platforms
+ \l Qt::MouseEventNotSynthesized is returned always.
- \sa Qt::MouseEventSource
- \sa QGraphicsSceneMouseEvent::source()
- */
+ \sa Qt::MouseEventSource
+ \sa QGraphicsSceneMouseEvent::source()
+*/
Qt::MouseEventSource QMouseEvent::source() const
{
- return QGuiApplicationPrivate::mouseEventSource(this);
+ return Qt::MouseEventSource(m_source);
}
/*!
- \since 5.3
+ \since 5.3
+ \deprecated in 6.0
- Returns the mouse event flags.
+ Returns the mouse event flags.
- The mouse event flags provide additional information about a mouse event.
+ The mouse event flags provide additional information about a mouse event.
- \sa Qt::MouseEventFlag
- \sa QGraphicsSceneMouseEvent::flags()
- */
+ \sa Qt::MouseEventFlag
+ \sa QGraphicsSceneMouseEvent::flags()
+*/
Qt::MouseEventFlags QMouseEvent::flags() const
{
- return QGuiApplicationPrivate::mouseEventFlags(this);
+ return (m_doubleClick ? Qt::MouseEventCreatedDoubleClick : Qt::NoMouseEventFlag);
}
/*!
@@ -684,8 +797,9 @@ Qt::MouseEventFlags QMouseEvent::flags() const
\a modifiers hold the state of all keyboard modifiers at the time
of the event.
*/
-QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers)
- : QInputEvent(type, QPointingDevice::primaryPointingDevice(), modifiers), p(pos), op(oldPos)
+QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos,
+ Qt::KeyboardModifiers modifiers, const QPointingDevice *device)
+ : QSinglePointEvent(type, device, pos, pos, pos, Qt::NoButton, Qt::NoButton, modifiers), op(oldPos)
{
}
@@ -712,7 +826,7 @@ QHoverEvent::~QHoverEvent()
degrees. These values are always provided. pixelDelta() returns
the deltas in screen pixels, and is available on platforms that
have high-resolution trackpads, such as \macos. If that is the
- case, source() will return Qt::MouseEventSynthesizedBySystem.
+ case, device()->type() will return QInputDevice::DeviceType::Touchpad.
The functions pos() and globalPos() return the mouse cursor's
location at the time of the event.
@@ -746,12 +860,16 @@ QHoverEvent::~QHoverEvent()
/*!
\fn Qt::MouseEventSource QWheelEvent::source() const
\since 5.5
+ \deprecated in 6.0: use pointingDevice()
Returns information about the wheel event source.
The source can be used to distinguish between events that come from a mouse
with a physical wheel and events that are generated by some other means,
such as a flick gesture on a touchpad.
+ This enum tells you from where it was synthesized; but often
+ it's more useful to know from which device it was synthesized,
+ so try to use pointingDevice() instead.
\note Many platforms provide no such information. On such platforms
\l Qt::MouseEventNotSynthesized is returned always.
@@ -801,26 +919,21 @@ QHoverEvent::~QHoverEvent()
The scrolling phase of the event is specified by \a phase.
- If the wheel event comes from a physical mouse wheel, \a source is set to
- Qt::MouseEventNotSynthesized. If it comes from a gesture detected by the
- operating system, or from a non-mouse hardware device, such that \a
- pixelDelta is directly related to finger movement, \a source is set to
- Qt::MouseEventSynthesizedBySystem. If it comes from Qt, source would be set
- to Qt::MouseEventSynthesizedByQt.
-
If the system is configured to invert the delta values delivered with the
event (such as natural scrolling of the touchpad on macOS), \a inverted
should be \c true. Otherwise, \a inverted is \c false
- \sa position(), globalPosition(), angleDelta(), pixelDelta(), phase(), inverted(), source()
+ The device from which the wheel event originated is specified by \a device.
+
+ \sa position(), globalPosition(), angleDelta(), pixelDelta(), phase(), inverted(), device()
*/
-QWheelEvent::QWheelEvent(QPointF pos, QPointF globalPos, QPoint pixelDelta, QPoint angleDelta,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase,
- bool inverted, Qt::MouseEventSource source)
- : QPointerEvent(Wheel, QPointingDevice::primaryPointingDevice(), modifiers),
- p(pos), g(globalPos), pixelD(pixelDelta), angleD(angleDelta),
- mouseState(buttons), src(source), ph(phase), invertedScrolling(inverted)
+QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
+ Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase,
+ bool inverted, Qt::MouseEventSource source, const QPointingDevice *device)
+ : QSinglePointEvent(Wheel, device, pos, pos, globalPos, Qt::NoButton, buttons, modifiers),
+ m_phase(phase), m_invertedScrolling(inverted), m_pixelDelta(pixelDelta), m_angleDelta(angleDelta)
{
+ m_source = source;
}
/*!
@@ -998,8 +1111,8 @@ QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const
*/
QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
- const QString &text, bool autorep, ushort count)
- : QInputEvent(type, QInputDevice::primaryKeyboard(), modifiers), txt(text), k(key),
+ const QString &text, bool autorep, ushort count, const QInputDevice *device)
+ : QInputEvent(type, device, modifiers), txt(text), k(key),
nScanCode(nativeScanCode), nVirtualKey(nativeVirtualKey), nModifiers(nativeModifiers),
c(count), autor(autorep)
{
@@ -2201,38 +2314,20 @@ QVariant QInputMethodQueryEvent::value(Qt::InputMethodQuery query) const
\sa pos(), globalPos(), device(), pressure(), xTilt(), yTilt(), uniqueId(), rotation(),
tangentialPressure(), z()
*/
-QTabletEvent::QTabletEvent(Type type, const QPointF &pos, const QPointF &globalPos,
- int deviceType, int pointerType, // TODO use the enums rather than int
- qreal pressure, int xTilt, int yTilt, qreal tangentialPressure,
- qreal rotation, int z, Qt::KeyboardModifiers keyState, qint64 uniqueID,
- Qt::MouseButton button, Qt::MouseButtons buttons)
- : QTabletEvent(type,
- QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType(deviceType),
- QPointingDevice::PointerType(pointerType),
- QPointingDeviceUniqueId::fromNumericId(uniqueID)),
- pos, globalPos, pressure, xTilt, yTilt, tangentialPressure,
- rotation, z, keyState, button, buttons)
-{
- Q_ASSERT(m_dev);
-}
-
QTabletEvent::QTabletEvent(Type type, const QPointingDevice *dev, const QPointF &pos, const QPointF &globalPos,
qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z,
Qt::KeyboardModifiers keyState,
Qt::MouseButton button, Qt::MouseButtons buttons)
- : QPointerEvent(type, dev, keyState),
- mPos(pos),
- mGPos(globalPos),
+ : QSinglePointEvent(type, dev, pos, pos, globalPos, button, buttons, keyState),
mXT(xTilt),
mYT(yTilt),
mZ(z),
- mPress(pressure),
- mTangential(tangentialPressure),
- mRot(rotation),
- mButton(button),
- mButtons(buttons)
+ mTangential(tangentialPressure)
{
+ QMutableEventPoint &mut = QMutableEventPoint::from(m_point);
+ mut.setPressure(pressure);
+ mut.setRotation(rotation);
}
/*!
@@ -2495,12 +2590,10 @@ QTabletEvent::~QTabletEvent()
\a realValue is the \macos event parameter, \a sequenceId and \a intValue are the Windows event parameters.
\since 5.10
*/
-QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *device,
- const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
- qreal realValue, ulong sequenceId, quint64 intValue)
- : QPointerEvent(QEvent::NativeGesture, device), mGestureType(type),
- mLocalPos(localPos), mScenePos(scenePos), mGlobalPos(globalPos), mRealValue(realValue),
- mSequenceId(sequenceId), mIntValue(intValue)
+QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *device, const QPointF &localPos, const QPointF &scenePos,
+ const QPointF &globalPos, qreal realValue, ulong sequenceId, quint64 intValue)
+ : QSinglePointEvent(QEvent::NativeGesture, device, localPos, scenePos, globalPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier), mGestureType(type),
+ mRealValue(realValue), mSequenceId(sequenceId), mIntValue(intValue)
{
}
@@ -3625,7 +3718,7 @@ static void formatTabletEvent(QDebug d, const QTabletEvent *e)
QtDebugUtils::formatQEnum(d, e->deviceType());
d << ", pointerType=";
QtDebugUtils::formatQEnum(d, e->pointerType());
- d << ", uniqueId=" << e->uniqueId()
+ d << ", uniqueId=" << e->pointingDevice()->uniqueId().numericId()
<< ", pos=" << e->position()
<< ", z=" << e->z()
<< ", xTilt=" << e->xTilt()
@@ -3642,12 +3735,14 @@ static void formatTabletEvent(QDebug d, const QTabletEvent *e)
# endif // QT_CONFIG(tabletevent)
-QDebug operator<<(QDebug dbg, const QTouchEvent::TouchPoint &tp)
+QDebug operator<<(QDebug dbg, const QEventPoint &tp)
{
QDebugStateSaver saver(dbg);
dbg.nospace();
- dbg << "TouchPoint(" << Qt::hex << tp.id() << Qt::dec << " (";
+ dbg << "QEventPoint(" << Qt::hex << tp.id() << Qt::dec << " (";
QtDebugUtils::formatQPoint(dbg, tp.position());
+ dbg << " global ";
+ QtDebugUtils::formatQPoint(dbg, tp.globalPosition());
dbg << ") ";
QtDebugUtils::formatQEnum(dbg, tp.state());
dbg << " pressure " << tp.pressure() << " ellipse ("
@@ -3657,9 +3752,9 @@ QDebug operator<<(QDebug dbg, const QTouchEvent::TouchPoint &tp)
dbg << ") start (";
QtDebugUtils::formatQPoint(dbg, tp.pressPosition());
dbg << ") last (";
- QtDebugUtils::formatQPoint(dbg, tp.lastPos());
+ QtDebugUtils::formatQPoint(dbg, tp.lastPosition());
dbg << ") delta (";
- QtDebugUtils::formatQPoint(dbg, tp.position() - tp.lastPos());
+ QtDebugUtils::formatQPoint(dbg, tp.position() - tp.lastPosition());
dbg << ')';
return dbg;
}
@@ -3704,13 +3799,11 @@ QDebug operator<<(QDebug dbg, const QEvent *e)
QtDebugUtils::formatQFlags(dbg, buttons);
}
QtDebugUtils::formatNonNullQFlags(dbg, ", ", me->modifiers());
- dbg << ", localPos=";
+ dbg << ", pos=";
QtDebugUtils::formatQPoint(dbg, me->position());
- dbg << ", screenPos=";
+ dbg << ", globalPos=";
QtDebugUtils::formatQPoint(dbg, me->globalPosition());
- QtDebugUtils::formatNonNullQEnum(dbg, ", ", me->source());
- QtDebugUtils::formatNonNullQFlags(dbg, ", flags=", me->flags());
- dbg << ')';
+ dbg << ", dev=" << me->device() << ')';
}
break;
# if QT_CONFIG(wheelevent)
@@ -3990,10 +4083,13 @@ QWindowStateChangeEvent::~QWindowStateChangeEvent()
gestures. Whenever such a decision is made (the gesture is recognized), the clients will be
notified with a QEvent::TouchCancel event so they can update their state accordingly.
- The touchPoints() function returns a list of all touch points contained in the event. Note that
- this list may be empty, for example in case of a QEvent::TouchCancel event. Information about
- each touch point can be retrieved using the QTouchEvent::TouchPoint class. The
- Qt::TouchPointState enum describes the different states that a touch point may have.
+ The pointCount() and point() functions can be used to access and iterate individual
+ touch points.
+
+ The touchPoints() function returns a list of all touch points contained in the event.
+ Note that this list may be empty, for example in case of a QEvent::TouchCancel event.
+ Each point is an instance of the QEventPoint class. The QEventPoint::State enum
+ describes the different states that a touch point may have.
\note The list of touchPoints() will never be partial: A touch event will always contain a touch
point for each existing physical touch contacts targetting the window or widget to which the
@@ -4071,27 +4167,50 @@ QWindowStateChangeEvent::~QWindowStateChangeEvent()
\endlist
- \sa QTouchEvent::TouchPoint, Qt::TouchPointState, Qt::WA_AcceptTouchEvents,
+ \sa QEventPoint, QEventPoint::State, Qt::WA_AcceptTouchEvents,
QGraphicsItem::acceptTouchEvents()
*/
/*!
+ Constructs a QTouchEvent with the given \a eventType, \a device,
+ \a touchPoints, and current keyboard \a modifiers at the time of the event.
+*/
+
+QTouchEvent::QTouchEvent(QEvent::Type eventType,
+ const QPointingDevice *device,
+ Qt::KeyboardModifiers modifiers,
+ const QList<QEventPoint> &touchPoints)
+ : QPointerEvent(eventType, device, modifiers),
+ m_target(nullptr),
+ m_touchPoints(touchPoints)
+{
+ for (QEventPoint &point : m_touchPoints) {
+ m_touchPointStates |= point.state();
+ QMutableEventPoint::from(point).setParent(this);
+ }
+}
+
+/*!
+ \obsolete Try to use another constructor, because \a touchPointStates
+ can be calculated from the given \a touchPoints.
+
Constructs a QTouchEvent with the given \a eventType, \a device, and
- \a touchPoints. The \a touchPointStates and \a modifiers
- are the current touch point states and keyboard modifiers at the time of
- the event.
+ \a touchPoints. The \a touchPointStates and \a modifiers are the current
+ touch point states and keyboard modifiers at the time of the event.
*/
QTouchEvent::QTouchEvent(QEvent::Type eventType,
const QPointingDevice *device,
Qt::KeyboardModifiers modifiers,
- Qt::TouchPointStates touchPointStates,
- const QList<QTouchEvent::TouchPoint> &touchPoints)
+ QEventPoint::States touchPointStates,
+ const QList<QEventPoint> &touchPoints)
: QPointerEvent(eventType, device, modifiers),
- _window(nullptr),
- _target(nullptr),
- _touchPointStates(touchPointStates),
- _touchPoints(touchPoints)
-{ }
+ m_target(nullptr),
+ m_touchPointStates(touchPointStates),
+ m_touchPoints(touchPoints)
+{
+ for (QEventPoint &point : m_touchPoints)
+ QMutableEventPoint::from(point).setParent(this);
+}
/*!
Destroys the QTouchEvent.
@@ -4099,173 +4218,62 @@ QTouchEvent::QTouchEvent(QEvent::Type eventType,
QTouchEvent::~QTouchEvent()
{ }
-/*! \fn QWindow *QTouchEvent::window() const
-
- Returns the window on which the event occurred. Useful for doing
- global-local mapping on data like rawScreenPositions() which,
- for performance reasons, only stores the global positions in the
- touch event.
-*/
-
/*! \fn QObject *QTouchEvent::target() const
Returns the target object within the window on which the event occurred.
This is typically a QWidget or a QQuickItem. May be 0 when no specific target is available.
*/
-/*! \fn QTouchEvent::TouchPoint::TouchPoint(TouchPoint &&other)
-
- Move-constructs a TouchPoint instance, making it point to the same
- object that \a other was pointing to.
-*/
-
-/*! \fn Qt::TouchPointStates QTouchEvent::touchPointStates() const
+/*! \fn QEventPoint::States QTouchEvent::touchPointStates() const
Returns a bitwise OR of all the touch point states for this event.
*/
-/*! \fn const QList<QTouchEvent::TouchPoint> &QTouchEvent::touchPoints() const
-
- Returns the list of touch points contained in the touch event.
-*/
+/*! \fn const QList<QEventPoint> &QTouchEvent::touchPoints() const
-/*! \fn QPointingDevice* QTouchEvent::device() const
+ Returns a reference to the list of touch points contained in the touch event.
- Returns the touch device from which this touch event originates.
+ \sa QPointerEvent::point(), QPointerEvent::pointCount()
*/
-/*! \fn void QTouchEvent::setWindow(QWindow *window)
-
- \internal
-
- Sets the window for this event.
-*/
-
-/*! \fn void QTouchEvent::setTarget(QObject *target)
-
- \internal
-
- Sets the target within the window (typically a widget) for this event.
-*/
-
-/*! \fn void QTouchEvent::setTouchPoints(const QList<QTouchEvent::TouchPoint> &touchPoints)
-
- \internal
-
- Sets the list of touch points for this event.
-*/
-
-/*! \class QTouchEvent::TouchPoint
- \brief The TouchPoint class provides information about a touch point in a QTouchEvent.
- \since 4.6
+/*! \class QEventPoint
+ \brief The QEventPoint class provides information about a point in a QPointerEvent.
+ \since 6.0
\inmodule QtGui
-
- \image touchpoint-metrics.png
*/
-/*! \enum TouchPoint::InfoFlag
-
- The values of this enum describe additional information about a touch point.
-
- \value Pen Indicates that the contact has been made by a designated pointing device (e.g. a pen) instead of a finger.
- \value Token Indicates that the contact has been made by a fiducial object (e.g. a knob or other token) instead of a finger.
-*/
-
-/*!
- \internal
-
- Constructs a QTouchEvent::TouchPoint for use in a QTouchEvent.
-*/
-QTouchEvent::TouchPoint::TouchPoint(int id)
- : d(new QTouchEventTouchPointPrivate(id))
-{ }
-
-/*!
- \fn QTouchEvent::TouchPoint::TouchPoint(const QTouchEvent::TouchPoint &other)
- \internal
-
- Constructs a copy of \a other.
-*/
-QTouchEvent::TouchPoint::TouchPoint(const QTouchEvent::TouchPoint &other)
- : d(other.d)
-{
- d->ref.ref();
-}
-
-/*!
- \internal
-
- Destroys the QTouchEvent::TouchPoint.
-*/
-QTouchEvent::TouchPoint::~TouchPoint()
-{
- if (d && !d->ref.deref())
- delete d;
-}
-
-/*!
+/*! \fn int QEventPoint::id() const
Returns the id number of this touch point.
Do not assume that id numbers start at zero or that they are sequential.
Such an assumption is often false due to the way the underlying drivers work.
*/
-int QTouchEvent::TouchPoint::id() const
-{
- return d->id;
-}
-/*!
+/*! \fn QPointingDeviceUniqueId QEventPoint::uniqueId() const
\since 5.8
Returns the unique ID of this touch point or token, if any.
- It is normally invalid (see \l {QPointingDeviceUniqueId::isValid()} {isValid()}),
+ It is often invalid (see \l {QPointingDeviceUniqueId::isValid()} {isValid()}),
because touchscreens cannot uniquely identify fingers. But when the
\l {TouchPoint::InfoFlag} {Token} flag is set, it is expected to uniquely
- identify a specific token (fiducial object).
+ identify a specific token (fiducial object). When it comes from a QTabletEvent,
+ it identifies the serial number of the stylus in use.
\sa flags
*/
-QPointingDeviceUniqueId QTouchEvent::TouchPoint::uniqueId() const
-{
- return d->uniqueId;
-}
-/*!
- Returns the current state of this touch point.
+/*! \fn QEventPoint::State QEventPoint::state() const
+ Returns the current state of this point.
*/
-Qt::TouchPointState QTouchEvent::TouchPoint::state() const
-{
- return Qt::TouchPointState(int(d->state));
-}
-/*!
- \fn QPointF QTouchEvent::pos() const
- \deprecated in Qt 6.0. Use position() instead.
+/*! \fn QPointF QEventPoint::position() const
- Returns the position of this touch point, relative to the widget
+ Returns the position of this point, relative to the widget
or item that received the event.
-
- \sa startPos(), lastPos(), screenPos(), scenePos(), normalizedPos()
*/
-/*!
- Returns the position of this touch point, relative to the widget
- or item that received the event.
-
- \sa startPos(), lastPos(), screenPos(), scenePos(), normalizedPos()
-*/
-QPointF QTouchEvent::TouchPoint::position() const
-{
- return d->pos;
-}
-
-/*!
- \fn QPointF QTouchEvent::scenePos() const
- \deprecated in Qt 6.0. Use scenePosition() instead.
-*/
-
-/*!
- Returns the position of this touch point relative to the window or scene.
+/*! \fn QPointF QEventPoint::scenePosition() const
+ Returns the position of this point relative to the window or scene.
The scene position is the position relative to QQuickWindow if handled in QQuickItem::event(),
in QGraphicsScene coordinates if handled by an override of QGraphicsItem::touchEvent(),
@@ -4273,64 +4281,33 @@ QPointF QTouchEvent::TouchPoint::position() const
\sa scenePressPosition(), position(), globalPosition()
*/
-QPointF QTouchEvent::TouchPoint::scenePosition() const
-{
- return d->scenePos;
-}
-/*!
- \fn QPointF QTouchEvent::screenPos() const
- \deprecated in Qt 6.0. Use globalPosition() instead.
-*/
-
-/*!
- Returns the position of this touch point on the screen or virtual desktop.
+/*! \fn QPointF QEventPoint::globalPosition() const
+ Returns the position of this point on the screen or virtual desktop.
\sa globalPressPosition(), position(), scenePosition()
*/
-QPointF QTouchEvent::TouchPoint::globalPosition() const
-{
- return d->screenPos;
-}
-/*!
+/*! \fn QPointF QEventPoint::normalizedPos() const
\deprecated in Qt 6.0. Use globalPosition() instead.
- Returns the normalized position of this touch point.
+ Returns the normalized position of this point.
- The coordinates are normalized to the size of the touch device,
+ The coordinates are normalized to QInputDevice::availableVirtualGeometry(),
i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
\sa startNormalizedPos(), lastNormalizedPos(), pos()
*/
-QPointF QTouchEvent::TouchPoint::normalizedPos() const
-{
- return d->normalizedPos;
-}
-
-/*!
- \fn QPointF QTouchEvent::startPos() const
- \deprecated in Qt 6.0. Use pressPosition() instead.
-*/
-/*!
- Returns the position at which this touch point was pressed, relative to the
+/*! \fn QPointF QEventPoint::pressPosition() const
+ Returns the position at which this point was pressed, relative to the
widget or item that received the event.
\sa position()
*/
-QPointF QTouchEvent::TouchPoint::pressPosition() const
-{
- return d->startPos;
-}
-
-/*!
- \fn QPointF QTouchEvent::sceneStartPos() const
- \deprecated in Qt 6.0. Use scenePressPosition() instead.
-*/
-/*!
- Returns the scene position at which this touch point was pressed.
+/*! \fn QPointF QEventPoint::scenePressPosition() const
+ Returns the scene position at which this point was pressed.
The scene position is the position relative to QQuickWindow if handled in QQuickItem::event(),
in QGraphicsScene coordinates if handled by an override of QGraphicsItem::touchEvent(),
@@ -4338,54 +4315,22 @@ QPointF QTouchEvent::TouchPoint::pressPosition() const
\sa scenePosition(), pressPosition(), globalPressPosition()
*/
-QPointF QTouchEvent::TouchPoint::scenePressPosition() const
-{
- return d->startScenePos;
-}
-
-/*!
- \fn QPointF QTouchEvent::startScreenPos() const
- \deprecated in Qt 6.0. Use globalPressPosition() instead.
-*/
-/*!
- Returns the starting screen position of this touch point.
+/*! \fn QPointF QEventPoint::globalPressPosition() const
+ Returns the position at which this point was pressed on the screen or virtual desktop.
\sa globalPosition(), pressPosition(), scenePressPosition()
*/
-QPointF QTouchEvent::TouchPoint::globalPressPosition() const
-{
- return d->startScreenPos;
-}
-/*!
- \deprecated in Qt 6.0. Use globalPressPosition() instead.
- Returns the normalized press position of this touch point.
-
- The coordinates are normalized to the size of the touch device,
- i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
-
- \sa normalizedPos(), lastNormalizedPos()
-*/
-QPointF QTouchEvent::TouchPoint::startNormalizedPos() const
-{
- return d->startNormalizedPos;
-}
-
-/*!
- Returns the position of this touch point from the previous touch
- event, relative to the widget or QGraphicsItem that received the event.
+/*! \fn QPointF QEventPoint::lastPosition() const
+ Returns the position of this point from the previous event,
+ relative to the widget or QGraphicsItem that received the event.
\sa pos(), startPos()
*/
-QPointF QTouchEvent::TouchPoint::lastPos() const
-{
- return d->lastPos;
-}
-/*!
- Returns the scene position of this touch point from the previous
- touch event.
+/*! \fn QPointF QEventPoint::lastScenePosition() const
+ Returns the scene position of this point from the previous event.
The scene position is the position in QGraphicsScene coordinates
if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
@@ -4394,295 +4339,48 @@ QPointF QTouchEvent::TouchPoint::lastPos() const
\sa scenePos(), startScenePos()
*/
-QPointF QTouchEvent::TouchPoint::lastScenePos() const
-{
- return d->lastScenePos;
-}
-
-/*!
- Returns the screen position of this touch point from the previous
- touch event.
-
- \sa screenPos(), startScreenPos()
-*/
-QPointF QTouchEvent::TouchPoint::lastScreenPos() const
-{
- return d->lastScreenPos;
-}
-/*!
+/*! \fn QPointF QEventPoint::lastNormalizedPos() const
+ \deprecated in 6.0: use globalLastPosition()
Returns the normalized position of this touch point from the
previous touch event.
- The coordinates are normalized to the size of the touch device,
+ The coordinates are normalized to QInputDevice::availableVirtualGeometry(),
i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
\sa normalizedPos(), startNormalizedPos()
*/
-QPointF QTouchEvent::TouchPoint::lastNormalizedPos() const
-{
- return d->lastNormalizedPos;
-}
-/*!
- Returns the pressure of this touch point. The return value is in
- the range 0.0 to 1.0.
+/*! \fn qreal QEventPoint::pressure() const
+ Returns the pressure of this point. The return value is in
+ the range \c 0.0 to \c 1.0.
*/
-qreal QTouchEvent::TouchPoint::pressure() const
-{
- return d->pressure;
-}
-/*!
+/*! \fn qreal QEventPoint::rotation() const
\since 5.8
- Returns the angular orientation of this touch point. The return value is in degrees,
- where zero (the default) indicates the finger or token is pointing upwards,
+ Returns the angular orientation of this point. The return value is in degrees,
+ where zero (the default) indicates the finger, token or stylus is pointing upwards,
a negative angle means it's rotated to the left, and a positive angle means
it's rotated to the right. Most touchscreens do not detect rotation, so
zero is the most common value.
*/
-qreal QTouchEvent::TouchPoint::rotation() const
-{
- return d->rotation;
-}
-/*!
+/*! \fn QSizeF QEventPoint::ellipseDiameters() const
\since 5.9
- Returns the width and height of the bounding ellipse of this touch point.
+ Returns the width and height of the bounding ellipse of the touch point.
The return value is in logical pixels. Most touchscreens do not detect the
- shape of the contact point, so a null size is the most common value.
- In other cases the diameters may be nonzero and equal (the ellipse is
- approximated as a circle).
+ shape of the contact point, and no mice or tablet devices can do detect it,
+ so a null size is the most common value. On some touchscreens the diameters
+ may be nonzero and equal (the ellipse is approximated as a circle).
*/
-QSizeF QTouchEvent::TouchPoint::ellipseDiameters() const
-{
- return d->ellipseDiameters;
-}
/*!
- Returns a velocity vector for this touch point.
+ Returns a velocity vector for this point.
The vector is in the screen's coordinate system, using pixels per seconds for the magnitude.
- \note The returned vector is only valid if the touch device's capabilities include QPointingDevice::Velocity.
-
- \sa QPointingDevice::capabilities(), device()
-*/
-QVector2D QTouchEvent::TouchPoint::velocity() const
-{
- return d->velocity;
-}
-
-/*!
- Returns additional information about the touch point.
-
- \sa QTouchEvent::TouchPoint::InfoFlags
- */
-QTouchEvent::TouchPoint::InfoFlags QTouchEvent::TouchPoint::flags() const
-{
- return d->flags;
-}
-
-/*!
- \since 5.0
- Returns the raw, unfiltered positions for the touch point. The positions are in native screen coordinates.
- To get local coordinates you can use mapFromGlobal() of the QWindow returned by QTouchEvent::window().
-
- \note Returns an empty list if the touch device's capabilities do not include QPointingDevice::RawPositions.
-
- \note Native screen coordinates refer to the native orientation of the screen which, in case of
- mobile devices, is typically portrait. This means that on systems capable of screen orientation
- changes the positions in this list will not reflect the current orientation (unlike pos(),
- screenPos(), etc.) and will always be reported in the native orientation.
+ \note The returned vector is only valid if the device's capabilities include QInputDevice::Velocity.
- \sa QPointingDevice::capabilities(), device(), window()
- */
-QList<QPointF> QTouchEvent::TouchPoint::rawScreenPositions() const
-{
- return d->rawScreenPositions;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setId(int id)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->id = id;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setUniqueId(qint64 uid)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->uniqueId = QPointingDeviceUniqueId::fromNumericId(uid);
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setState(Qt::TouchPointStates state)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->state = state;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setPos(const QPointF &pos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->pos = pos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->scenePos = scenePos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->screenPos = screenPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setNormalizedPos(const QPointF &normalizedPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->normalizedPos = normalizedPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->startPos = startPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->startScenePos = startScenePos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->startScreenPos = startScreenPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setStartNormalizedPos(const QPointF &startNormalizedPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->startNormalizedPos = startNormalizedPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->lastPos = lastPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->lastScenePos = lastScenePos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->lastScreenPos = lastScreenPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalizedPos)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->lastNormalizedPos = lastNormalizedPos;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setPressure(qreal pressure)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->pressure = pressure;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setRotation(qreal angle)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->rotation = angle;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setEllipseDiameters(const QSizeF &dia)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->ellipseDiameters = dia;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setVelocity(const QVector2D &v)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->velocity = v;
-}
-
-/*! \internal */
-void QTouchEvent::TouchPoint::setRawScreenPositions(const QList<QPointF> &positions)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->rawScreenPositions = positions;
-}
-
-/*!
- \internal
-*/
-void QTouchEvent::TouchPoint::setFlags(InfoFlags flags)
-{
- if (d->ref.loadRelaxed() != 1)
- d = d->detach();
- d->flags = flags;
-}
-
-/*!
- \fn QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::TouchPoint &other)
- \internal
- */
-
-/*!
- \fn QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(QTouchEvent::TouchPoint &&other)
- \internal
- */
-/*!
- \fn void QTouchEvent::TouchPoint::swap(TouchPoint &other);
- \internal
+ \sa QInputDevice::capabilities(), device()
*/
/*!
@@ -4936,7 +4634,7 @@ Qt::ApplicationState QApplicationStateChangeEvent::applicationState() const
be very inefficient. Use a QList instead, which has the same API as QList, but more
efficient storage.
- \sa QTouchEvent::TouchPoint
+ \sa QEventPoint
*/
/*!
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index baf39439df..8cd8659bce 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -46,6 +46,7 @@
#include <QtCore/qiodevice.h>
#include <QtCore/qlist.h>
#include <QtCore/qnamespace.h>
+#include <QtCore/qpointer.h>
#include <QtCore/qstring.h>
#include <QtCore/qurl.h>
#include <QtCore/qvariant.h>
@@ -64,6 +65,7 @@ class QFile;
class QAction;
class QInputDevice;
class QPointingDevice;
+class QPointerEvent;
class QScreen;
#if QT_CONFIG(gestures)
class QGesture;
@@ -80,15 +82,130 @@ public:
inline void setModifiers(Qt::KeyboardModifiers amodifiers) { modState = amodifiers; }
inline ulong timestamp() const { return ts; }
inline void setTimestamp(ulong atimestamp) { ts = atimestamp; }
+
protected:
const QInputDevice *m_dev = nullptr;
- Qt::KeyboardModifiers modState;
+ Qt::KeyboardModifiers modState = Qt::NoModifier;
ulong ts;
+ qint64 m_extra = 0; // reserved, unused for now
+};
+
+namespace QTest {
+ class QTouchEventSequence; // just for the friend declaration below
+}
+
+class Q_GUI_EXPORT QEventPoint
+{
+ Q_GADGET
+public:
+ enum State : quint8 {
+ Unknown = Qt::TouchPointUnknownState,
+ Stationary = Qt::TouchPointStationary,
+ Pressed = Qt::TouchPointPressed,
+ Updated = Qt::TouchPointMoved,
+ Released = Qt::TouchPointReleased
+ };
+ Q_DECLARE_FLAGS(States, State)
+ Q_FLAG(States)
+
+ QEventPoint(int id = -1, const QPointerEvent *parent = nullptr);
+ QEventPoint(int pointId, State state, const QPointF &scenePosition, const QPointF &globalPosition);
+
+ const QPointerEvent *event() const { return m_parent; }
+ QPointF position() const { return m_pos; }
+ QPointF pressPosition() const { return m_globalPressPos - m_globalPos + m_pos; }
+ QPointF grabPosition() const { return m_globalGrabPos - m_globalPos + m_pos; }
+ QPointF lastPosition() const { return m_globalLastPos - m_globalPos + m_pos; }
+ QPointF scenePosition() const { return m_scenePos; }
+ QPointF scenePressPosition() const { return m_globalPressPos - m_globalPos + m_scenePos; }
+ QPointF sceneGrabPosition() const { return m_globalGrabPos - m_globalPos + m_scenePos; }
+ QPointF sceneLastPosition() const { return m_globalLastPos - m_globalPos + m_scenePos; }
+ QPointF globalPosition() const { return m_globalPos; }
+ QPointF globalPressPosition() const { return m_globalPressPos; }
+ QPointF globalGrabPosition() const { return m_globalGrabPos; }
+ QPointF globalLastPosition() const { return m_globalLastPos; }
+
+#if QT_DEPRECATED_SINCE(6, 0)
+ // QEventPoint replaces QTouchEvent::TouchPoint, so we need all its old accessors, for now
+ QT_DEPRECATED_VERSION_X_6_0("Use position()")
+ QPointF pos() const { return position(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use pressPosition()")
+ QPointF startPos() const { return pressPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use scenePosition()")
+ QPointF scenePos() const { return scenePosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use scenePressPosition()")
+ QPointF startScenePos() const { return scenePressPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
+ QPointF screenPos() const { return globalPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use globalPressPosition()")
+ QPointF startScreenPos() const { return globalPressPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use globalPressPosition()")
+ QPointF startNormalizedPos() const;
+ QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
+ QPointF normalizedPos() const;
+ QT_DEPRECATED_VERSION_X_6_0("Use lastPosition()")
+ QPointF lastPos() const { return lastPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use sceneLastPosition()")
+ QPointF lastScenePos() const { return sceneLastPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use globalLastPosition()")
+ QPointF lastScreenPos() const { return globalLastPosition(); }
+ QT_DEPRECATED_VERSION_X_6_0("Use globalLastPosition()")
+ QPointF lastNormalizedPos() const;
+#endif // QT_DEPRECATED_SINCE(6, 0)
+ QVector2D velocity() const { return m_velocity; }
+ State state() const { return m_state; }
+ int id() const { return m_pointId; }
+ QPointingDeviceUniqueId uniqueId() const { return m_uniqueId; }
+ qreal timeHeld() const { return (m_timestamp - m_pressTimestamp) / qreal(1000); }
+ qreal pressure() const { return m_pressure; }
+ qreal rotation() const { return m_rotation; }
+ QSizeF ellipseDiameters() const { return m_ellipseDiameters; }
+
+ bool isAccepted() const { return m_accept; }
+ void setAccepted(bool accepted = true);
+ QObject *exclusiveGrabber() const { return m_exclusiveGrabber.data(); }
+ void setExclusiveGrabber(QObject *exclusiveGrabber);
+ void cancelExclusiveGrab();
+ void cancelPassiveGrab(QObject *grabber);
+ bool removePassiveGrabber(QObject *grabber);
+ void cancelAllGrabs(QObject *grabber);
+ const QList<QPointer <QObject>> &passiveGrabbers() const { return m_passiveGrabbers; }
+ void setPassiveGrabbers(const QList<QPointer <QObject>> &grabbers);
+ void clearPassiveGrabbers();
+
+protected:
+ const QPointerEvent *m_parent = nullptr;
+ QPointF m_pos, m_scenePos, m_globalPos,
+ m_globalPressPos, m_globalGrabPos, m_globalLastPos;
+ qreal m_pressure = 1;
+ qreal m_rotation = 0;
+ QSizeF m_ellipseDiameters = QSizeF(0, 0);
+ QVector2D m_velocity;
+ QPointer<QObject> m_exclusiveGrabber;
+ QList<QPointer <QObject> > m_passiveGrabbers;
+ ulong m_timestamp = 0;
+ ulong m_pressTimestamp = 0;
+ QPointingDeviceUniqueId m_uniqueId;
+ int m_pointId = -1;
+ State m_state : 8;
+ quint32 m_accept : 1;
+ quint32 m_stationaryWithModifiedProperty : 1;
+ quint32 m_reserved : 22;
+
+ friend class QTest::QTouchEventSequence;
};
+#ifndef QT_NO_DEBUG_STREAM
+Q_GUI_EXPORT QDebug operator<<(QDebug, const QEventPoint &);
+#endif
+
class Q_GUI_EXPORT QPointerEvent : public QInputEvent
{
public:
+ virtual ~QPointerEvent();
+ virtual int pointCount() const = 0;
+ virtual const QEventPoint &point(int i) const = 0;
+
explicit QPointerEvent(Type type, const QPointingDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
const QPointingDevice *pointingDevice() const;
QPointingDevice::PointerType pointerType() const {
@@ -96,10 +213,38 @@ public:
}
};
-class Q_GUI_EXPORT QEnterEvent : public QEvent
+class Q_GUI_EXPORT QSinglePointEvent : public QPointerEvent
{
public:
- QEnterEvent(const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos);
+ QSinglePointEvent();
+ QSinglePointEvent(Type type, const QPointingDevice *dev, const QPointF &localPos,
+ const QPointF &scenePos, const QPointF &globalPos,
+ Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons buttons = Qt::NoButton,
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ int pointCount() const override { return 1; }
+ const QEventPoint &point(int i) const override { Q_ASSERT(i == 0); return m_point; }
+
+ inline Qt::MouseButton button() const { return m_button; }
+ inline Qt::MouseButtons buttons() const { return m_mouseState; }
+
+ inline QPointF position() const { return m_point.position(); }
+ inline QPointF scenePosition() const { return m_point.scenePosition(); }
+ inline QPointF globalPosition() const { return m_point.globalPosition(); }
+
+protected:
+ QEventPoint m_point;
+ Qt::MouseButton m_button = Qt::NoButton;
+ Qt::MouseButtons m_mouseState = Qt::NoButton;
+ quint32 m_source : 8; // actually Qt::MouseEventSource
+ quint32 m_doubleClick : 1;
+ quint32 m_reserved : 7; // subclasses dovetail their flags, so we don't reserve all 32 bits here
+};
+
+class Q_GUI_EXPORT QEnterEvent : public QSinglePointEvent
+{
+public:
+ QEnterEvent(const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
~QEnterEvent();
#if QT_DEPRECATED_SINCE(6, 0)
@@ -124,29 +269,26 @@ public:
QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
QPointF screenPos() const { return globalPosition(); }
#endif // QT_DEPRECATED_SINCE(6, 0)
-
- QPointF position() const { return l; }
- QPointF scenePosition() const { return s; }
- QPointF globalPosition() const { return g; }
-
-protected:
- QPointF l, s, g;
};
-class Q_GUI_EXPORT QMouseEvent : public QPointerEvent
+class Q_GUI_EXPORT QMouseEvent : public QSinglePointEvent
{
public:
QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton button,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
+ Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
QMouseEvent(Type type, const QPointF &localPos, const QPointF &globalPos,
Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers);
+ Qt::KeyboardModifiers modifiers,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
QMouseEvent(Type type, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers);
+ Qt::KeyboardModifiers modifiers,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
QMouseEvent(Type type, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source);
+ Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
~QMouseEvent();
#ifndef QT_NO_INTEGER_EVENT_COORDINATES
@@ -171,34 +313,18 @@ public:
QPointF windowPos() const { return scenePosition(); }
QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
QPointF screenPos() const { return globalPosition(); }
-#endif // QT_DEPRECATED_SINCE(6, 0)
-
- QPointF position() const { return l; }
- QPointF scenePosition() const { return w; }
- QPointF globalPosition() const { return g; }
-
- inline Qt::MouseButton button() const { return b; }
- inline Qt::MouseButtons buttons() const { return mouseState; }
-
- inline void setLocalPos(const QPointF &localPosition) { l = localPosition; }
-
Qt::MouseEventSource source() const;
+ QT_DEPRECATED_VERSION_X_6_0("Internal, don't use")
Qt::MouseEventFlags flags() const;
-
-protected:
- QPointF l, w, g;
- Qt::MouseButton b;
- Qt::MouseButtons mouseState;
- int caps;
- QVector2D velocity;
-
- friend class QGuiApplicationPrivate;
+#endif // QT_DEPRECATED_SINCE(6, 0)
};
-class Q_GUI_EXPORT QHoverEvent : public QInputEvent
+class Q_GUI_EXPORT QHoverEvent : public QSinglePointEvent
{
public:
- QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos,
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
~QHoverEvent();
#if QT_DEPRECATED_SINCE(6, 0)
@@ -215,63 +341,51 @@ public:
inline QPoint oldPos() const { return op.toPoint(); }
inline QPointF oldPosF() const { return op; }
- QPointF position() const { return p; }
-
protected:
- QPointF p, op;
+ quint32 mReserved : 16;
+ QPointF op; // TODO remove?
};
#if QT_CONFIG(wheelevent)
-class Q_GUI_EXPORT QWheelEvent : public QPointerEvent
+class Q_GUI_EXPORT QWheelEvent : public QSinglePointEvent
{
public:
enum { DefaultDeltasPerStep = 120 };
- QWheelEvent(QPointF pos, QPointF globalPos, QPoint pixelDelta, QPoint angleDelta,
+ QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase,
- bool inverted, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
+ bool inverted, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized,
+ const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
~QWheelEvent();
+ inline QPoint pixelDelta() const { return m_pixelDelta; }
+ inline QPoint angleDelta() const { return m_angleDelta; }
- inline QPoint pixelDelta() const { return pixelD; }
- inline QPoint angleDelta() const { return angleD; }
-
- inline QPointF position() const { return p; }
- inline QPointF globalPosition() const { return g; }
+ inline Qt::ScrollPhase phase() const { return Qt::ScrollPhase(m_phase); }
+ inline bool inverted() const { return m_invertedScrolling; }
- inline Qt::MouseButtons buttons() const { return mouseState; }
-
- inline Qt::ScrollPhase phase() const { return Qt::ScrollPhase(ph); }
- inline bool inverted() const { return invertedScrolling; }
-
- Qt::MouseEventSource source() const { return Qt::MouseEventSource(src); }
+ Qt::MouseEventSource source() const { return Qt::MouseEventSource(m_source); }
protected:
- QPointF p;
- QPointF g;
- QPoint pixelD;
- QPoint angleD;
- Qt::MouseButtons mouseState;
- uint src: 2;
- uint ph : 3;
- bool invertedScrolling : 1;
- int reserved : 26;
-
- friend class QApplication;
+ quint32 m_phase : 3;
+ quint32 m_invertedScrolling : 1;
+ quint32 m_reserved : 12;
+ QPoint m_pixelDelta;
+ QPoint m_angleDelta;
};
#endif
#if QT_CONFIG(tabletevent)
-class Q_GUI_EXPORT QTabletEvent : public QPointerEvent
+class Q_GUI_EXPORT QTabletEvent : public QSinglePointEvent
{
- Q_GADGET
public:
QTabletEvent(Type t, const QPointF &pos, const QPointF &globalPos,
int deviceType, int pointerType, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z,
Qt::KeyboardModifiers keyState, qint64 uniqueID,
Qt::MouseButton button, Qt::MouseButtons buttons);
- QTabletEvent(Type t, const QPointingDevice *dev, const QPointF &pos, const QPointF &globalPos,
+ QTabletEvent(Type t, const QPointingDevice *device,
+ const QPointF &pos, const QPointF &globalPos,
qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z,
Qt::KeyboardModifiers keyState,
@@ -300,37 +414,31 @@ public:
inline qreal hiResGlobalX() const { return globalPosition().x(); }
QT_DEPRECATED_VERSION_X_6_0("use globalPosition().y()")
inline qreal hiResGlobalY() const { return globalPosition().y(); }
-#endif
- inline QPointF position() const { return mPos; }
- inline QPointF globalPosition() const { return mGPos; }
+ QT_DEPRECATED_VERSION_X_6_0("use pointingDevice().uniqueId()")
inline qint64 uniqueId() const { return pointingDevice() ? pointingDevice()->uniqueId().numericId() : -1; }
- inline qreal pressure() const { return mPress; }
+#endif
+ inline qreal pressure() const { return point(0).pressure(); }
+ inline qreal rotation() const { return point(0).rotation(); }
inline int z() const { return mZ; }
inline qreal tangentialPressure() const { return mTangential; }
- inline qreal rotation() const { return mRot; }
inline int xTilt() const { return mXT; }
inline int yTilt() const { return mYT; }
- inline Qt::MouseButton button() const { return mButton; }
- inline Qt::MouseButtons buttons() const { return mButtons; }
protected:
- QPointF mPos, mGPos;
+ quint32 mReserved : 16;
int mXT, mYT, mZ;
- qreal mPress, mTangential, mRot;
- // TODO refactor to parent class along with QMouseEvent's button storage
- Qt::MouseButton mButton;
- Qt::MouseButtons mButtons;
+ qreal mTangential;
};
#endif // QT_CONFIG(tabletevent)
#if QT_CONFIG(gestures)
-class Q_GUI_EXPORT QNativeGestureEvent : public QPointerEvent
+class Q_GUI_EXPORT QNativeGestureEvent : public QSinglePointEvent
{
public:
QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *dev, const QPointF &localPos, const QPointF &scenePos,
const QPointF &globalPos, qreal value, ulong sequenceId, quint64 intArgument);
~QNativeGestureEvent();
- Qt::NativeGestureType gestureType() const { return mGestureType; }
+ Qt::NativeGestureType gestureType() const { return Qt::NativeGestureType(mGestureType); }
qreal value() const { return mRealValue; }
#if QT_DEPRECATED_SINCE(6, 0)
@@ -348,15 +456,9 @@ public:
QPointF screenPos() const { return globalPosition(); }
#endif
- QPointF position() const { return mLocalPos; }
- QPointF scenePosition() const { return mScenePos; }
- QPointF globalPosition() const { return mGlobalPos; }
-
protected:
- Qt::NativeGestureType mGestureType;
- QPointF mLocalPos;
- QPointF mScenePos;
- QPointF mGlobalPos;
+ quint32 mGestureType : 4;
+ quint32 mReserved : 12;
qreal mRealValue;
ulong mSequenceId;
quint64 mIntValue;
@@ -370,7 +472,8 @@ public:
bool autorep = false, ushort count = 1);
QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
- const QString &text = QString(), bool autorep = false, ushort count = 1);
+ const QString &text = QString(), bool autorep = false, ushort count = 1,
+ const QInputDevice *device = QInputDevice::primaryKeyboard());
~QKeyEvent();
int key() const { return k; }
@@ -829,156 +932,34 @@ class QTouchEventTouchPointPrivate;
class Q_GUI_EXPORT QTouchEvent : public QPointerEvent
{
public:
- class Q_GUI_EXPORT TouchPoint
- {
- public:
- enum InfoFlag {
- Pen = 0x0001,
- Token = 0x0002
- };
-#ifndef Q_MOC_RUN
- // otherwise moc gives
- // Error: Meta object features not supported for nested classes
- Q_DECLARE_FLAGS(InfoFlags, InfoFlag)
-#endif
-
- explicit TouchPoint(int id = -1);
- TouchPoint(const TouchPoint &other);
- TouchPoint(TouchPoint &&other) noexcept
- : d(nullptr)
- { qSwap(d, other.d); }
- TouchPoint &operator=(TouchPoint &&other) noexcept
- { qSwap(d, other.d); return *this; }
- ~TouchPoint();
-
- TouchPoint &operator=(const TouchPoint &other)
- { if ( d != other.d ) { TouchPoint copy(other); swap(copy); } return *this; }
-
- void swap(TouchPoint &other) noexcept
- { qSwap(d, other.d); }
-
- int id() const;
- QPointingDeviceUniqueId uniqueId() const;
-
- Qt::TouchPointState state() const;
-
-#if QT_DEPRECATED_SINCE(6, 0)
- QT_DEPRECATED_VERSION_X_6_0("Use position()")
- QPointF pos() const { return position(); }
- QT_DEPRECATED_VERSION_X_6_0("Use pressPosition()")
- QPointF startPos() const { return pressPosition(); }
-
- QT_DEPRECATED_VERSION_X_6_0("Use scenePosition()")
- QPointF scenePos() const { return scenePosition(); }
- QT_DEPRECATED_VERSION_X_6_0("Use scenePressPosition()")
- QPointF startScenePos() const { return scenePressPosition(); }
-
- QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
- QPointF screenPos() const { return globalPosition(); }
- QT_DEPRECATED_VERSION_X_6_0("Use globalPressPosition()")
- QPointF startScreenPos() const { return globalPressPosition(); }
-#endif // QT_DEPRECATED_SINCE(6, 0)
-
- // TODO deprecate these after finding good replacements (use QPointingDevice::globalArea?)
- QPointF normalizedPos() const;
- QPointF startNormalizedPos() const;
-
- // TODO deprecate these after finding good replacements (store longer history perhaps?)
- QPointF lastPos() const;
- QPointF lastScenePos() const;
- QPointF lastScreenPos() const;
- QPointF lastNormalizedPos() const;
-
- QPointF position() const;
- QPointF pressPosition() const;
- QPointF scenePosition() const;
- QPointF scenePressPosition() const;
- QPointF globalPosition() const;
- QPointF globalPressPosition() const;
-
- qreal pressure() const;
- qreal rotation() const;
- QSizeF ellipseDiameters() const;
-
- QVector2D velocity() const;
- InfoFlags flags() const;
- QList<QPointF> rawScreenPositions() const;
-
- // internal
- // ### Qt 6: move private, rename appropriately, only friends can call them
-#if QT_DEPRECATED_SINCE(6, 0)
- void setId(int id);
- void setUniqueId(qint64 uid);
- void setState(Qt::TouchPointStates state);
- void setPos(const QPointF &pos);
- void setScenePos(const QPointF &scenePos);
- void setScreenPos(const QPointF &screenPos);
- void setNormalizedPos(const QPointF &normalizedPos);
- void setStartPos(const QPointF &startPos);
- void setStartScenePos(const QPointF &startScenePos);
- void setStartScreenPos(const QPointF &startScreenPos);
- void setStartNormalizedPos(const QPointF &startNormalizedPos);
- void setLastPos(const QPointF &lastPos);
- void setLastScenePos(const QPointF &lastScenePos);
- void setLastScreenPos(const QPointF &lastScreenPos);
- void setLastNormalizedPos(const QPointF &lastNormalizedPos);
- void setPressure(qreal pressure);
- void setRotation(qreal angle);
- void setEllipseDiameters(const QSizeF &dia);
- void setVelocity(const QVector2D &v);
- void setFlags(InfoFlags flags);
- void setRawScreenPositions(const QList<QPointF> &positions);
-#endif // QT_DEPRECATED_SINCE(6, 0)
-
- private:
- QTouchEventTouchPointPrivate *d;
- friend class QGuiApplication;
- friend class QGuiApplicationPrivate;
- friend class QApplication;
- friend class QApplicationPrivate;
- friend class QQuickPointerTouchEvent;
- friend class QQuickMultiPointTouchArea;
- };
+ using TouchPoint = QEventPoint; // source compat
explicit QTouchEvent(QEvent::Type eventType,
- const QPointingDevice *source = nullptr,
+ const QPointingDevice *device = nullptr,
Qt::KeyboardModifiers modifiers = Qt::NoModifier,
- Qt::TouchPointStates touchPointStates = Qt::TouchPointStates(),
- const QList<QTouchEvent::TouchPoint> &touchPoints = QList<QTouchEvent::TouchPoint>());
+ const QList<QEventPoint> &touchPoints = {});
+#if QT_DEPRECATED_SINCE(6, 0)
+ QT_DEPRECATED_VERSION_X_6_0("Use another constructor")
+ explicit QTouchEvent(QEvent::Type eventType,
+ const QPointingDevice *device,
+ Qt::KeyboardModifiers modifiers,
+ QEventPoint::States touchPointStates,
+ const QList<QEventPoint> &touchPoints = {});
+#endif
~QTouchEvent();
- inline QWindow *window() const { return _window; }
- inline QObject *target() const { return _target; }
- inline Qt::TouchPointStates touchPointStates() const { return _touchPointStates; }
- inline const QList<QTouchEvent::TouchPoint> &touchPoints() const { return _touchPoints; }
+ int pointCount() const override { return m_touchPoints.count(); }
+ const QEventPoint &point(int i) const override { return m_touchPoints.at(i); }
- // ### Qt 6: move private, rename appropriately, only friends can call them; or just let friends modify variables directly
-#if QT_DEPRECATED_SINCE(6, 0)
- inline void setWindow(QWindow *awindow) { _window = awindow; }
- inline void setTarget(QObject *atarget) { _target = atarget; }
- inline void setTouchPoints(const QList<QTouchEvent::TouchPoint> &atouchPoints) { _touchPoints = atouchPoints; }
-#endif // QT_DEPRECATED_SINCE(6, 0)
+ inline QObject *target() const { return m_target; }
+ inline QEventPoint::States touchPointStates() const { return m_touchPointStates; }
+ const QList<QEventPoint> &touchPoints() const { return m_touchPoints; }
protected:
- QWindow *_window;
- QObject *_target;
- Qt::TouchPointStates _touchPointStates;
- QList<QTouchEvent::TouchPoint> _touchPoints;
-
- friend class QGuiApplication;
- friend class QGuiApplicationPrivate;
- friend class QApplication;
- friend class QApplicationPrivate;
-#ifndef QT_NO_GRAPHICSVIEW
- friend class QGraphicsScenePrivate; // direct access to _touchPoints
-#endif
+ QObject *m_target = nullptr;
+ QEventPoint::States m_touchPointStates = QEventPoint::State::Unknown;
+ QList<QEventPoint> m_touchPoints;
};
-Q_DECLARE_TYPEINFO(QTouchEvent::TouchPoint, Q_MOVABLE_TYPE);
-Q_DECLARE_OPERATORS_FOR_FLAGS(QTouchEvent::TouchPoint::InfoFlags)
-
-#ifndef QT_NO_DEBUG_STREAM
-Q_GUI_EXPORT QDebug operator<<(QDebug, const QTouchEvent::TouchPoint &);
-#endif
class Q_GUI_EXPORT QScrollPrepareEvent : public QEvent
{
diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h
index bfe0740ace..8f0948a7fe 100644
--- a/src/gui/kernel/qevent_p.h
+++ b/src/gui/kernel/qevent_p.h
@@ -47,55 +47,113 @@
QT_BEGIN_NAMESPACE
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-class QTouchEventTouchPointPrivate
+// Private subclasses to allow accessing and modifying protected variables.
+// These should NOT hold any extra state.
+
+class QMutableEventPoint : public QEventPoint
{
public:
- inline QTouchEventTouchPointPrivate(int id)
- : ref(1),
- id(id),
- state(Qt::TouchPointReleased),
- pressure(-1),
- rotation(0),
- ellipseDiameters(0, 0),
- stationaryWithModifiedProperty(false)
- { }
-
- inline QTouchEventTouchPointPrivate *detach()
+ QMutableEventPoint(int pointId = -1, State state = QEventPoint::State::Stationary,
+ const QPointF &scenePosition = QPointF(), const QPointF &globalPosition = QPointF()) :
+ QEventPoint(pointId, state, scenePosition, globalPosition) {}
+
+ QMutableEventPoint(ulong timestamp, int pointId, State state,
+ const QPointF &position, const QPointF &scenePosition, const QPointF &globalPosition) :
+ QEventPoint(pointId, state, scenePosition, globalPosition)
{
- QTouchEventTouchPointPrivate *d = new QTouchEventTouchPointPrivate(*this);
- d->ref.storeRelaxed(1);
- if (!this->ref.deref())
- delete this;
- return d;
+ m_timestamp = timestamp;
+ m_pos = position;
}
- QAtomicInt ref;
- int id;
- QPointingDeviceUniqueId uniqueId;
- Qt::TouchPointStates state;
- QPointF pos, scenePos, screenPos, normalizedPos,
- startPos, startScenePos, startScreenPos, startNormalizedPos,
- lastPos, lastScenePos, lastScreenPos, lastNormalizedPos;
- qreal pressure;
- qreal rotation;
- QSizeF ellipseDiameters;
- QVector2D velocity;
- QTouchEvent::TouchPoint::InfoFlags flags;
- bool stationaryWithModifiedProperty : 1;
- QList<QPointF> rawScreenPositions;
+ static QMutableEventPoint *from(QEventPoint *me) { return static_cast<QMutableEventPoint *>(me); }
+
+ static QMutableEventPoint &from(QEventPoint &me) { return static_cast<QMutableEventPoint &>(me); }
+
+ bool stationaryWithModifiedProperty() const { return m_stationaryWithModifiedProperty; }
+
+ void setId(int pointId) { m_pointId = pointId; }
+
+ void setParent(const QPointerEvent *p) { m_parent = p; }
+
+ void setTimestamp(const ulong t) { m_timestamp = t; }
+
+ void setState(QEventPoint::State state) { m_state = state; }
+
+ void setUniqueId(const QPointingDeviceUniqueId &uid) { m_uniqueId = uid; }
+
+ void setPosition(const QPointF &pos) { m_pos = pos; }
+
+ void setScenePosition(const QPointF &pos) { m_scenePos = pos; }
+
+ void setGlobalPosition(const QPointF &pos) { m_globalPos = pos; }
+
+#if QT_DEPRECATED_SINCE(6, 0)
+ // temporary replacements for QTouchEvent::TouchPoint setters, mainly to make porting easier
+ QT_DEPRECATED_VERSION_X_6_0("Use setPosition()")
+ void setPos(const QPointF &pos) { m_pos = pos; }
+ QT_DEPRECATED_VERSION_X_6_0("Use setScenePosition()")
+ void setScenePos(const QPointF &pos) { m_scenePos = pos; }
+ QT_DEPRECATED_VERSION_X_6_0("Use setGlobalPosition()")
+ void setScreenPos(const QPointF &pos) { m_globalPos = pos; }
+#endif
+
+ void setGlobalPressPosition(const QPointF &pos) { m_globalPressPos = pos; }
+
+ void setGlobalGrabPosition(const QPointF &pos) { m_globalGrabPos = pos; }
+
+ void setGlobalLastPosition(const QPointF &pos) { m_globalLastPos = pos; }
+
+ void setEllipseDiameters(const QSizeF &d) { m_ellipseDiameters = d; }
+
+ void setPressure(qreal v) { m_pressure = v; }
+
+ void setRotation(qreal v) { m_rotation = v; }
+
+ void setVelocity(const QVector2D &v) { m_velocity = v; }
+
+ void setStationaryWithModifiedProperty(bool s = true) { m_stationaryWithModifiedProperty = s; }
};
+static_assert(sizeof(QMutableEventPoint) == sizeof(QEventPoint));
+
+class QMutableTouchEvent : public QTouchEvent
+{
+public:
+ QMutableTouchEvent(QEvent::Type eventType,
+ const QPointingDevice *device = nullptr,
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier,
+ const QList<QEventPoint> &touchPoints = QList<QEventPoint>()) :
+ QTouchEvent(eventType, device, modifiers, touchPoints) { }
+
+ static QMutableTouchEvent *from(QTouchEvent *e) { return static_cast<QMutableTouchEvent *>(e); }
+
+ static QMutableTouchEvent &from(QTouchEvent &e) { return static_cast<QMutableTouchEvent &>(e); }
+
+ void setTarget(QObject *target) { m_target = target; }
+
+ QList<QEventPoint> &touchPoints() { return m_touchPoints; }
+};
+
+static_assert(sizeof(QMutableTouchEvent) == sizeof(QTouchEvent));
+
+class QMutableSinglePointEvent : public QSinglePointEvent
+{
+public:
+ static QMutableSinglePointEvent *from(QSinglePointEvent *e) { return static_cast<QMutableSinglePointEvent *>(e); }
+
+ static QMutableSinglePointEvent &from(QSinglePointEvent &e) { return static_cast<QMutableSinglePointEvent &>(e); }
+
+ QMutableEventPoint &mutablePoint() { return QMutableEventPoint::from(m_point); }
+
+ void setSource(Qt::MouseEventSource s) { m_source = s; }
+
+ bool isDoubleClick() { return m_doubleClick; }
+
+ void setDoubleClick(bool d = true) { m_doubleClick = d; }
+};
+
+static_assert(sizeof(QMutableSinglePointEvent) == sizeof(QSinglePointEvent));
+
QT_END_NAMESPACE
#endif // QEVENT_P_H
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index f6bae28625..fbfce44767 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -2159,8 +2159,8 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
if (mouseMove) {
QGuiApplicationPrivate::lastCursorPosition = globalPoint;
- const auto doubleClickDistance = e->source == Qt::MouseEventNotSynthesized ?
- mouseDoubleClickDistance : touchDoubleTapDistance;
+ const auto doubleClickDistance = (e->device && e->device->type() == QInputDevice::DeviceType::Mouse ?
+ mouseDoubleClickDistance : touchDoubleTapDistance);
if (qAbs(globalPoint.x() - mousePressX) > doubleClickDistance ||
qAbs(globalPoint.y() - mousePressY) > doubleClickDistance)
mousePressButton = Qt::NoButton;
@@ -2199,6 +2199,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
if (!window)
return;
+ const QPointingDevice *device = static_cast<const QPointingDevice *>(e->device);
#ifndef QT_NO_CURSOR
if (!e->synthetic()) {
if (const QScreen *screen = window->screen())
@@ -2206,14 +2207,14 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
const QPointF nativeLocalPoint = QHighDpi::toNativePixels(localPoint, screen);
const QPointF nativeGlobalPoint = QHighDpi::toNativePixels(globalPoint, screen);
QMouseEvent ev(type, nativeLocalPoint, nativeLocalPoint, nativeGlobalPoint,
- button, e->buttons, e->modifiers, e->source);
+ button, e->buttons, e->modifiers, e->source, device);
ev.setTimestamp(e->timestamp);
cursor->pointerEvent(ev);
}
}
#endif
- QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source);
+ QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, e->buttons, e->modifiers, e->source, device);
ev.setTimestamp(e->timestamp);
if (window->d_func()->blockedByModalWindow && !qApp->d_func()->popupActive()) {
@@ -2223,7 +2224,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
if (doubleClick && (ev.type() == QEvent::MouseButtonPress)) {
// QtBUG-25831, used to suppress delivery in qwidgetwindow.cpp
- setMouseEventFlags(&ev, ev.flags() | Qt::MouseEventCreatedDoubleClick);
+ QMutableSinglePointEvent::from(ev).setDoubleClick();
}
QGuiApplication::sendSpontaneousEvent(window, &ev);
@@ -2244,11 +2245,11 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
// avoid strange touch event sequences when several
// buttons are pressed
if (type == QEvent::MouseButtonPress && button == Qt::LeftButton) {
- point.state = Qt::TouchPointPressed;
+ point.state = QEventPoint::State::Pressed;
} else if (type == QEvent::MouseButtonRelease && button == Qt::LeftButton) {
- point.state = Qt::TouchPointReleased;
+ point.state = QEventPoint::State::Released;
} else if (type == QEvent::MouseMove && (e->buttons & Qt::LeftButton)) {
- point.state = Qt::TouchPointMoved;
+ point.state = QEventPoint::State::Updated;
} else {
return;
}
@@ -2256,7 +2257,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
points << point;
QEvent::Type type;
- QList<QTouchEvent::TouchPoint> touchPoints =
+ const QList<QEventPoint> &touchPoints =
QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, m_fakeTouchDevice, touchPoints, e->modifiers);
@@ -2268,7 +2269,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
if (!e->window.isNull() || e->nullWindow()) { // QTBUG-36364, check if window closed in response to press
const QEvent::Type doubleClickType = e->nonClientArea ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick;
QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint,
- button, e->buttons, e->modifiers, e->source);
+ button, e->buttons, e->modifiers, e->source, device);
dblClickEvent.setTimestamp(e->timestamp);
QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent);
}
@@ -2301,10 +2302,11 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh
return;
}
- QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
- mouse_buttons, e->modifiers, e->phase, e->inverted, e->source);
- ev.setTimestamp(e->timestamp);
- QGuiApplication::sendSpontaneousEvent(window, &ev);
+ const QPointingDevice *device = static_cast<const QPointingDevice *>(e->device);
+ QWheelEvent ev(localPoint, globalPoint, e->pixelDelta, e->angleDelta,
+ mouse_buttons, e->modifiers, e->phase, e->inverted, e->source, device);
+ ev.setTimestamp(e->timestamp);
+ QGuiApplication::sendSpontaneousEvent(window, &ev);
#else
Q_UNUSED(e);
#endif // QT_CONFIG(wheelevent)
@@ -2673,7 +2675,7 @@ void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::T
}
}();
QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local,
- e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventSynthesizedByQt);
+ e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventNotSynthesized, false, device);
mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
processMouseEvent(&mouseEvent);
}
@@ -2716,7 +2718,8 @@ void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::
if (e->window.isNull())
return;
- QNativeGestureEvent ev(e->type, e->device, e->pos, e->pos, e->globalPos, e->realValue, e->sequenceId, e->intValue);
+ const QPointingDevice *device = static_cast<const QPointingDevice *>(e->device);
+ QNativeGestureEvent ev(e->type, device, e->pos, e->pos, e->globalPos, e->realValue, e->sequenceId, e->intValue);
ev.setTimestamp(e->timestamp);
QGuiApplication::sendSpontaneousEvent(e->window, &ev);
}
@@ -2765,11 +2768,12 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
{
QGuiApplicationPrivate *d = self;
modifier_buttons = e->modifiers;
+ const QPointingDevice *device = static_cast<const QPointingDevice *>(e->device);
if (e->touchType == QEvent::TouchCancel) {
// The touch sequence has been canceled (e.g. by the compositor).
// Send the TouchCancel to all windows with active touches and clean up.
- QTouchEvent touchEvent(QEvent::TouchCancel, static_cast<const QPointingDevice *>(e->device), e->modifiers);
+ QTouchEvent touchEvent(QEvent::TouchCancel, device, e->modifiers);
touchEvent.setTimestamp(e->timestamp);
QHash<ActiveTouchPointsKey, ActiveTouchPointsValue>::const_iterator it
= self->activeTouchPoints.constBegin(), ite = self->activeTouchPoints.constEnd();
@@ -2782,7 +2786,6 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
}
for (QSet<QWindow *>::const_iterator winIt = windowsNeedingCancel.constBegin(),
winItEnd = windowsNeedingCancel.constEnd(); winIt != winItEnd; ++winIt) {
- touchEvent.setWindow(*winIt);
QGuiApplication::sendSpontaneousEvent(*winIt, &touchEvent);
}
if (!self->synthesizedMousePoints.isEmpty() && !e->synthetic()) {
@@ -2798,7 +2801,9 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
e->modifiers,
Qt::LeftButton,
QEvent::MouseButtonRelease,
- Qt::MouseEventSynthesizedByQt);
+ Qt::MouseEventNotSynthesized,
+ false,
+ device);
fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
processMouseEvent(&fake);
}
@@ -2816,25 +2821,22 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
self->lastTouchType = e->touchType;
QWindow *window = e->window.data();
- typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints;
+ // TODO get rid of this QPair; we don't need to accumulate combined states here anymore
+ typedef QPair<QEventPoint::States, QList<QEventPoint> > StatesAndTouchPoints;
QHash<QWindow *, StatesAndTouchPoints> windowsNeedingEvents;
bool stationaryTouchPointChangedProperty = false;
for (int i = 0; i < e->points.count(); ++i) {
- QTouchEvent::TouchPoint touchPoint = e->points.at(i);
- // explicitly detach from the original touch point that we got, so even
- // if the touchpoint structs are reused, we will make a copy that we'll
- // deliver to the user (which might want to store the struct for later use).
- touchPoint.d = touchPoint.d->detach();
+ QMutableEventPoint touchPoint = QMutableEventPoint::from(e->points[i]);
// update state
QPointer<QWindow> w;
- QTouchEvent::TouchPoint previousTouchPoint;
- ActiveTouchPointsKey touchInfoKey(static_cast<const QPointingDevice *>(e->device), touchPoint.id());
+ QEventPoint previousTouchPoint;
+ ActiveTouchPointsKey touchInfoKey(device, touchPoint.id());
ActiveTouchPointsValue &touchInfo = d->activeTouchPoints[touchInfoKey];
switch (touchPoint.state()) {
- case Qt::TouchPointPressed:
- if (e->device->type() == QInputDevice::DeviceType::TouchPad) {
+ case QEventPoint::State::Pressed:
+ if (e->device && e->device->type() == QInputDevice::DeviceType::TouchPad) {
// on touch-pads, send all touch points to the same widget
w = d->activeTouchPoints.isEmpty()
? QPointer<QWindow>()
@@ -2851,30 +2853,23 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
}
touchInfo.window = w;
- touchPoint.d->startScreenPos = touchPoint.globalPosition();
- touchPoint.d->lastScreenPos = touchPoint.globalPosition();
- touchPoint.d->startNormalizedPos = touchPoint.normalizedPos();
- touchPoint.d->lastNormalizedPos = touchPoint.normalizedPos();
- if (touchPoint.pressure() < qreal(0.))
- touchPoint.d->pressure = qreal(1.);
+ touchPoint.setGlobalPressPosition(touchPoint.globalPosition());
+ touchPoint.setGlobalLastPosition(touchPoint.globalPosition());
+ if (touchPoint.pressure() < 0)
+ touchPoint.setPressure(1);
touchInfo.touchPoint = touchPoint;
break;
- case Qt::TouchPointReleased:
+ case QEventPoint::State::Released:
w = touchInfo.window;
if (!w)
continue;
previousTouchPoint = touchInfo.touchPoint;
- touchPoint.d->startScreenPos = previousTouchPoint.globalPressPosition();
- touchPoint.d->lastScreenPos = previousTouchPoint.globalPosition();
- touchPoint.d->startPos = previousTouchPoint.pressPosition();
- touchPoint.d->lastPos = previousTouchPoint.position();
- touchPoint.d->startNormalizedPos = previousTouchPoint.startNormalizedPos();
- touchPoint.d->lastNormalizedPos = previousTouchPoint.normalizedPos();
- if (touchPoint.pressure() < qreal(0.))
- touchPoint.d->pressure = qreal(0.);
+ touchPoint.setGlobalPressPosition(previousTouchPoint.globalPressPosition());
+ touchPoint.setGlobalLastPosition(previousTouchPoint.globalPosition());
+ touchPoint.setPressure(0);
break;
@@ -2884,26 +2879,22 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
continue;
previousTouchPoint = touchInfo.touchPoint;
- touchPoint.d->startScreenPos = previousTouchPoint.globalPressPosition();
- touchPoint.d->lastScreenPos = previousTouchPoint.globalPosition();
- touchPoint.d->startPos = previousTouchPoint.pressPosition();
- touchPoint.d->lastPos = previousTouchPoint.position();
- touchPoint.d->startNormalizedPos = previousTouchPoint.startNormalizedPos();
- touchPoint.d->lastNormalizedPos = previousTouchPoint.normalizedPos();
- if (touchPoint.pressure() < qreal(0.))
- touchPoint.d->pressure = qreal(1.);
+ touchPoint.setGlobalPressPosition(previousTouchPoint.globalPressPosition());
+ touchPoint.setGlobalLastPosition(previousTouchPoint.globalPosition());
+ if (touchPoint.pressure() < 0)
+ touchPoint.setPressure(1);
// Stationary points might not be delivered down to the receiving item
// and get their position transformed, keep the old values instead.
- if (touchPoint.state() == Qt::TouchPointStationary) {
+ if (touchPoint.state() == QEventPoint::State::Stationary) {
if (touchInfo.touchPoint.velocity() != touchPoint.velocity()) {
touchInfo.touchPoint.setVelocity(touchPoint.velocity());
- touchPoint.d->stationaryWithModifiedProperty = true;
+ touchPoint.setStationaryWithModifiedProperty();
stationaryTouchPointChangedProperty = true;
}
if (!qFuzzyCompare(touchInfo.touchPoint.pressure(), touchPoint.pressure())) {
touchInfo.touchPoint.setPressure(touchPoint.pressure());
- touchPoint.d->stationaryWithModifiedProperty = true;
+ touchPoint.setStationaryWithModifiedProperty();
stationaryTouchPointChangedProperty = true;
}
} else {
@@ -2914,13 +2905,9 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
Q_ASSERT(w.data() != nullptr);
- // make the *scene* functions return the same as the *screen* functions
- // Note: touchPoint is a reference to the one from activeTouchPoints,
- // so we can modify it as long as we're careful NOT to call setters and
- // otherwise NOT to cause the d-pointer to be detached.
- touchPoint.d->scenePos = touchPoint.globalPosition();
- touchPoint.d->startScenePos = touchPoint.globalPressPosition();
- touchPoint.d->lastScenePos = touchPoint.lastScreenPos();
+ // make the *scene* position the same as the *global* position
+ // Note: touchPoint is a reference to the one from activeTouchPoints, so we can modify it.
+ touchPoint.setScenePosition(touchPoint.globalPosition());
StatesAndTouchPoints &maskAndPoints = windowsNeedingEvents[w.data()];
maskAndPoints.first |= touchPoint.state();
@@ -2937,13 +2924,13 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
QEvent::Type eventType;
switch (it.value().first) {
- case Qt::TouchPointPressed:
+ case QEventPoint::State::Pressed:
eventType = QEvent::TouchBegin;
break;
- case Qt::TouchPointReleased:
+ case QEventPoint::State::Released:
eventType = QEvent::TouchEnd;
break;
- case Qt::TouchPointStationary:
+ case QEventPoint::State::Stationary:
// don't send the event if nothing changed
if (!stationaryTouchPointChangedProperty)
continue;
@@ -2961,39 +2948,26 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
// but don't leave dangling state: e.g.
// QQuickWindowPrivate::itemForTouchPointId needs to be cleared.
QTouchEvent touchEvent(QEvent::TouchCancel,
- static_cast<const QPointingDevice *>(e->device),
+ device,
e->modifiers);
touchEvent.setTimestamp(e->timestamp);
- touchEvent.setWindow(w);
QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
}
continue;
}
- QTouchEvent touchEvent(eventType,
- static_cast<const QPointingDevice *>(e->device),
- e->modifiers,
- it.value().first, // state flags
- it.value().second); // list of touchpoints
+ const auto &touchpoints = it.value().second;
+ QMutableTouchEvent touchEvent(eventType, device, e->modifiers, touchpoints);
touchEvent.setTimestamp(e->timestamp);
- touchEvent.setWindow(w);
- const int pointCount = touchEvent.touchPoints().count();
- for (int i = 0; i < pointCount; ++i) {
- QTouchEvent::TouchPoint &touchPoint = touchEvent._touchPoints[i];
+ for (QEventPoint &pt : touchEvent.touchPoints()) {
+ auto &touchPoint = QMutableEventPoint::from(pt);
// preserve the sub-pixel resolution
const QPointF screenPos = touchPoint.globalPosition();
const QPointF delta = screenPos - screenPos.toPoint();
- touchPoint.d->pos = w->mapFromGlobal(screenPos.toPoint()) + delta;
- if (touchPoint.state() == Qt::TouchPointPressed) {
- // touchPoint is actually a reference to one that is stored in activeTouchPoints,
- // and we are now going to store the startPos and lastPos there, for the benefit
- // of future moves and releases. It's important that the d-pointer is NOT detached.
- touchPoint.d->startPos = w->mapFromGlobal(touchPoint.globalPressPosition().toPoint()) + delta;
- touchPoint.d->lastPos = w->mapFromGlobal(touchPoint.lastScreenPos().toPoint()) + delta;
- }
+ touchPoint.setPosition(w->mapFromGlobal(screenPos.toPoint()) + delta);
}
QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
@@ -3004,9 +2978,8 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
if (eventType == QEvent::TouchEnd)
self->synthesizedMousePoints.clear();
- const QList<QTouchEvent::TouchPoint> &touchPoints = touchEvent.touchPoints();
if (eventType == QEvent::TouchBegin)
- m_fakeMouseSourcePointId = touchPoints.first().id();
+ m_fakeMouseSourcePointId = touchEvent.point(0).id();
const QEvent::Type mouseType = [&]() {
switch (eventType) {
@@ -3020,8 +2993,8 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
Qt::MouseButton button = mouseType == QEvent::MouseMove ? Qt::NoButton : Qt::LeftButton;
Qt::MouseButtons buttons = mouseType == QEvent::MouseButtonRelease ? Qt::NoButton : Qt::LeftButton;
- for (int i = 0; i < touchPoints.count(); ++i) {
- const QTouchEvent::TouchPoint &touchPoint = touchPoints.at(i);
+ const auto &points = touchEvent.touchPoints();
+ for (const QEventPoint &touchPoint : points) {
if (touchPoint.id() == m_fakeMouseSourcePointId) {
if (eventType != QEvent::TouchEnd)
self->synthesizedMousePoints.insert(w, SynthesizedMouseData(
@@ -3035,7 +3008,9 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
e->modifiers,
button,
mouseType,
- Qt::MouseEventSynthesizedByQt);
+ Qt::MouseEventSynthesizedByQt,
+ false,
+ device);
fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
processMouseEvent(&fake);
break;
@@ -3049,10 +3024,9 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
// delivered. When the receiver is a widget, QApplication will access
// activeTouchPoints during delivery and therefore nothing can be removed
// before sending the event.
- for (int i = 0; i < e->points.count(); ++i) {
- QTouchEvent::TouchPoint touchPoint = e->points.at(i);
- if (touchPoint.state() == Qt::TouchPointReleased)
- d->activeTouchPoints.remove(ActiveTouchPointsKey(static_cast<const QPointingDevice *>(e->device), touchPoint.id()));
+ for (const QEventPoint &touchPoint : e->points) {
+ if (touchPoint.state() == QEventPoint::State::Released)
+ d->activeTouchPoints.remove(ActiveTouchPointsKey(device, touchPoint.id()));
}
}
@@ -4247,53 +4221,6 @@ enum MouseMasks {
MouseFlagsShift = 16
};
-int QGuiApplicationPrivate::mouseEventCaps(QMouseEvent *event)
-{
- return event->caps & MouseCapsMask;
-}
-
-QVector2D QGuiApplicationPrivate::mouseEventVelocity(QMouseEvent *event)
-{
- return event->velocity;
-}
-
-void QGuiApplicationPrivate::setMouseEventCapsAndVelocity(QMouseEvent *event, int caps, const QVector2D &velocity)
-{
- Q_ASSERT(caps <= MouseCapsMask);
- event->caps &= ~MouseCapsMask;
- event->caps |= caps & MouseCapsMask;
- event->velocity = velocity;
-}
-
-Qt::MouseEventSource QGuiApplicationPrivate::mouseEventSource(const QMouseEvent *event)
-{
- return Qt::MouseEventSource((event->caps & MouseSourceMaskDst) >> MouseSourceShift);
-}
-
-void QGuiApplicationPrivate::setMouseEventSource(QMouseEvent *event, Qt::MouseEventSource source)
-{
- // Mouse event synthesization status is encoded in the caps field because
- // QPointingDevice::Capability uses only 6 bits from it.
- int value = source;
- Q_ASSERT(value <= MouseSourceMaskSrc);
- event->caps &= ~MouseSourceMaskDst;
- event->caps |= (value & MouseSourceMaskSrc) << MouseSourceShift;
-}
-
-Qt::MouseEventFlags QGuiApplicationPrivate::mouseEventFlags(const QMouseEvent *event)
-{
- return Qt::MouseEventFlags((event->caps & MouseFlagsCapsMask) >> MouseFlagsShift);
-}
-
-void QGuiApplicationPrivate::setMouseEventFlags(QMouseEvent *event, Qt::MouseEventFlags flags)
-{
- // use the 0x00FF0000 byte from caps (containing up to 7 mouse event flags)
- unsigned int value = flags;
- Q_ASSERT(value <= Qt::MouseEventFlagMask);
- event->caps &= ~MouseFlagsCapsMask;
- event->caps |= (value & Qt::MouseEventFlagMask) << MouseFlagsShift;
-}
-
QInputDeviceManager *QGuiApplicationPrivate::inputDeviceManager()
{
Q_ASSERT(QGuiApplication::instance());
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index c5c4bd09d1..b469c94319 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -293,7 +293,7 @@ public:
struct ActiveTouchPointsValue {
QPointer<QWindow> window;
QPointer<QObject> target;
- QTouchEvent::TouchPoint touchPoint;
+ QMutableEventPoint touchPoint;
};
QHash<ActiveTouchPointsKey, ActiveTouchPointsValue> activeTouchPoints;
QEvent::Type lastTouchType;
@@ -306,16 +306,6 @@ public:
};
QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
- static int mouseEventCaps(QMouseEvent *event);
- static QVector2D mouseEventVelocity(QMouseEvent *event);
- static void setMouseEventCapsAndVelocity(QMouseEvent *event, int caps, const QVector2D &velocity);
-
- static Qt::MouseEventSource mouseEventSource(const QMouseEvent *event);
- static void setMouseEventSource(QMouseEvent *event, Qt::MouseEventSource source);
-
- static Qt::MouseEventFlags mouseEventFlags(const QMouseEvent *event);
- static void setMouseEventFlags(QMouseEvent *event, Qt::MouseEventFlags flags);
-
static QInputDeviceManager *inputDeviceManager();
const QColorTrcLut *colorProfileForA8Text();
diff --git a/src/gui/kernel/qinputdevice.h b/src/gui/kernel/qinputdevice.h
index b160c796d4..667338fe02 100644
--- a/src/gui/kernel/qinputdevice.h
+++ b/src/gui/kernel/qinputdevice.h
@@ -81,7 +81,6 @@ public:
Area = 0x0002,
Pressure = 0x0004,
Velocity = 0x0008,
- RawPositions = 0x0010,
NormalizedPosition = 0x0020,
MouseEmulation = 0x0040,
Scroll = 0x0100,
diff --git a/src/gui/kernel/qpointingdevice.cpp b/src/gui/kernel/qpointingdevice.cpp
index 8242354ac7..05bea8ccd7 100644
--- a/src/gui/kernel/qpointingdevice.cpp
+++ b/src/gui/kernel/qpointingdevice.cpp
@@ -79,7 +79,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices)
In this type of device, the touch surface and display are integrated.
This means the surface and display typically have the same size, such
that there is a direct relationship between the touch points' physical
- positions and the coordinate reported by QTouchEvent::TouchPoint. As a
+ positions and the coordinate reported by QEventPoint. As a
result, Qt allows the user to interact directly with multiple QWidgets,
QGraphicsItems, or Qt Quick Items at the same time.
@@ -159,12 +159,6 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices)
Indicates that velocity information is available, meaning that
QPointerEvent::EventPoint::velocity() returns a valid vector.
- \value RawPositions
- Indicates that the list returned by
- QPointerEvent::EventPoint::rawScreenPositions() may contain one or more
- positions for each touch point. This is relevant when the touch input
- gets filtered or corrected on the driver level.
-
\value NormalizedPosition
Indicates that the normalized position is available, meaning that
QPointerEvent::EventPoint::normalizedPos() returns a valid value.
diff --git a/src/gui/kernel/qsimpledrag.cpp b/src/gui/kernel/qsimpledrag.cpp
index 58fdf7a2c3..20aacbdd16 100644
--- a/src/gui/kernel/qsimpledrag.cpp
+++ b/src/gui/kernel/qsimpledrag.cpp
@@ -184,7 +184,7 @@ bool QBasicDrag::eventFilter(QObject *o, QEvent *e)
QMouseEvent *newRelease = new QMouseEvent(release->type(),
releaseWindowPos, releaseWindowPos, release->globalPosition(),
release->button(), release->buttons(),
- release->modifiers(), release->source());
+ release->modifiers(), release->source(), release->pointingDevice());
QCoreApplication::postEvent(o, newRelease);
return true; // defer mouse release events until drag event loop has returned
}
diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
index 1a0d582465..d812c17c4e 100644
--- a/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/src/gui/kernel/qwindowsysteminterface.cpp
@@ -623,37 +623,30 @@ void QWindowSystemInterface::registerInputDevice(const QInputDevice *device)
QInputDevicePrivate::registerDevice(device);
}
-QList<QTouchEvent::TouchPoint>
+QList<QEventPoint>
QWindowSystemInterfacePrivate::fromNativeTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points,
const QWindow *window, QEvent::Type *type)
{
- QList<QTouchEvent::TouchPoint> touchPoints;
- Qt::TouchPointStates states;
- QTouchEvent::TouchPoint p;
+ QList<QEventPoint> touchPoints;
+ QEventPoint::States states;
touchPoints.reserve(points.count());
QList<QWindowSystemInterface::TouchPoint>::const_iterator point = points.constBegin();
QList<QWindowSystemInterface::TouchPoint>::const_iterator end = points.constEnd();
while (point != end) {
- p.setId(point->id);
+ QPointF globalPos = QHighDpi::fromNativePixels(point->area.center(), window);
+ QMutableEventPoint p(point->id, point->state, globalPos, globalPos);
+ states |= point->state;
if (point->uniqueId >= 0)
- p.setUniqueId(point->uniqueId);
+ p.setUniqueId(QPointingDeviceUniqueId::fromNumericId(point->uniqueId));
p.setPressure(point->pressure);
p.setRotation(point->rotation);
- states |= point->state;
- p.setState(point->state);
-
- p.setScreenPos(QHighDpi::fromNativePixels(point->area.center(), window));
p.setEllipseDiameters(QHighDpi::fromNativePixels(point->area.size(), window));
+ p.setVelocity(QHighDpi::fromNativePixels(point->velocity, window));
// The local pos is not set: it will be calculated
// when the event gets processed by QGuiApplication.
- p.setNormalizedPos(QHighDpi::fromNativePixels(point->normalPosition, window));
- p.setVelocity(QHighDpi::fromNativePixels(point->velocity, window));
- p.setFlags(point->flags);
- p.setRawScreenPositions(QHighDpi::fromNativePixels(point->rawPositions, window));
-
touchPoints.append(p);
++point;
}
@@ -661,37 +654,28 @@ QList<QTouchEvent::TouchPoint>
// Determine the event type based on the combined point states.
if (type) {
*type = QEvent::TouchUpdate;
- if (states == Qt::TouchPointPressed)
+ if (states == QEventPoint::State::Pressed)
*type = QEvent::TouchBegin;
- else if (states == Qt::TouchPointReleased)
+ else if (states == QEventPoint::State::Released)
*type = QEvent::TouchEnd;
}
return touchPoints;
}
-QList<QWindowSystemInterface::TouchPoint>
- QWindowSystemInterfacePrivate::toNativeTouchPoints(const QList<QTouchEvent::TouchPoint>& pointList,
- const QWindow *window)
-{
- QList<QWindowSystemInterface::TouchPoint> newList;
- newList.reserve(pointList.size());
- for (const QTouchEvent::TouchPoint &pt : pointList) {
- QWindowSystemInterface::TouchPoint p;
- p.id = pt.id();
- p.flags = pt.flags();
- p.normalPosition = QHighDpi::toNativeLocalPosition(pt.normalizedPos(), window);
- QRectF area(QPointF(), pt.ellipseDiameters());
- area.moveCenter(pt.globalPosition());
- // TODO store ellipseDiameters in QWindowSystemInterface::TouchPoint or just use QTouchEvent::TouchPoint
- p.area = QHighDpi::toNativePixels(area, window);
- p.pressure = pt.pressure();
- p.state = pt.state();
- p.velocity = QHighDpi::toNativePixels(pt.velocity(), window);
- p.rawPositions = QHighDpi::toNativePixels(pt.rawScreenPositions(), window);
- newList.append(p);
- }
- return newList;
+QWindowSystemInterface::TouchPoint
+QWindowSystemInterfacePrivate::toNativeTouchPoint(const QEventPoint &pt, const QWindow *window)
+{
+ QWindowSystemInterface::TouchPoint p;
+ p.id = pt.id();
+ QRectF area(QPointF(), pt.ellipseDiameters());
+ area.moveCenter(pt.globalPosition());
+ // TODO store ellipseDiameters in QWindowSystemInterface::TouchPoint or just use QEventPoint
+ p.area = QHighDpi::toNativePixels(area, window);
+ p.pressure = pt.pressure();
+ p.state = pt.state();
+ p.velocity = QHighDpi::toNativePixels(pt.velocity(), window);
+ return p;
}
QT_DEFINE_QPA_EVENT_HANDLER(bool, handleTouchEvent, QWindow *window, const QPointingDevice *device,
@@ -711,7 +695,7 @@ QT_DEFINE_QPA_EVENT_HANDLER(bool, handleTouchEvent, QWindow *window, ulong times
return false;
QEvent::Type type;
- QList<QTouchEvent::TouchPoint> touchPoints =
+ QList<QEventPoint> touchPoints =
QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
QWindowSystemInterfacePrivate::TouchEvent *e =
new QWindowSystemInterfacePrivate::TouchEvent(window, timestamp, type, device, touchPoints, mods);
@@ -730,7 +714,7 @@ QT_DEFINE_QPA_EVENT_HANDLER(bool, handleTouchCancelEvent, QWindow *window, ulong
{
QWindowSystemInterfacePrivate::TouchEvent *e =
new QWindowSystemInterfacePrivate::TouchEvent(window, timestamp, QEvent::TouchCancel, device,
- QList<QTouchEvent::TouchPoint>(), mods);
+ QList<QEventPoint>(), mods);
return QWindowSystemInterfacePrivate::handleWindowSystemEvent<Delivery>(e);
}
@@ -1248,7 +1232,7 @@ namespace QTest
}
Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *window, const QPointingDevice *device,
- const QList<QTouchEvent::TouchPoint> &points,
+ const QList<QEventPoint> &points,
Qt::KeyboardModifiers mods = Qt::NoModifier)
{
QWindowSystemInterface::handleTouchEvent<QWindowSystemInterface::SynchronousDelivery>(window, device,
diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h
index 5116c72120..fe90934e52 100644
--- a/src/gui/kernel/qwindowsysteminterface.h
+++ b/src/gui/kernel/qwindowsysteminterface.h
@@ -156,7 +156,7 @@ public:
bool inverted = false);
struct TouchPoint {
- TouchPoint() : id(0), uniqueId(-1), pressure(0), rotation(0), state(Qt::TouchPointStationary) { }
+ TouchPoint() : id(0), uniqueId(-1), pressure(0), rotation(0), state(QEventPoint::State::Stationary) { }
int id; // for application use
qint64 uniqueId; // for TUIO: object/token ID; otherwise empty
// TODO for TUIO 2.0: add registerPointerUniqueID(QPointingDeviceUniqueId)
@@ -166,9 +166,8 @@ public:
qreal pressure; // 0 to 1
qreal rotation; // rotation applied to the elliptical contact patch
// 0 means pointing straight up; 0 if unknown (like QTabletEvent::rotation)
- Qt::TouchPointState state; //Qt::TouchPoint{Pressed|Moved|Stationary|Released}
+ QEventPoint::State state; // Pressed|Updated|Stationary|Released
QVector2D velocity; // in screen coordinate system, pixels / seconds
- QTouchEvent::TouchPoint::InfoFlags flags;
QList<QPointF> rawPositions; // in screen coordinates
};
diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h
index 6db1fc2499..bca4786b6d 100644
--- a/src/gui/kernel/qwindowsysteminterface_p.h
+++ b/src/gui/kernel/qwindowsysteminterface_p.h
@@ -50,6 +50,7 @@
// We mean it.
//
+#include <QtGui/private/qevent_p.h>
#include <QtGui/private/qtguiglobal_p.h>
#include "qwindowsysteminterface.h"
@@ -234,14 +235,20 @@ public:
const QInputDevice *device;
};
- class MouseEvent : public InputEvent {
+ class PointerEvent : public InputEvent {
+ public:
+ PointerEvent(QWindow * w, ulong time, EventType t, Qt::KeyboardModifiers mods, const QPointingDevice *device)
+ : InputEvent(w, time, t, mods, device) {}
+ };
+
+ class MouseEvent : public PointerEvent {
public:
MouseEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global,
Qt::MouseButtons state, Qt::KeyboardModifiers mods,
Qt::MouseButton b, QEvent::Type type,
Qt::MouseEventSource src = Qt::MouseEventNotSynthesized, bool frame = false,
const QPointingDevice *device = QPointingDevice::primaryPointingDevice())
- : InputEvent(w, time, Mouse, mods, device), localPos(local), globalPos(global),
+ : PointerEvent(w, time, Mouse, mods, device), localPos(local), globalPos(global),
buttons(state), source(src), nonClientArea(frame), button(b), buttonType(type) { }
// ### In Qt6 this method can be removed as there won't be need for compatibility code path
@@ -260,12 +267,12 @@ public:
QEvent::Type buttonType;
};
- class WheelEvent : public InputEvent {
+ class WheelEvent : public PointerEvent {
public:
WheelEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, QPoint pixelD, QPoint angleD, int qt4D, Qt::Orientation qt4O,
Qt::KeyboardModifiers mods, Qt::ScrollPhase phase = Qt::NoScrollPhase, Qt::MouseEventSource src = Qt::MouseEventNotSynthesized,
bool inverted = false, const QPointingDevice *device = QPointingDevice::primaryPointingDevice())
- : InputEvent(w, time, Wheel, mods, device), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D),
+ : PointerEvent(w, time, Wheel, mods, device), pixelDelta(pixelD), angleDelta(angleD), qt4Delta(qt4D),
qt4Orientation(qt4O), localPos(local), globalPos(global), phase(phase), source(src), inverted(inverted) { }
QPoint pixelDelta;
QPoint angleDelta;
@@ -291,6 +298,7 @@ public:
: InputEvent(w, time, Key, mods, device), key(k), unicode(text), repeat(autorep),
repeatCount(count), keyType(t),
nativeScanCode(nativeSC), nativeVirtualKey(nativeVK), nativeModifiers(nativeMods) { }
+ const QInputDevice *source;
int key;
QString unicode;
bool repeat;
@@ -301,13 +309,12 @@ public:
quint32 nativeModifiers;
};
- class TouchEvent : public InputEvent {
+ class TouchEvent : public PointerEvent {
public:
TouchEvent(QWindow *w, ulong time, QEvent::Type t, const QPointingDevice *device,
- const QList<QTouchEvent::TouchPoint> &p, Qt::KeyboardModifiers mods)
- : InputEvent(w, time, Touch, mods, device), points(p), touchType(t) {
- }
- QList<QTouchEvent::TouchPoint> points;
+ const QList<QEventPoint> &p, Qt::KeyboardModifiers mods)
+ : PointerEvent(w, time, Touch, mods, device), points(p), touchType(t) { }
+ QList<QEventPoint> points;
QEvent::Type touchType;
};
@@ -371,8 +378,9 @@ public:
QUrl url;
};
- class Q_GUI_EXPORT TabletEvent : public InputEvent {
+ class Q_GUI_EXPORT TabletEvent : public PointerEvent {
public:
+ // TODO take QPointingDevice* instead of types and IDs
static void handleTabletEvent(QWindow *w, const QPointF &local, const QPointF &global,
int device, int pointerType, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt,
qreal tangentialPressure, qreal rotation, int z, qint64 uid,
@@ -382,7 +390,7 @@ public:
TabletEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global,
const QPointingDevice *device, Qt::MouseButtons b, qreal pressure, int xTilt, int yTilt, qreal tpressure,
qreal rotation, int z, Qt::KeyboardModifiers mods)
- : InputEvent(w, time, Tablet, mods, device),
+ : PointerEvent(w, time, Tablet, mods, device),
buttons(b), local(local), global(global),
pressure(pressure), xTilt(xTilt), yTilt(yTilt), tangentialPressure(tpressure),
rotation(rotation), z(z) { }
@@ -398,16 +406,18 @@ public:
static bool platformSynthesizesMouse;
};
- class TabletEnterProximityEvent : public InputEvent {
+ class TabletEnterProximityEvent : public PointerEvent {
public:
+ // TODO store more info: position and whatever else we can get on most platforms
TabletEnterProximityEvent(ulong time, const QPointingDevice *device)
- : InputEvent(nullptr, time, TabletEnterProximity, Qt::NoModifier, device) { }
+ : PointerEvent(nullptr, time, TabletEnterProximity, Qt::NoModifier, device) { }
};
- class TabletLeaveProximityEvent : public InputEvent {
+ class TabletLeaveProximityEvent : public PointerEvent {
public:
+ // TODO store more info: position and whatever else we can get on most platforms
TabletLeaveProximityEvent(ulong time, const QPointingDevice *device)
- : InputEvent(nullptr, time, TabletLeaveProximity, Qt::NoModifier, device) { }
+ : PointerEvent(nullptr, time, TabletLeaveProximity, Qt::NoModifier, device) { }
};
class PlatformPanelEvent : public WindowSystemEvent {
@@ -433,11 +443,11 @@ public:
#endif
#ifndef QT_NO_GESTURES
- class GestureEvent : public InputEvent {
+ class GestureEvent : public PointerEvent {
public:
GestureEvent(QWindow *window, ulong time, Qt::NativeGestureType type, const QPointingDevice *dev, QPointF pos, QPointF globalPos)
- : InputEvent(window, time, Gesture, Qt::NoModifier, dev), type(type), pos(pos), globalPos(globalPos),
- realValue(0), sequenceId(0), intValue(0), device(dev) { }
+ : PointerEvent(window, time, Gesture, Qt::NoModifier, dev), type(type), pos(pos), globalPos(globalPos),
+ realValue(0), sequenceId(0), intValue(0) { }
Qt::NativeGestureType type;
QPointF pos;
QPointF globalPos;
@@ -446,7 +456,6 @@ public:
// Windows
ulong sequenceId;
quint64 intValue;
- const QPointingDevice *device;
};
#endif
@@ -526,12 +535,22 @@ public:
static QMutex flushEventMutex;
static QAtomicInt eventAccepted;
- static QList<QTouchEvent::TouchPoint>
+ static QList<QEventPoint>
fromNativeTouchPoints(const QList<QWindowSystemInterface::TouchPoint> &points,
const QWindow *window, QEvent::Type *type = nullptr);
+ template<class EventPointList>
static QList<QWindowSystemInterface::TouchPoint>
- toNativeTouchPoints(const QList<QTouchEvent::TouchPoint>& pointList,
- const QWindow *window);
+ toNativeTouchPoints(const EventPointList &pointList, const QWindow *window)
+ {
+ QList<QWindowSystemInterface::TouchPoint> newList;
+ newList.reserve(pointList.size());
+ for (const auto &point : pointList) {
+ newList.append(toNativeTouchPoint(point, window));
+ }
+ return newList;
+ }
+ static QWindowSystemInterface::TouchPoint
+ toNativeTouchPoint(const QEventPoint &point, const QWindow *window);
static void installWindowSystemEventHandler(QWindowSystemEventHandler *handler);
static void removeWindowSystemEventhandler(QWindowSystemEventHandler *handler);