summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qnamespace.h2
-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
-rw-r--r--src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp54
-rw-r--r--src/platformsupport/input/libinput/qlibinputtouch.cpp20
-rw-r--r--src/plugins/generic/tuiotouch/qtuiocursor_p.h16
-rw-r--r--src/plugins/generic/tuiotouch/qtuiohandler.cpp13
-rw-r--r--src/plugins/generic/tuiotouch/qtuiotoken_p.h20
-rw-r--r--src/plugins/platforms/android/androidjniinput.cpp12
-rw-r--r--src/plugins/platforms/cocoa/qmultitouch_mac.mm16
-rw-r--r--src/plugins/platforms/cocoa/qmultitouch_mac_p.h2
-rw-r--r--src/plugins/platforms/ios/quiview.mm12
-rw-r--r--src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp12
-rw-r--r--src/plugins/platforms/wasm/qwasmeventtranslator.cpp12
-rw-r--r--src/plugins/platforms/windows/qwindowsmousehandler.cpp12
-rw-r--r--src/plugins/platforms/windows/qwindowspointerhandler.cpp10
-rw-r--r--src/plugins/platforms/xcb/qxcbconnection_xi2.cpp16
-rw-r--r--src/testlib/qtestmouse.h8
-rw-r--r--src/testlib/qtesttouch.h87
-rw-r--r--src/widgets/graphicsview/qgraphicsproxywidget.cpp4
-rw-r--r--src/widgets/graphicsview/qgraphicsscene.cpp30
-rw-r--r--src/widgets/graphicsview/qgraphicsscene_p.h2
-rw-r--r--src/widgets/graphicsview/qgraphicssceneevent.cpp1
-rw-r--r--src/widgets/graphicsview/qgraphicssceneevent.h4
-rw-r--r--src/widgets/graphicsview/qgraphicsview.cpp15
-rw-r--r--src/widgets/kernel/qapplication.cpp79
-rw-r--r--src/widgets/kernel/qapplication_p.h6
-rw-r--r--src/widgets/kernel/qstandardgestures.cpp22
-rw-r--r--src/widgets/kernel/qwidgetwindow.cpp11
38 files changed, 1019 insertions, 1384 deletions
diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h
index 3e2020ebd5..65a8e8b3c8 100644
--- a/src/corelib/global/qnamespace.h
+++ b/src/corelib/global/qnamespace.h
@@ -1618,6 +1618,7 @@ namespace Qt {
};
enum TouchPointState {
+ TouchPointUnknownState = 0x00,
TouchPointPressed = 0x01,
TouchPointMoved = 0x02,
TouchPointStationary = 0x04,
@@ -1707,6 +1708,7 @@ namespace Qt {
};
enum MouseEventFlag {
+ NoMouseEventFlag = 0x00,
MouseEventCreatedDoubleClick = 0x01,
MouseEventFlagMask = 0xFF
};
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);
diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp
index 5a964c0a17..313d201515 100644
--- a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp
+++ b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp
@@ -126,8 +126,7 @@ public:
int y = 0;
int maj = -1;
int pressure = 0;
- Qt::TouchPointState state = Qt::TouchPointPressed;
- QTouchEvent::TouchPoint::InfoFlags flags;
+ QEventPoint::State state = QEventPoint::State::Pressed;
};
QHash<int, Contact> m_contacts; // The key is a tracking id for type A, slot number for type B.
QHash<int, Contact> m_lastContacts;
@@ -138,7 +137,7 @@ public:
double m_lastTimeStamp;
int findClosestContact(const QHash<int, Contact> &contacts, int x, int y, int *dist);
- void addTouchPoint(const Contact &contact, Qt::TouchPointStates *combinedStates);
+ void addTouchPoint(const Contact &contact, QEventPoint::States *combinedStates);
void reportPoints();
void loadMultiScreenMappings();
@@ -474,11 +473,10 @@ void QEvdevTouchScreenHandler::unregisterPointingDevice()
m_device = nullptr;
}
-void QEvdevTouchScreenData::addTouchPoint(const Contact &contact, Qt::TouchPointStates *combinedStates)
+void QEvdevTouchScreenData::addTouchPoint(const Contact &contact, QEventPoint::States *combinedStates)
{
QWindowSystemInterface::TouchPoint tp;
tp.id = contact.trackingId;
- tp.flags = contact.flags;
tp.state = contact.state;
*combinedStates |= tp.state;
@@ -509,8 +507,8 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data)
m_contacts[m_currentSlot].x = m_currentData.x;
if (m_typeB) {
m_contacts[m_currentSlot].x = m_currentData.x;
- if (m_contacts[m_currentSlot].state == Qt::TouchPointStationary)
- m_contacts[m_currentSlot].state = Qt::TouchPointMoved;
+ if (m_contacts[m_currentSlot].state == QEventPoint::State::Stationary)
+ m_contacts[m_currentSlot].state = QEventPoint::State::Updated;
}
} else if (data->code == ABS_MT_POSITION_Y || (m_singleTouch && data->code == ABS_Y)) {
m_currentData.y = qBound(hw_range_y_min, data->value, hw_range_y_max);
@@ -518,23 +516,23 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data)
m_contacts[m_currentSlot].y = m_currentData.y;
if (m_typeB) {
m_contacts[m_currentSlot].y = m_currentData.y;
- if (m_contacts[m_currentSlot].state == Qt::TouchPointStationary)
- m_contacts[m_currentSlot].state = Qt::TouchPointMoved;
+ if (m_contacts[m_currentSlot].state == QEventPoint::State::Stationary)
+ m_contacts[m_currentSlot].state = QEventPoint::State::Updated;
}
} else if (data->code == ABS_MT_TRACKING_ID) {
m_currentData.trackingId = data->value;
if (m_typeB) {
if (m_currentData.trackingId == -1) {
- m_contacts[m_currentSlot].state = Qt::TouchPointReleased;
+ m_contacts[m_currentSlot].state = QEventPoint::State::Released;
} else {
- m_contacts[m_currentSlot].state = Qt::TouchPointPressed;
+ m_contacts[m_currentSlot].state = QEventPoint::State::Pressed;
m_contacts[m_currentSlot].trackingId = m_currentData.trackingId;
}
}
} else if (data->code == ABS_MT_TOUCH_MAJOR) {
m_currentData.maj = data->value;
if (data->value == 0)
- m_currentData.state = Qt::TouchPointReleased;
+ m_currentData.state = QEventPoint::State::Released;
if (m_typeB)
m_contacts[m_currentSlot].maj = m_currentData.maj;
} else if (data->code == ABS_PRESSURE || data->code == ABS_MT_PRESSURE) {
@@ -550,7 +548,7 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data)
} else if (data->type == EV_KEY && !m_typeB) {
if (data->code == BTN_TOUCH && data->value == 0)
- m_contacts[m_currentSlot].state = Qt::TouchPointReleased;
+ m_contacts[m_currentSlot].state = QEventPoint::State::Released;
} else if (data->type == EV_SYN && data->code == SYN_MT_REPORT && m_lastEventType != EV_SYN) {
// If there is no tracking id, one will be generated later.
@@ -578,7 +576,7 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data)
m_lastTouchPoints = m_touchPoints;
m_touchPoints.clear();
- Qt::TouchPointStates combinedStates;
+ QEventPoint::States combinedStates;
bool hasPressure = false;
for (auto it = m_contacts.begin(), end = m_contacts.end(); it != end; /*erasing*/) {
@@ -590,19 +588,19 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data)
int key = m_typeB ? it.key() : contact.trackingId;
if (!m_typeB && m_lastContacts.contains(key)) {
const Contact &prev(m_lastContacts.value(key));
- if (contact.state == Qt::TouchPointReleased) {
+ if (contact.state == QEventPoint::State::Released) {
// Copy over the previous values for released points, just in case.
contact.x = prev.x;
contact.y = prev.y;
contact.maj = prev.maj;
} else {
contact.state = (prev.x == contact.x && prev.y == contact.y)
- ? Qt::TouchPointStationary : Qt::TouchPointMoved;
+ ? QEventPoint::State::Stationary : QEventPoint::State::Updated;
}
}
// Avoid reporting a contact in released state more than once.
- if (!m_typeB && contact.state == Qt::TouchPointReleased
+ if (!m_typeB && contact.state == QEventPoint::State::Released
&& !m_lastContacts.contains(key)) {
it = m_contacts.erase(it);
continue;
@@ -621,12 +619,12 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data)
int key = m_typeB ? it.key() : contact.trackingId;
if (m_typeB) {
if (contact.trackingId != m_contacts[key].trackingId && contact.state) {
- contact.state = Qt::TouchPointReleased;
+ contact.state = QEventPoint::State::Released;
addTouchPoint(contact, &combinedStates);
}
} else {
if (!m_contacts.contains(key)) {
- contact.state = Qt::TouchPointReleased;
+ contact.state = QEventPoint::State::Released;
addTouchPoint(contact, &combinedStates);
}
}
@@ -639,15 +637,15 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data)
if (!contact.state)
continue;
- if (contact.state == Qt::TouchPointReleased) {
+ if (contact.state == QEventPoint::State::Released) {
if (m_typeB) {
- contact.state = static_cast<Qt::TouchPointState>(0);
+ contact.state = QEventPoint::State::Stationary;
} else {
it = m_contacts.erase(it);
continue;
}
} else {
- contact.state = Qt::TouchPointStationary;
+ contact.state = QEventPoint::State::Stationary;
}
++it;
}
@@ -657,7 +655,7 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data)
m_contacts.clear();
- if (!m_touchPoints.isEmpty() && (hasPressure || combinedStates != Qt::TouchPointStationary))
+ if (!m_touchPoints.isEmpty() && (hasPressure || combinedStates != QEventPoint::State::Stationary))
reportPoints();
}
@@ -780,7 +778,7 @@ void QEvdevTouchScreenData::reportPoints()
// Calculate normalized pressure.
if (!hw_pressure_min && !hw_pressure_max)
- tp.pressure = tp.state == Qt::TouchPointReleased ? 0 : 1;
+ tp.pressure = tp.state == QEventPoint::State::Released ? 0 : 1;
else
tp.pressure = (tp.pressure - hw_pressure_min) / qreal(hw_pressure_max - hw_pressure_min);
@@ -927,8 +925,8 @@ void QEvdevTouchScreenHandlerThread::filterAndSendTouchPoints()
f.y.initialize(pos.y(), velocity.y());
// Make sure the first instance of a touch point we send has the
// 'pressed' state.
- if (tp.state != Qt::TouchPointPressed)
- tp.state = Qt::TouchPointPressed;
+ if (tp.state != QEventPoint::State::Pressed)
+ tp.state = QEventPoint::State::Pressed;
}
tp.velocity = QVector2D(f.x.velocity() * winRect.width(), f.y.velocity() * winRect.height());
@@ -950,14 +948,14 @@ void QEvdevTouchScreenHandlerThread::filterAndSendTouchPoints()
f.touchPoint = tp;
// Don't store the point for future reference if it is a release.
- if (tp.state != Qt::TouchPointReleased)
+ if (tp.state != QEventPoint::State::Released)
filteredPoints[tp.id] = f;
}
for (QHash<int, FilteredTouchPoint>::const_iterator it = m_filteredPoints.constBegin(), end = m_filteredPoints.constEnd(); it != end; ++it) {
const FilteredTouchPoint &f = it.value();
QWindowSystemInterface::TouchPoint tp = f.touchPoint;
- tp.state = Qt::TouchPointReleased;
+ tp.state = QEventPoint::State::Released;
tp.velocity = QVector2D();
points.append(tp);
}
diff --git a/src/platformsupport/input/libinput/qlibinputtouch.cpp b/src/platformsupport/input/libinput/qlibinputtouch.cpp
index c1df7e4c7a..32d1df5b89 100644
--- a/src/platformsupport/input/libinput/qlibinputtouch.cpp
+++ b/src/platformsupport/input/libinput/qlibinputtouch.cpp
@@ -133,7 +133,7 @@ void QLibInputTouch::processTouchDown(libinput_event_touch *e)
} else {
QWindowSystemInterface::TouchPoint newTp;
newTp.id = qMax(0, slot);
- newTp.state = Qt::TouchPointPressed;
+ newTp.state = QEventPoint::State::Pressed;
newTp.area = QRect(0, 0, 8, 8);
newTp.area.moveCenter(getPos(e));
state->m_points.append(newTp);
@@ -146,15 +146,15 @@ void QLibInputTouch::processTouchMotion(libinput_event_touch *e)
DeviceState *state = deviceState(e);
QWindowSystemInterface::TouchPoint *tp = state->point(slot);
if (tp) {
- Qt::TouchPointState tmpState = Qt::TouchPointMoved;
+ QEventPoint::State tmpState = QEventPoint::State::Updated;
const QPointF p = getPos(e);
if (tp->area.center() == p)
- tmpState = Qt::TouchPointStationary;
+ tmpState = QEventPoint::State::Stationary;
else
tp->area.moveCenter(p);
// 'down' may be followed by 'motion' within the same "frame".
// Handle this by compressing and keeping the Pressed state until the 'frame'.
- if (tp->state != Qt::TouchPointPressed && tp->state != Qt::TouchPointReleased)
+ if (tp->state != QEventPoint::State::Pressed && tp->state != QEventPoint::State::Released)
tp->state = tmpState;
} else {
qWarning("Inconsistent touch state (got 'motion' without 'down')");
@@ -167,12 +167,12 @@ void QLibInputTouch::processTouchUp(libinput_event_touch *e)
DeviceState *state = deviceState(e);
QWindowSystemInterface::TouchPoint *tp = state->point(slot);
if (tp) {
- tp->state = Qt::TouchPointReleased;
+ tp->state = QEventPoint::State::Released;
// There may not be a Frame event after the last Up. Work this around.
- Qt::TouchPointStates s;
+ QEventPoint::States s;
for (int i = 0; i < state->m_points.count(); ++i)
s |= state->m_points.at(i).state;
- if (s == Qt::TouchPointReleased)
+ if (s == QEventPoint::State::Released)
processTouchFrame(e);
} else {
qWarning("Inconsistent touch state (got 'up' without 'down')");
@@ -203,10 +203,10 @@ void QLibInputTouch::processTouchFrame(libinput_event_touch *e)
for (int i = 0; i < state->m_points.count(); ++i) {
QWindowSystemInterface::TouchPoint &tp(state->m_points[i]);
- if (tp.state == Qt::TouchPointReleased)
+ if (tp.state == QEventPoint::State::Released)
state->m_points.removeAt(i--);
- else if (tp.state == Qt::TouchPointPressed)
- tp.state = Qt::TouchPointStationary;
+ else if (tp.state == QEventPoint::State::Pressed)
+ tp.state = QEventPoint::State::Stationary;
}
}
diff --git a/src/plugins/generic/tuiotouch/qtuiocursor_p.h b/src/plugins/generic/tuiotouch/qtuiocursor_p.h
index 46134e6f3f..b8301bcf2c 100644
--- a/src/plugins/generic/tuiotouch/qtuiocursor_p.h
+++ b/src/plugins/generic/tuiotouch/qtuiocursor_p.h
@@ -55,7 +55,7 @@ public:
, m_vx(0)
, m_vy(0)
, m_acceleration(0)
- , m_state(Qt::TouchPointPressed)
+ , m_state(QEventPoint::State::Pressed)
{
}
@@ -63,9 +63,9 @@ public:
void setX(float x)
{
- if (state() == Qt::TouchPointStationary &&
+ if (state() == QEventPoint::State::Stationary &&
!qFuzzyCompare(m_x + 2.0, x + 2.0)) { // +2 because 1 is a valid value, and qFuzzyCompare can't cope with 0.0
- setState(Qt::TouchPointMoved);
+ setState(QEventPoint::State::Updated);
}
m_x = x;
}
@@ -73,9 +73,9 @@ public:
void setY(float y)
{
- if (state() == Qt::TouchPointStationary &&
+ if (state() == QEventPoint::State::Stationary &&
!qFuzzyCompare(m_y + 2.0, y + 2.0)) { // +2 because 1 is a valid value, and qFuzzyCompare can't cope with 0.0
- setState(Qt::TouchPointMoved);
+ setState(QEventPoint::State::Updated);
}
m_y = y;
}
@@ -90,8 +90,8 @@ public:
void setAcceleration(float acceleration) { m_acceleration = acceleration; }
float acceleration() const { return m_acceleration; }
- void setState(const Qt::TouchPointState &state) { m_state = state; }
- Qt::TouchPointState state() const { return m_state; }
+ void setState(const QEventPoint::State &state) { m_state = state; }
+ QEventPoint::State state() const { return m_state; }
private:
int m_id;
@@ -100,7 +100,7 @@ private:
float m_vx;
float m_vy;
float m_acceleration;
- Qt::TouchPointState m_state;
+ QEventPoint::State m_state;
};
Q_DECLARE_TYPEINFO(QTuioCursor, Q_MOVABLE_TYPE); // Q_PRIMITIVE_TYPE: not possible, m_state is = 1, not 0.
diff --git a/src/plugins/generic/tuiotouch/qtuiohandler.cpp b/src/plugins/generic/tuiotouch/qtuiohandler.cpp
index 260dc883af..f61bd906bf 100644
--- a/src/plugins/generic/tuiotouch/qtuiohandler.cpp
+++ b/src/plugins/generic/tuiotouch/qtuiohandler.cpp
@@ -260,12 +260,12 @@ void QTuioHandler::process2DCurAlive(const QOscMessage &message)
if (!oldActiveCursors.contains(cursorId)) {
// newly active
QTuioCursor cursor(cursorId);
- cursor.setState(Qt::TouchPointPressed);
+ cursor.setState(QEventPoint::State::Pressed);
newActiveCursors.insert(cursorId, cursor);
} else {
// we already know about it, remove it so it isn't marked as released
QTuioCursor cursor = oldActiveCursors.value(cursorId);
- cursor.setState(Qt::TouchPointStationary); // position change in SET will update if needed
+ cursor.setState(QEventPoint::State::Stationary); // position change in SET will update if needed
newActiveCursors.insert(cursorId, cursor);
oldActiveCursors.remove(cursorId);
}
@@ -378,7 +378,7 @@ void QTuioHandler::process2DCurFseq(const QOscMessage &message)
for (const QTuioCursor &tc : qAsConst(m_deadCursors)) {
QWindowSystemInterface::TouchPoint tp = cursorToTouchPoint(tc, win);
- tp.state = Qt::TouchPointReleased;
+ tp.state = QEventPoint::State::Released;
tpl.append(tp);
}
QWindowSystemInterface::handleTouchEvent(win, m_device, tpl);
@@ -425,12 +425,12 @@ void QTuioHandler::process2DObjAlive(const QOscMessage &message)
if (!oldActiveTokens.contains(sessionId)) {
// newly active
QTuioToken token(sessionId);
- token.setState(Qt::TouchPointPressed);
+ token.setState(QEventPoint::State::Pressed);
newActiveTokens.insert(sessionId, token);
} else {
// we already know about it, remove it so it isn't marked as released
QTuioToken token = oldActiveTokens.value(sessionId);
- token.setState(Qt::TouchPointStationary); // position change in SET will update if needed
+ token.setState(QEventPoint::State::Stationary); // position change in SET will update if needed
newActiveTokens.insert(sessionId, token);
oldActiveTokens.remove(sessionId);
}
@@ -511,7 +511,6 @@ QWindowSystemInterface::TouchPoint QTuioHandler::tokenToTouchPoint(const QTuioTo
QWindowSystemInterface::TouchPoint tp;
tp.id = tc.id();
tp.uniqueId = tc.classId(); // TODO TUIO 2.0: populate a QVariant, and register the mapping from int to arbitrary UID data
- tp.flags = QTouchEvent::TouchPoint::Token;
tp.pressure = 1.0f;
tp.normalPosition = QPointF(tc.x(), tc.y());
@@ -552,7 +551,7 @@ void QTuioHandler::process2DObjFseq(const QOscMessage &message)
for (const QTuioToken & t : qAsConst(m_deadTokens)) {
QWindowSystemInterface::TouchPoint tp = tokenToTouchPoint(t, win);
- tp.state = Qt::TouchPointReleased;
+ tp.state = QEventPoint::State::Released;
tp.velocity = QVector2D();
tpl.append(tp);
}
diff --git a/src/plugins/generic/tuiotouch/qtuiotoken_p.h b/src/plugins/generic/tuiotouch/qtuiotoken_p.h
index b784190d53..0c72436c4c 100644
--- a/src/plugins/generic/tuiotouch/qtuiotoken_p.h
+++ b/src/plugins/generic/tuiotouch/qtuiotoken_p.h
@@ -66,7 +66,7 @@ public:
, m_angle(0)
, m_angularVelocity(0)
, m_angularAcceleration(0)
- , m_state(Qt::TouchPointPressed)
+ , m_state(QEventPoint::State::Pressed)
{
}
@@ -77,9 +77,9 @@ public:
void setX(float x)
{
- if (state() == Qt::TouchPointStationary &&
+ if (state() == QEventPoint::State::Stationary &&
!qFuzzyCompare(m_x + 2.0, x + 2.0)) { // +2 because 1 is a valid value, and qFuzzyCompare can't cope with 0.0
- setState(Qt::TouchPointMoved);
+ setState(QEventPoint::State::Updated);
}
m_x = x;
}
@@ -87,9 +87,9 @@ public:
void setY(float y)
{
- if (state() == Qt::TouchPointStationary &&
+ if (state() == QEventPoint::State::Stationary &&
!qFuzzyCompare(m_y + 2.0, y + 2.0)) { // +2 because 1 is a valid value, and qFuzzyCompare can't cope with 0.0
- setState(Qt::TouchPointMoved);
+ setState(QEventPoint::State::Updated);
}
m_y = y;
}
@@ -109,9 +109,9 @@ public:
{
if (angle > M_PI)
angle = angle - M_PI * 2.0; // zero is pointing upwards, and is the default; but we want to have negative angles when rotating left
- if (state() == Qt::TouchPointStationary &&
+ if (state() == QEventPoint::State::Stationary &&
!qFuzzyCompare(m_angle + 2.0, angle + 2.0)) { // +2 because 1 is a valid value, and qFuzzyCompare can't cope with 0.0
- setState(Qt::TouchPointMoved);
+ setState(QEventPoint::State::Updated);
}
m_angle = angle;
}
@@ -122,8 +122,8 @@ public:
float angularAcceleration() const { return m_angularAcceleration; }
void setAngularAcceleration(float angularAcceleration) { m_angularAcceleration = angularAcceleration; }
- void setState(const Qt::TouchPointState &state) { m_state = state; }
- Qt::TouchPointState state() const { return m_state; }
+ void setState(const QEventPoint::State &state) { m_state = state; }
+ QEventPoint::State state() const { return m_state; }
private:
int m_id; // sessionID, temporary object ID
@@ -136,7 +136,7 @@ private:
float m_angle;
float m_angularVelocity;
float m_angularAcceleration;
- Qt::TouchPointState m_state;
+ QEventPoint::State m_state;
};
Q_DECLARE_TYPEINFO(QTuioToken, Q_MOVABLE_TYPE); // Q_PRIMITIVE_TYPE: not possible: m_id, m_classId == -1
diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp
index 9906bdffd3..98f56808b7 100644
--- a/src/plugins/platforms/android/androidjniinput.cpp
+++ b/src/plugins/platforms/android/androidjniinput.cpp
@@ -228,19 +228,19 @@ namespace QtAndroidInput
static void touchAdd(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint id, jint action, jboolean /*primary*/, jint x, jint y,
jfloat major, jfloat minor, jfloat rotation, jfloat pressure)
{
- Qt::TouchPointState state = Qt::TouchPointStationary;
+ QEventPoint::State state = QEventPoint::State::Stationary;
switch (action) {
case 0:
- state = Qt::TouchPointPressed;
+ state = QEventPoint::State::Pressed;
break;
case 1:
- state = Qt::TouchPointMoved;
+ state = QEventPoint::State::Updated;
break;
case 2:
- state = Qt::TouchPointStationary;
+ state = QEventPoint::State::Stationary;
break;
case 3:
- state = Qt::TouchPointReleased;
+ state = QEventPoint::State::Released;
break;
}
@@ -258,7 +258,7 @@ namespace QtAndroidInput
double(major * 2));
m_touchPoints.push_back(touchPoint);
- if (state == Qt::TouchPointPressed) {
+ if (state == QEventPoint::State::Pressed) {
QAndroidInputContext *inputContext = QAndroidInputContext::androidInputContext();
if (inputContext && qGuiApp)
QMetaObject::invokeMethod(inputContext, "touchDown", Q_ARG(int, x), Q_ARG(int, y));
diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac.mm b/src/plugins/platforms/cocoa/qmultitouch_mac.mm
index 7bbbb486e5..28d641b598 100644
--- a/src/plugins/platforms/cocoa/qmultitouch_mac.mm
+++ b/src/plugins/platforms/cocoa/qmultitouch_mac.mm
@@ -112,22 +112,22 @@ QCocoaTouch *QCocoaTouch::findQCocoaTouch(NSTouch *nstouch)
return nullptr;
}
-Qt::TouchPointState QCocoaTouch::toTouchPointState(NSTouchPhase nsState)
+QEventPoint::State QCocoaTouch::toTouchPointState(NSTouchPhase nsState)
{
- Qt::TouchPointState qtState = Qt::TouchPointReleased;
+ QEventPoint::State qtState = QEventPoint::State::Released;
switch (nsState) {
case NSTouchPhaseBegan:
- qtState = Qt::TouchPointPressed;
+ qtState = QEventPoint::State::Pressed;
break;
case NSTouchPhaseMoved:
- qtState = Qt::TouchPointMoved;
+ qtState = QEventPoint::State::Updated;
break;
case NSTouchPhaseStationary:
- qtState = Qt::TouchPointStationary;
+ qtState = QEventPoint::State::Stationary;
break;
case NSTouchPhaseEnded:
case NSTouchPhaseCancelled:
- qtState = Qt::TouchPointReleased;
+ qtState = QEventPoint::State::Released;
break;
default:
break;
@@ -191,7 +191,7 @@ QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch)
const auto currentTouchesSnapshot = _currentTouches;
for (QCocoaTouch *qcocoaTouch : currentTouchesSnapshot) {
if (!_updateInternalStateOnly) {
- qcocoaTouch->_touchPoint.state = Qt::TouchPointReleased;
+ qcocoaTouch->_touchPoint.state = QEventPoint::State::Released;
touchPoints.insert(qcocoaTouch->_touchPoint.id, qcocoaTouch->_touchPoint);
}
delete qcocoaTouch;
@@ -207,7 +207,7 @@ QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch)
if (_updateInternalStateOnly && !wasUpdateInternalStateOnly && !_currentTouches.isEmpty()) {
QCocoaTouch *qcocoaTouch = _currentTouches.cbegin().value();
- qcocoaTouch->_touchPoint.state = Qt::TouchPointReleased;
+ qcocoaTouch->_touchPoint.state = QEventPoint::State::Released;
touchPoints.insert(qcocoaTouch->_touchPoint.id, qcocoaTouch->_touchPoint);
// Since this last touch also will end up being the first
// touch (if the user adds a second finger without lifting
diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac_p.h b/src/plugins/platforms/cocoa/qmultitouch_mac_p.h
index 875a7d365e..ff4479fa4c 100644
--- a/src/plugins/platforms/cocoa/qmultitouch_mac_p.h
+++ b/src/plugins/platforms/cocoa/qmultitouch_mac_p.h
@@ -88,7 +88,7 @@ class QCocoaTouch
void updateTouchData(NSTouch *nstouch, NSTouchPhase phase);
static QCocoaTouch *findQCocoaTouch(NSTouch *nstouch);
- static Qt::TouchPointState toTouchPointState(NSTouchPhase nsState);
+ static QEventPoint::State toTouchPointState(NSTouchPhase nsState);
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/ios/quiview.mm b/src/plugins/platforms/ios/quiview.mm
index d1a0cbf858..f5dd20bace 100644
--- a/src/plugins/platforms/ios/quiview.mm
+++ b/src/plugins/platforms/ios/quiview.mm
@@ -367,7 +367,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
return [super pointInside:point withEvent:event];
}
-- (void)handleTouches:(NSSet *)touches withEvent:(UIEvent *)event withState:(Qt::TouchPointState)state withTimestamp:(ulong)timeStamp
+- (void)handleTouches:(NSSet *)touches withEvent:(UIEvent *)event withState:(QEventPoint::State)state withTimestamp:(ulong)timeStamp
{
QIOSIntegration *iosIntegration = QIOSIntegration::instance();
bool supportsPressure = QIOSIntegration::instance()->touchDevice()->capabilities() & QPointingDevice::Capability::Pressure;
@@ -417,7 +417,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
}
}
if (!uiTouch) {
- touchPoint.state = Qt::TouchPointStationary;
+ touchPoint.state = QEventPoint::State::Stationary;
} else {
touchPoint.state = state;
@@ -444,7 +444,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
} else {
// We don't claim that our touch device supports QPointingDevice::Capability::Pressure,
// but fill in a meaningful value in case clients use it anyway.
- touchPoint.pressure = (state == Qt::TouchPointReleased) ? 0.0 : 1.0;
+ touchPoint.pressure = (state == QEventPoint::State::Released) ? 0.0 : 1.0;
}
}
}
@@ -499,17 +499,17 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
topLevel->requestActivateWindow();
}
- [self handleTouches:touches withEvent:event withState:Qt::TouchPointPressed withTimestamp:ulong(event.timestamp * 1000)];
+ [self handleTouches:touches withEvent:event withState:QEventPoint::State::Pressed withTimestamp:ulong(event.timestamp * 1000)];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
- [self handleTouches:touches withEvent:event withState:Qt::TouchPointMoved withTimestamp:ulong(event.timestamp * 1000)];
+ [self handleTouches:touches withEvent:event withState:QEventPoint::State::Updated withTimestamp:ulong(event.timestamp * 1000)];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
- [self handleTouches:touches withEvent:event withState:Qt::TouchPointReleased withTimestamp:ulong(event.timestamp * 1000)];
+ [self handleTouches:touches withEvent:event withState:QEventPoint::State::Released withTimestamp:ulong(event.timestamp * 1000)];
// Remove ended touch points from the active set:
#ifndef Q_OS_TVOS
diff --git a/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp b/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp
index 40033d05c9..5653c9ee57 100644
--- a/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp
+++ b/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp
@@ -160,7 +160,7 @@ QQnxScreenEventHandler::QQnxScreenEventHandler(QQnxIntegration *integration)
m_touchPoints[i].pressure = 1.0;
// nothing touching
- m_touchPoints[i].state = Qt::TouchPointReleased;
+ m_touchPoints[i].state = QEventPoint::State::Released;
}
}
@@ -544,15 +544,15 @@ void QQnxScreenEventHandler::handleTouchEvent(screen_event_t event, int qnxType)
QEvent::Type type = QEvent::None;
switch (qnxType) {
case SCREEN_EVENT_MTOUCH_TOUCH:
- m_touchPoints[touchId].state = Qt::TouchPointPressed;
+ m_touchPoints[touchId].state = QEventPoint::State::Pressed;
type = QEvent::TouchBegin;
break;
case SCREEN_EVENT_MTOUCH_MOVE:
- m_touchPoints[touchId].state = Qt::TouchPointMoved;
+ m_touchPoints[touchId].state = QEventPoint::State::Updated;
type = QEvent::TouchUpdate;
break;
case SCREEN_EVENT_MTOUCH_RELEASE:
- m_touchPoints[touchId].state = Qt::TouchPointReleased;
+ m_touchPoints[touchId].state = QEventPoint::State::Released;
type = QEvent::TouchEnd;
break;
}
@@ -563,9 +563,9 @@ void QQnxScreenEventHandler::handleTouchEvent(screen_event_t event, int qnxType)
if (i == touchId) {
// current touch point is always active
pointList.append(m_touchPoints[i]);
- } else if (m_touchPoints[i].state != Qt::TouchPointReleased) {
+ } else if (m_touchPoints[i].state != QEventPoint::State::Released) {
// finger is down but did not move
- m_touchPoints[i].state = Qt::TouchPointStationary;
+ m_touchPoints[i].state = QEventPoint::State::Stationary;
pointList.append(m_touchPoints[i]);
}
}
diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
index 41e4b557c0..2387f3cdea 100644
--- a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
+++ b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
@@ -738,22 +738,22 @@ int QWasmEventTranslator::handleTouch(int eventType, const EmscriptenTouchEvent
case EMSCRIPTEN_EVENT_TOUCHSTART:
if (tp != pressedTouchIds.constEnd()) {
touchPoint.state = (stationaryTouchPoint
- ? Qt::TouchPointStationary
- : Qt::TouchPointMoved);
+ ? QEventPoint::State::Stationary
+ : QEventPoint::State::Updated);
} else {
- touchPoint.state = Qt::TouchPointPressed;
+ touchPoint.state = QEventPoint::State::Pressed;
}
pressedTouchIds.insert(touchPoint.id, touchPoint.normalPosition);
break;
case EMSCRIPTEN_EVENT_TOUCHEND:
- touchPoint.state = Qt::TouchPointReleased;
+ touchPoint.state = QEventPoint::State::Released;
pressedTouchIds.remove(touchPoint.id);
break;
case EMSCRIPTEN_EVENT_TOUCHMOVE:
touchPoint.state = (stationaryTouchPoint
- ? Qt::TouchPointStationary
- : Qt::TouchPointMoved);
+ ? QEventPoint::State::Stationary
+ : QEventPoint::State::Updated);
pressedTouchIds.insert(touchPoint.id, touchPoint.normalPosition);
break;
diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp
index 13dd324a09..5e2710bc28 100644
--- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp
+++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp
@@ -601,7 +601,7 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND,
QTouchPointList touchPoints;
touchPoints.reserve(winTouchPointCount);
- Qt::TouchPointStates allStates;
+ QEventPoint::States allStates;
GetTouchInputInfo(reinterpret_cast<HTOUCHINPUT>(msg.lParam),
UINT(msg.wParam), winTouchInputs.data(), sizeof(TOUCHINPUT));
@@ -628,15 +628,15 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND,
touchPoint.normalPosition = normalPosition;
if (winTouchInput.dwFlags & TOUCHEVENTF_DOWN) {
- touchPoint.state = Qt::TouchPointPressed;
+ touchPoint.state = QEventPoint::State::Pressed;
m_lastTouchPositions.insert(id, touchPoint.normalPosition);
} else if (winTouchInput.dwFlags & TOUCHEVENTF_UP) {
- touchPoint.state = Qt::TouchPointReleased;
+ touchPoint.state = QEventPoint::State::Released;
m_lastTouchPositions.remove(id);
} else {
touchPoint.state = (stationaryTouchPoint
- ? Qt::TouchPointStationary
- : Qt::TouchPointMoved);
+ ? QEventPoint::State::Stationary
+ : QEventPoint::State::Updated);
m_lastTouchPositions.insert(id, touchPoint.normalPosition);
}
@@ -648,7 +648,7 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND,
CloseTouchInputHandle(reinterpret_cast<HTOUCHINPUT>(msg.lParam));
// all touch points released, forget the ids we've seen, they may not be reused
- if (allStates == Qt::TouchPointReleased)
+ if (allStates == QEventPoint::State::Released)
m_touchInputIDToTouchPointID.clear();
QWindowSystemInterface::handleTouchEvent(window,
diff --git a/src/plugins/platforms/windows/qwindowspointerhandler.cpp b/src/plugins/platforms/windows/qwindowspointerhandler.cpp
index 7dc2bd729a..d5c3aeacff 100644
--- a/src/plugins/platforms/windows/qwindowspointerhandler.cpp
+++ b/src/plugins/platforms/windows/qwindowspointerhandler.cpp
@@ -491,7 +491,7 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd,
<< " message=" << Qt::hex << msg.message
<< " count=" << Qt::dec << count;
- Qt::TouchPointStates allStates;
+ QEventPoint::States allStates;
for (quint32 i = 0; i < count; ++i) {
if (QWindowsContext::verbose > 1)
@@ -526,13 +526,13 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd,
touchPoint.normalPosition = normalPosition;
if (touchInfo[i].pointerInfo.pointerFlags & POINTER_FLAG_DOWN) {
- touchPoint.state = Qt::TouchPointPressed;
+ touchPoint.state = QEventPoint::State::Pressed;
m_lastTouchPositions.insert(touchPoint.id, touchPoint.normalPosition);
} else if (touchInfo[i].pointerInfo.pointerFlags & POINTER_FLAG_UP) {
- touchPoint.state = Qt::TouchPointReleased;
+ touchPoint.state = QEventPoint::State::Released;
m_lastTouchPositions.remove(touchPoint.id);
} else {
- touchPoint.state = stationaryTouchPoint ? Qt::TouchPointStationary : Qt::TouchPointMoved;
+ touchPoint.state = stationaryTouchPoint ? QEventPoint::State::Stationary : QEventPoint::State::Updated;
m_lastTouchPositions.insert(touchPoint.id, touchPoint.normalPosition);
}
allStates |= touchPoint.state;
@@ -544,7 +544,7 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd,
}
// all touch points released, forget the ids we've seen.
- if (allStates == Qt::TouchPointReleased)
+ if (allStates == QEventPoint::State::Released)
m_touchInputIDToTouchPointID.clear();
QWindowSystemInterface::handleTouchEvent(window, m_touchDevice, touchPoints,
diff --git a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
index 74044db0de..dc8a533388 100644
--- a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
+++ b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
@@ -819,7 +819,7 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo
if (xiDeviceEvent->event_type == XCB_INPUT_TOUCH_BEGIN) {
QWindowSystemInterface::TouchPoint tp;
tp.id = xiDeviceEvent->detail % INT_MAX;
- tp.state = Qt::TouchPointPressed;
+ tp.state = QEventPoint::State::Pressed;
tp.pressure = -1.0;
dev->touchPoints[tp.id] = tp;
}
@@ -926,9 +926,9 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo
dev->size.height() * screen->geometry().height() / screen->physicalSize().height();
x = dev->firstPressedPosition.x() + dx;
y = dev->firstPressedPosition.y() + dy;
- touchPoint.state = Qt::TouchPointMoved;
+ touchPoint.state = QEventPoint::State::Updated;
} else if (touchPoint.area.center() != QPoint(x, y)) {
- touchPoint.state = Qt::TouchPointMoved;
+ touchPoint.state = QEventPoint::State::Updated;
if (dev->qtTouchDevice->type() == QInputDevice::DeviceType::TouchPad)
dev->pointPressedPosition[touchPoint.id] = QPointF(x, y);
}
@@ -948,7 +948,7 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo
}
break;
case XCB_INPUT_TOUCH_END:
- touchPoint.state = Qt::TouchPointReleased;
+ touchPoint.state = QEventPoint::State::Released;
if (dev->qtTouchDevice->type() == QInputDevice::DeviceType::TouchPad && dev->pointPressedPosition.value(touchPoint.id) == QPointF(x, y)) {
qreal dx = (nx - dev->firstPressedNormalPosition.x()) *
dev->size.width() * screen->geometry().width() / screen->physicalSize().width();
@@ -967,13 +967,13 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo
" area " << touchPoint.area << " pressure " << touchPoint.pressure;
Qt::KeyboardModifiers modifiers = keyboard()->translateModifiers(xiDeviceEvent->mods.effective);
QWindowSystemInterface::handleTouchEvent(platformWindow->window(), xiDeviceEvent->time, dev->qtTouchDevice, dev->touchPoints.values(), modifiers);
- if (touchPoint.state == Qt::TouchPointReleased)
+ if (touchPoint.state == QEventPoint::State::Released)
// If a touchpoint was released, we can forget it, because the ID won't be reused.
dev->touchPoints.remove(touchPoint.id);
else
// Make sure that we don't send TouchPointPressed/Moved in more than one QTouchEvent
// with this touch point if the next XI2 event is about a different touch point.
- touchPoint.state = Qt::TouchPointStationary;
+ touchPoint.state = QEventPoint::State::Stationary;
}
bool QXcbConnection::startSystemMoveResizeForTouch(xcb_window_t window, int edges)
@@ -984,8 +984,8 @@ bool QXcbConnection::startSystemMoveResizeForTouch(xcb_window_t window, int edge
if (deviceData.qtTouchDevice->type() == QInputDevice::DeviceType::TouchScreen) {
auto pointIt = deviceData.touchPoints.constBegin();
for (; pointIt != deviceData.touchPoints.constEnd(); ++pointIt) {
- Qt::TouchPointState state = pointIt.value().state;
- if (state == Qt::TouchPointMoved || state == Qt::TouchPointPressed || state == Qt::TouchPointStationary) {
+ QEventPoint::State state = pointIt.value().state;
+ if (state == QEventPoint::State::Updated || state == QEventPoint::State::Pressed || state == QEventPoint::State::Stationary) {
m_startSystemMoveResizeInfo.window = window;
m_startSystemMoveResizeInfo.deviceid = devIt.key();
m_startSystemMoveResizeInfo.pointid = pointIt.key();
diff --git a/src/testlib/qtestmouse.h b/src/testlib/qtestmouse.h
index e3e446577d..4848462be6 100644
--- a/src/testlib/qtestmouse.h
+++ b/src/testlib/qtestmouse.h
@@ -211,20 +211,20 @@ namespace QTest
stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
- QMouseEvent me(QEvent::User, QPoint(), Qt::LeftButton, button, stateKey);
+ QMouseEvent me(QEvent::User, QPointF(), Qt::LeftButton, QTestPrivate::qtestMouseButtons, stateKey, QPointingDevice::primaryPointingDevice());
switch (action)
{
case MousePress:
- me = QMouseEvent(QEvent::MouseButtonPress, pos, widget->mapToGlobal(pos), button, button, stateKey);
+ me = QMouseEvent(QEvent::MouseButtonPress, pos, widget->mapToGlobal(pos), button, button, stateKey, QPointingDevice::primaryPointingDevice());
me.setTimestamp(++lastMouseTimestamp);
break;
case MouseRelease:
- me = QMouseEvent(QEvent::MouseButtonRelease, pos, widget->mapToGlobal(pos), button, Qt::MouseButton(), stateKey);
+ me = QMouseEvent(QEvent::MouseButtonRelease, pos, widget->mapToGlobal(pos), button, Qt::MouseButton(), stateKey, QPointingDevice::primaryPointingDevice());
me.setTimestamp(++lastMouseTimestamp);
lastMouseTimestamp += mouseDoubleClickInterval; // avoid double clicks being generated
break;
case MouseDClick:
- me = QMouseEvent(QEvent::MouseButtonDblClick, pos, widget->mapToGlobal(pos), button, button, stateKey);
+ me = QMouseEvent(QEvent::MouseButtonDblClick, pos, widget->mapToGlobal(pos), button, button, stateKey, QPointingDevice::primaryPointingDevice());
me.setTimestamp(++lastMouseTimestamp);
break;
case MouseMove:
diff --git a/src/testlib/qtesttouch.h b/src/testlib/qtesttouch.h
index 6db7fb52ec..f976a6ef0a 100644
--- a/src/testlib/qtesttouch.h
+++ b/src/testlib/qtesttouch.h
@@ -61,7 +61,7 @@
QT_BEGIN_NAMESPACE
Q_GUI_EXPORT void qt_handleTouchEvent(QWindow *w, const QPointingDevice *device,
- const QList<QTouchEvent::TouchPoint> &points,
+ const QList<QEventPoint> &points,
Qt::KeyboardModifiers mods = Qt::NoModifier);
@@ -81,52 +81,52 @@ namespace QTest
}
QTouchEventSequence& press(int touchId, const QPoint &pt, QWindow *window = nullptr)
{
- QTouchEvent::TouchPoint &p = point(touchId);
- p.setScreenPos(mapToScreen(window, pt));
- p.setState(Qt::TouchPointPressed);
+ QEventPoint &p = point(touchId);
+ p.m_globalPos = mapToScreen(window, pt);
+ p.m_state = QEventPoint::State::Pressed;
return *this;
}
QTouchEventSequence& move(int touchId, const QPoint &pt, QWindow *window = nullptr)
{
- QTouchEvent::TouchPoint &p = point(touchId);
- p.setScreenPos(mapToScreen(window, pt));
- p.setState(Qt::TouchPointMoved);
+ QEventPoint &p = point(touchId);
+ p.m_globalPos = mapToScreen(window, pt);
+ p.m_state = QEventPoint::State::Updated;
return *this;
}
QTouchEventSequence& release(int touchId, const QPoint &pt, QWindow *window = nullptr)
{
- QTouchEvent::TouchPoint &p = point(touchId);
- p.setScreenPos(mapToScreen(window, pt));
- p.setState(Qt::TouchPointReleased);
+ QEventPoint &p = point(touchId);
+ p.m_globalPos = mapToScreen(window, pt);
+ p.m_state = QEventPoint::State::Released;
return *this;
}
QTouchEventSequence& stationary(int touchId)
{
- QTouchEvent::TouchPoint &p = pointOrPreviousPoint(touchId);
- p.setState(Qt::TouchPointStationary);
+ QEventPoint &p = pointOrPreviousPoint(touchId);
+ p.m_state = QEventPoint::State::Stationary;
return *this;
}
#ifdef QT_WIDGETS_LIB
QTouchEventSequence& press(int touchId, const QPoint &pt, QWidget *widget = nullptr)
{
- QTouchEvent::TouchPoint &p = point(touchId);
- p.setScreenPos(mapToScreen(widget, pt));
- p.setState(Qt::TouchPointPressed);
+ QEventPoint &p = point(touchId);
+ p.m_globalPos = mapToScreen(widget, pt);
+ p.m_state = QEventPoint::State::Pressed;
return *this;
}
QTouchEventSequence& move(int touchId, const QPoint &pt, QWidget *widget = nullptr)
{
- QTouchEvent::TouchPoint &p = point(touchId);
- p.setScreenPos(mapToScreen(widget, pt));
- p.setState(Qt::TouchPointMoved);
+ QEventPoint &p = point(touchId);
+ p.m_globalPos = mapToScreen(widget, pt);
+ p.m_state = QEventPoint::State::Updated;
return *this;
}
QTouchEventSequence& release(int touchId, const QPoint &pt, QWidget *widget = nullptr)
{
- QTouchEvent::TouchPoint &p = point(touchId);
- p.setScreenPos(mapToScreen(widget, pt));
- p.setState(Qt::TouchPointReleased);
+ QEventPoint &p = point(touchId);
+ p.m_globalPos = mapToScreen(widget, pt);
+ p.m_state = QEventPoint::State::Released;
return *this;
}
#endif
@@ -168,24 +168,6 @@ private:
{
}
- QTouchEvent::TouchPoint &point(int touchId)
- {
- if (!points.contains(touchId))
- points[touchId] = QTouchEvent::TouchPoint(touchId);
- return points[touchId];
- }
-
- QTouchEvent::TouchPoint &pointOrPreviousPoint(int touchId)
- {
- if (!points.contains(touchId)) {
- if (previousPoints.contains(touchId))
- points[touchId] = previousPoints.value(touchId);
- else
- points[touchId] = QTouchEvent::TouchPoint(touchId);
- }
- return points[touchId];
- }
-
#ifdef QT_WIDGETS_LIB
QPoint mapToScreen(QWidget *widget, const QPoint &pt)
{
@@ -201,8 +183,8 @@ private:
return targetWindow ? targetWindow->mapToGlobal(pt) : pt;
}
- QMap<int, QTouchEvent::TouchPoint> previousPoints;
- QMap<int, QTouchEvent::TouchPoint> points;
+ QMap<int, QEventPoint> previousPoints;
+ QMap<int, QEventPoint> points;
#ifdef QT_WIDGETS_LIB
QWidget *targetWidget;
#endif
@@ -213,6 +195,29 @@ private:
friend QTouchEventSequence touchEvent(QWidget *widget, QPointingDevice *device, bool autoCommit);
#endif
friend QTouchEventSequence touchEvent(QWindow *window, QPointingDevice *device, bool autoCommit);
+
+ protected:
+ // These don't make sense for public testing API,
+ // because we are getting rid of most public setters in QEventPoint.
+ // Each of these constructs a QEventPoint with null parent; in normal usage,
+ // the QTouchEvent constructor will set the points' parents to itself, later on.
+ QEventPoint &point(int touchId)
+ {
+ if (!points.contains(touchId))
+ points[touchId] = QEventPoint(touchId);
+ return points[touchId];
+ }
+
+ QEventPoint &pointOrPreviousPoint(int touchId)
+ {
+ if (!points.contains(touchId)) {
+ if (previousPoints.contains(touchId))
+ points[touchId] = previousPoints.value(touchId);
+ else
+ points[touchId] = QEventPoint(touchId);
+ }
+ return points[touchId];
+ }
};
#if defined(QT_WIDGETS_LIB) || defined(Q_CLANG_QDOC)
diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp
index 42211c7ccf..d2ae77fd83 100644
--- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp
+++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp
@@ -1301,7 +1301,9 @@ void QGraphicsProxyWidget::wheelEvent(QGraphicsSceneWheelEvent *event)
// pixelDelta, inverted, scrollPhase and source from the original QWheelEvent
// were not preserved in the QGraphicsSceneWheelEvent unfortunately
QWheelEvent wheelEvent(pos, event->screenPos(), QPoint(), angleDelta,
- event->buttons(), event->modifiers(), Qt::NoScrollPhase, false);
+ event->buttons(), event->modifiers(), Qt::NoScrollPhase,
+ false, Qt::MouseEventNotSynthesized,
+ QPointingDevice::primaryPointingDevice());
QPointer<QWidget> focusWidget = d->widget->focusWidget();
extern bool qt_sendSpontaneousEvent(QObject *, QEvent *);
qt_sendSpontaneousEvent(receiver, &wheelEvent);
diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp
index 71bfff2ef5..1e47885bc7 100644
--- a/src/widgets/graphicsview/qgraphicsscene.cpp
+++ b/src/widgets/graphicsview/qgraphicsscene.cpp
@@ -243,6 +243,7 @@
#include <QtGui/qtransform.h>
#include <QtGui/qinputmethod.h>
#include <private/qapplication_p.h>
+#include <private/qevent_p.h>
#include <private/qobject_p.h>
#if QT_CONFIG(graphicseffect)
#include <private/qgraphicseffect_p.h>
@@ -5828,18 +5829,15 @@ void QGraphicsScenePrivate::updateTouchPointsForItem(QGraphicsItem *item, QTouch
const QTransform mapFromScene =
item->d_ptr->genericMapFromSceneTransform(static_cast<const QWidget *>(touchEvent->target()));
- for (auto &touchPoint : touchEvent->_touchPoints) {
- touchPoint.setPos(mapFromScene.map(touchPoint.scenePosition()));
- touchPoint.setStartPos(mapFromScene.map(touchPoint.scenePressPosition()));
- touchPoint.setLastPos(mapFromScene.map(touchPoint.lastScenePos()));
- }
+ for (QEventPoint &pt : QMutableTouchEvent::from(touchEvent)->touchPoints())
+ QMutableEventPoint::from(pt).setPosition(mapFromScene.map(pt.scenePosition()));
}
int QGraphicsScenePrivate::findClosestTouchPointId(const QPointF &scenePos)
{
int closestTouchPointId = -1;
qreal closestDistance = qreal(0.);
- for (const QTouchEvent::TouchPoint &touchPoint : qAsConst(sceneCurrentTouchPoints)) {
+ for (const QEventPoint &touchPoint : qAsConst(sceneCurrentTouchPoints)) {
qreal distance = QLineF(scenePos, touchPoint.scenePosition()).length();
if (closestTouchPointId == -1|| distance < closestDistance) {
closestTouchPointId = touchPoint.id();
@@ -5851,14 +5849,14 @@ int QGraphicsScenePrivate::findClosestTouchPointId(const QPointF &scenePos)
void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
{
- typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints;
+ typedef QPair<QEventPoint::States, QList<QEventPoint> > StatesAndTouchPoints;
QHash<QGraphicsItem *, StatesAndTouchPoints> itemsNeedingEvents;
const auto touchPoints = sceneTouchEvent->touchPoints();
for (const auto &touchPoint : touchPoints) {
// update state
QGraphicsItem *item = nullptr;
- if (touchPoint.state() == Qt::TouchPointPressed) {
+ if (touchPoint.state() == QEventPoint::State::Pressed) {
if (sceneTouchEvent->pointingDevice()->type() == QInputDevice::DeviceType::TouchPad) {
// on touch-pad devices, send all touch points to the same item
item = itemForTouchPointId.isEmpty()
@@ -5886,7 +5884,7 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
itemForTouchPointId.insert(touchPoint.id(), item);
sceneCurrentTouchPoints.insert(touchPoint.id(), touchPoint);
- } else if (touchPoint.state() == Qt::TouchPointReleased) {
+ } else if (touchPoint.state() == QEventPoint::State::Released) {
item = itemForTouchPointId.take(touchPoint.id());
if (!item)
continue;
@@ -5901,7 +5899,7 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
}
StatesAndTouchPoints &statesAndTouchPoints = itemsNeedingEvents[item];
- statesAndTouchPoints.first |= touchPoint.state();
+ statesAndTouchPoints.first = QEventPoint::States(statesAndTouchPoints.first | touchPoint.state());
statesAndTouchPoints.second.append(touchPoint);
}
@@ -5921,15 +5919,15 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
// determine event type from the state mask
QEvent::Type eventType;
switch (it.value().first) {
- case Qt::TouchPointPressed:
+ case QEventPoint::State::Pressed:
// all touch points have pressed state
eventType = QEvent::TouchBegin;
break;
- case Qt::TouchPointReleased:
+ case QEventPoint::State::Released:
// all touch points have released state
eventType = QEvent::TouchEnd;
break;
- case Qt::TouchPointStationary:
+ case QEventPoint::State::Stationary:
// don't send the event if nothing changed
continue;
default:
@@ -5938,9 +5936,7 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent)
break;
}
- QTouchEvent touchEvent(eventType, sceneTouchEvent->pointingDevice(), sceneTouchEvent->modifiers(), it.value().first, it.value().second);
- // TODO more constructor args and fewer setters?
- touchEvent.setWindow(sceneTouchEvent->window());
+ QMutableTouchEvent touchEvent(eventType, sceneTouchEvent->pointingDevice(), sceneTouchEvent->modifiers(), it.value().second);
touchEvent.setTarget(sceneTouchEvent->target());
touchEvent.setModifiers(sceneTouchEvent->modifiers());
touchEvent.setTimestamp(sceneTouchEvent->timestamp());
@@ -5981,7 +5977,7 @@ bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEve
if (focusOnTouch) {
if (cachedItemsUnderMouse.isEmpty() || cachedItemsUnderMouse.constFirst() != origin) {
- const QTouchEvent::TouchPoint &firstTouchPoint = touchEvent->touchPoints().first();
+ const QEventPoint &firstTouchPoint = touchEvent->touchPoints().first();
cachedItemsUnderMouse = itemsAtPosition(firstTouchPoint.globalPosition().toPoint(),
firstTouchPoint.scenePosition(),
static_cast<QWidget *>(touchEvent->target()));
diff --git a/src/widgets/graphicsview/qgraphicsscene_p.h b/src/widgets/graphicsview/qgraphicsscene_p.h
index 48681cafae..0cb8cd3c57 100644
--- a/src/widgets/graphicsview/qgraphicsscene_p.h
+++ b/src/widgets/graphicsview/qgraphicsscene_p.h
@@ -309,7 +309,7 @@ public:
QStyleOptionGraphicsItem styleOptionTmp;
- QMap<int, QTouchEvent::TouchPoint> sceneCurrentTouchPoints;
+ QMap<int, QEventPoint> sceneCurrentTouchPoints;
QMap<int, QGraphicsItem *> itemForTouchPointId;
static void updateTouchPointsForItem(QGraphicsItem *item, QTouchEvent *touchEvent);
int findClosestTouchPointId(const QPointF &scenePos);
diff --git a/src/widgets/graphicsview/qgraphicssceneevent.cpp b/src/widgets/graphicsview/qgraphicssceneevent.cpp
index 048ea6dc7d..af2f87211f 100644
--- a/src/widgets/graphicsview/qgraphicssceneevent.cpp
+++ b/src/widgets/graphicsview/qgraphicssceneevent.cpp
@@ -653,6 +653,7 @@ void QGraphicsSceneMouseEvent::setSource(Qt::MouseEventSource source)
/*!
\since 5.4
+ \deprecated in 6.0
Returns the mouse event flags.
diff --git a/src/widgets/graphicsview/qgraphicssceneevent.h b/src/widgets/graphicsview/qgraphicssceneevent.h
index 4a47b642fe..f47b1a4d4f 100644
--- a/src/widgets/graphicsview/qgraphicssceneevent.h
+++ b/src/widgets/graphicsview/qgraphicssceneevent.h
@@ -121,8 +121,12 @@ public:
Qt::MouseEventSource source() const;
void setSource(Qt::MouseEventSource source);
+#if QT_DEPRECATED_SINCE(6, 0)
+ QT_DEPRECATED_VERSION_X_6_0("Internal, don't use")
Qt::MouseEventFlags flags() const;
+ QT_DEPRECATED_VERSION_X_6_0("Internal, don't use")
void setFlags(Qt::MouseEventFlags);
+#endif // QT_DEPRECATED_SINCE(6, 0)
private:
Q_DECLARE_PRIVATE(QGraphicsSceneMouseEvent)
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp
index 4119fd4851..d3059de378 100644
--- a/src/widgets/graphicsview/qgraphicsview.cpp
+++ b/src/widgets/graphicsview/qgraphicsview.cpp
@@ -310,21 +310,12 @@ inline int q_round_bound(qreal d) //### (int)(qreal) INT_MAX != INT_MAX for sing
void QGraphicsViewPrivate::translateTouchEvent(QGraphicsViewPrivate *d, QTouchEvent *touchEvent)
{
- QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
- for (int i = 0; i < touchPoints.count(); ++i) {
- QTouchEvent::TouchPoint &touchPoint = touchPoints[i];
- const QSizeF ellipseDiameters = touchPoint.ellipseDiameters();
+ for (QEventPoint &pt : QMutableTouchEvent::from(touchEvent)->touchPoints()) {
// the scene will set the item local pos, startPos, lastPos, and rect before delivering to
// an item, but for now those functions are returning the view's local coordinates
- touchPoint.setScenePos(d->mapToScene(touchPoint.position()));
- touchPoint.setStartScenePos(d->mapToScene(touchPoint.pressPosition()));
- touchPoint.setLastScenePos(d->mapToScene(touchPoint.lastPos()));
- touchPoint.setEllipseDiameters(ellipseDiameters);
-
+ QMutableEventPoint::from(pt).setScenePosition(d->mapToScene(pt.position()));
// screenPos, startScreenPos, and lastScreenPos are already set
}
-
- touchEvent->setTouchPoints(touchPoints);
}
/*!
@@ -2929,7 +2920,7 @@ bool QGraphicsView::viewportEvent(QEvent *event)
if (d->scene && d->sceneInteractionAllowed) {
// Convert and deliver the touch event to the scene.
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
- touchEvent->setTarget(viewport());
+ QMutableTouchEvent::from(touchEvent)->setTarget(viewport());
QGraphicsViewPrivate::translateTouchEvent(d, touchEvent);
QCoreApplication::sendEvent(d->scene, touchEvent);
} else {
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 27ffd1cc7c..f19801f511 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -91,6 +91,7 @@
#include <qthread.h>
#include <private/qthread_p.h>
+#include <QtGui/private/qevent_p.h>
#include <private/qfont_p.h>
#if QT_CONFIG(action)
#include <private/qaction_p.h>
@@ -99,7 +100,6 @@
#include <stdlib.h>
#include "qapplication_p.h"
-#include "private/qevent_p.h"
#include "qwidget_p.h"
#include "qgesture.h"
@@ -2946,7 +2946,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
mouse->button(), mouse->buttons(), mouse->modifiers(), mouse->source());
me.spont = mouse->spontaneous();
me.setTimestamp(mouse->timestamp());
- QGuiApplicationPrivate::setMouseEventFlags(&me, mouse->flags());
+ QMutableSinglePointEvent::from(me).setDoubleClick(QMutableSinglePointEvent::from(mouse)->isDoubleClick());
// throw away any mouse-tracking-only mouse events
if (!w->hasMouseTracking()
&& mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) {
@@ -3067,7 +3067,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
}
QWheelEvent we(relpos, wheel->globalPosition(), wheel->pixelDelta(), wheel->angleDelta(), wheel->buttons(),
- wheel->modifiers(), phase, wheel->inverted(), wheel->source());
+ wheel->modifiers(), phase, wheel->inverted(), wheel->source(), wheel->pointingDevice());
we.setTimestamp(wheel->timestamp());
bool eventAccepted;
@@ -3080,7 +3080,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
break;
- we.p += w->pos();
+ QMutableSinglePointEvent::from(we).mutablePoint().setPosition(we.position() + w->pos());
w = w->parentWidget();
} while (w);
wheel->setAccepted(eventAccepted);
@@ -3250,7 +3250,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
// Note: TouchUpdate and TouchEnd events are never propagated
{
QWidget *widget = static_cast<QWidget *>(receiver);
- QTouchEvent *touchEvent = static_cast<QTouchEvent *>(e);
+ QMutableTouchEvent *touchEvent = QMutableTouchEvent::from(static_cast<QTouchEvent *>(e));
bool eventAccepted = touchEvent->isAccepted();
bool acceptTouchEvents = widget->testAttribute(Qt::WA_AcceptTouchEvents);
@@ -3293,12 +3293,8 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
QPoint offset = widget->pos();
widget = widget->parentWidget();
touchEvent->setTarget(widget);
- for (int i = 0; i < touchEvent->_touchPoints.size(); ++i) {
- QTouchEvent::TouchPoint &pt = touchEvent->_touchPoints[i];
- pt.d->pos = pt.position() + offset;
- pt.d->startPos = pt.pressPosition() + offset;
- pt.d->lastPos = pt.lastPos() + offset;
- }
+ for (QEventPoint &pt : touchEvent->touchPoints())
+ QMutableEventPoint::from(pt).setPosition(pt.position() + offset);
}
#ifndef QT_NO_GESTURES
@@ -3944,18 +3940,15 @@ bool QApplicationPrivate::shouldSetFocus(QWidget *w, Qt::FocusPolicy policy)
bool QApplicationPrivate::updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent)
{
bool containsPress = false;
- for (int i = 0; i < touchEvent->touchPoints().count(); ++i) {
- QTouchEvent::TouchPoint &touchPoint = touchEvent->_touchPoints[i];
+ for (QEventPoint &pt : QMutableTouchEvent::from(touchEvent)->touchPoints()) {
// preserve the sub-pixel resolution
- const QPointF screenPos = touchPoint.globalPosition();
+ const QPointF screenPos = pt.globalPosition();
const QPointF delta = screenPos - screenPos.toPoint();
- touchPoint.d->pos = widget->mapFromGlobal(screenPos.toPoint()) + delta;
- touchPoint.d->startPos = widget->mapFromGlobal(touchPoint.globalPressPosition().toPoint()) + delta;
- touchPoint.d->lastPos = widget->mapFromGlobal(touchPoint.lastScreenPos().toPoint()) + delta;
+ QMutableEventPoint::from(pt).setPosition(widget->mapFromGlobal(screenPos.toPoint()) + delta);
- if (touchPoint.state() == Qt::TouchPointPressed)
+ if (pt.state() == QEventPoint::State::Pressed)
containsPress = true;
}
return containsPress;
@@ -3979,7 +3972,7 @@ void QApplicationPrivate::cleanupMultitouch_sys()
{
}
-QWidget *QApplicationPrivate::findClosestTouchPointTarget(const QPointingDevice *device, const QTouchEvent::TouchPoint &touchPoint)
+QWidget *QApplicationPrivate::findClosestTouchPointTarget(const QPointingDevice *device, const QEventPoint &touchPoint)
{
const QPointF screenPos = touchPoint.globalPosition();
int closestTouchPointId = -1;
@@ -3989,7 +3982,7 @@ QWidget *QApplicationPrivate::findClosestTouchPointTarget(const QPointingDevice
ite = activeTouchPoints.constEnd();
while (it != ite) {
if (it.key().device == device && it.key().touchPointId != touchPoint.id()) {
- const QTouchEvent::TouchPoint &touchPoint = it->touchPoint;
+ const QEventPoint &touchPoint = it->touchPoint;
qreal dx = screenPos.x() - touchPoint.globalPosition().x();
qreal dy = screenPos.y() - touchPoint.globalPosition().y();
qreal distance = dx * dx + dy * dy;
@@ -4010,7 +4003,7 @@ void QApplicationPrivate::activateImplicitTouchGrab(QWidget *widget, QTouchEvent
return;
for (int i = 0, tc = touchEvent->touchPoints().count(); i < tc; ++i) {
- const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i);
+ const QEventPoint &touchPoint = touchEvent->touchPoints().at(i);
activeTouchPoints[QGuiApplicationPrivate::ActiveTouchPointsKey(
touchEvent->pointingDevice(), touchPoint.id())].target = widget;
}
@@ -4018,30 +4011,31 @@ void QApplicationPrivate::activateImplicitTouchGrab(QWidget *widget, QTouchEvent
bool QApplicationPrivate::translateRawTouchEvent(QWidget *window,
const QPointingDevice *device,
- const QList<QTouchEvent::TouchPoint> &touchPoints,
+ const QList<QEventPoint> &touchPoints,
ulong timestamp)
{
QApplicationPrivate *d = self;
- typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints;
+ // TODO get rid of this QPair
+ typedef QPair<QEventPoint::State, QList<QEventPoint> > StatesAndTouchPoints;
QHash<QWidget *, StatesAndTouchPoints> widgetsNeedingEvents;
for (int i = 0; i < touchPoints.count(); ++i) {
- QTouchEvent::TouchPoint touchPoint = touchPoints.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();
+ QEventPoint touchPoint = touchPoints.at(i);
// update state
QPointer<QObject> target;
ActiveTouchPointsKey touchInfoKey(device, touchPoint.id());
ActiveTouchPointsValue &touchInfo = d->activeTouchPoints[touchInfoKey];
- if (touchPoint.state() == Qt::TouchPointPressed) {
- if (device->type() == QInputDevice::DeviceType::TouchPad) {
+ if (touchPoint.state() == QEventPoint::State::Pressed) {
+ if (device->type() == QInputDevice::DeviceType::TouchPad && !d->activeTouchPoints.isEmpty()) {
// on touch-pads, send all touch points to the same widget
- target = d->activeTouchPoints.isEmpty()
- ? QPointer<QObject>()
- : d->activeTouchPoints.constBegin().value().target;
+ // pick the first non-null target if possible
+ for (const auto &a : d->activeTouchPoints.values()) {
+ if (a.target) {
+ target = a.target;
+ break;
+ }
+ }
}
if (!target) {
@@ -4084,7 +4078,7 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window,
#endif
StatesAndTouchPoints &maskAndPoints = widgetsNeedingEvents[targetWidget];
- maskAndPoints.first |= touchPoint.state();
+ maskAndPoints.first = QEventPoint::State(maskAndPoints.first | touchPoint.state());
maskAndPoints.second.append(touchPoint);
}
@@ -4101,13 +4095,13 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window,
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
continue;
default:
@@ -4115,14 +4109,10 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window,
break;
}
- QTouchEvent touchEvent(eventType,
- device,
- QGuiApplication::keyboardModifiers(),
- it.value().first,
- it.value().second);
+ QMutableTouchEvent touchEvent(eventType, device, QGuiApplication::keyboardModifiers(),
+ it.value().second);
bool containsPress = updateTouchPointsForWidget(widget, &touchEvent);
touchEvent.setTimestamp(timestamp);
- touchEvent.setWindow(window->windowHandle());
touchEvent.setTarget(widget);
if (containsPress)
@@ -4160,7 +4150,7 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window,
void QApplicationPrivate::translateTouchCancel(const QPointingDevice *device, ulong timestamp)
{
- QTouchEvent touchEvent(QEvent::TouchCancel, device, QGuiApplication::keyboardModifiers());
+ QMutableTouchEvent touchEvent(QEvent::TouchCancel, device, QGuiApplication::keyboardModifiers());
touchEvent.setTimestamp(timestamp);
QHash<ActiveTouchPointsKey, ActiveTouchPointsValue>::const_iterator it
= self->activeTouchPoints.constBegin(), ite = self->activeTouchPoints.constEnd();
@@ -4174,7 +4164,6 @@ void QApplicationPrivate::translateTouchCancel(const QPointingDevice *device, ul
for (QSet<QWidget *>::const_iterator widIt = widgetsNeedingCancel.constBegin(),
widItEnd = widgetsNeedingCancel.constEnd(); widIt != widItEnd; ++widIt) {
QWidget *widget = *widIt;
- touchEvent.setWindow(widget->windowHandle());
touchEvent.setTarget(widget);
QApplication::sendSpontaneousEvent(widget, &touchEvent);
}
diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h
index e9595a9fbb..77182bf9dd 100644
--- a/src/widgets/kernel/qapplication_p.h
+++ b/src/widgets/kernel/qapplication_p.h
@@ -247,13 +247,13 @@ public:
void initializeMultitouch_sys();
void cleanupMultitouch();
void cleanupMultitouch_sys();
- QWidget *findClosestTouchPointTarget(const QPointingDevice *device, const QTouchEvent::TouchPoint &touchPoint);
- void appendTouchPoint(const QTouchEvent::TouchPoint &touchPoint);
+ QWidget *findClosestTouchPointTarget(const QPointingDevice *device, const QEventPoint &touchPoint);
+ void appendTouchPoint(const QEventPoint &touchPoint);
void removeTouchPoint(int touchPointId);
void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent);
static bool translateRawTouchEvent(QWidget *widget,
const QPointingDevice *device,
- const QList<QTouchEvent::TouchPoint> &touchPoints,
+ const QList<QEventPoint> &touchPoints,
ulong timestamp);
static void translateTouchCancel(const QPointingDevice *device, ulong timestamp);
diff --git a/src/widgets/kernel/qstandardgestures.cpp b/src/widgets/kernel/qstandardgestures.cpp
index 0a637ab6f8..48a2770df3 100644
--- a/src/widgets/kernel/qstandardgestures.cpp
+++ b/src/widgets/kernel/qstandardgestures.cpp
@@ -71,7 +71,7 @@ QGesture *QPanGestureRecognizer::create(QObject *target)
return new QPanGesture;
}
-static QPointF panOffset(const QList<QTouchEvent::TouchPoint> &touchPoints, int maxCount)
+static QPointF panOffset(const QList<QEventPoint> &touchPoints, int maxCount)
{
QPointF result;
const int count = qMin(touchPoints.size(), maxCount);
@@ -92,7 +92,7 @@ QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state,
case QEvent::TouchBegin: {
const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
result = QGestureRecognizer::MayBeGesture;
- QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
+ QEventPoint p = ev->touchPoints().at(0);
d->lastOffset = d->offset = QPointF();
d->pointCount = m_pointCount;
break;
@@ -185,8 +185,8 @@ QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state,
const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
d->changeFlags = { };
if (ev->touchPoints().size() == 2) {
- QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
- QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
+ QEventPoint p1 = ev->touchPoints().at(0);
+ QEventPoint p2 = ev->touchPoints().at(1);
d->hotSpot = p1.globalPosition();
d->isHotSpotSet = true;
@@ -209,7 +209,7 @@ QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state,
} else {
d->lastScaleFactor = d->scaleFactor;
QLineF line(p1.globalPosition(), p2.globalPosition());
- QLineF lastLine(p1.lastScreenPos(), p2.lastScreenPos());
+ QLineF lastLine(p1.globalLastPosition(), p2.globalLastPosition());
qreal newScaleFactor = line.length() / lastLine.length();
if (newScaleFactor > kSingleStepScaleMax || newScaleFactor < kSingleStepScaleMin)
return QGestureRecognizer::Ignore;
@@ -315,9 +315,9 @@ QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state,
result = QGestureRecognizer::CancelGesture;
else if (ev->touchPoints().size() == 3) {
d->state = QSwipeGesturePrivate::ThreePointsReached;
- QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
- QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
- QTouchEvent::TouchPoint p3 = ev->touchPoints().at(2);
+ QEventPoint p1 = ev->touchPoints().at(0);
+ QEventPoint p2 = ev->touchPoints().at(1);
+ QEventPoint p3 = ev->touchPoints().at(2);
if (d->lastPositions[0].isNull()) {
d->lastPositions[0] = p1.globalPressPosition().toPoint();
@@ -381,7 +381,7 @@ QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state,
result = QGestureRecognizer::Ignore;
break;
case QSwipeGesturePrivate::ThreePointsReached:
- result = (ev->touchPointStates() & Qt::TouchPointPressed)
+ result = (ev->touchPointStates() & QEventPoint::State::Pressed)
? QGestureRecognizer::CancelGesture : QGestureRecognizer::Ignore;
break;
}
@@ -447,7 +447,7 @@ QGestureRecognizer::Result QTapGestureRecognizer::recognize(QGesture *state,
case QEvent::TouchUpdate:
case QEvent::TouchEnd: {
if (q->state() != Qt::NoGesture && ev->touchPoints().size() == 1) {
- QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
+ QEventPoint p = ev->touchPoints().at(0);
QPoint delta = p.position().toPoint() - p.pressPosition().toPoint();
enum { TapRadius = 40 };
if (delta.manhattanLength() <= TapRadius) {
@@ -551,7 +551,7 @@ QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object,
case QEvent::TouchUpdate: {
const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
if (d->timerId && ev->touchPoints().size() == 1) {
- QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
+ QEventPoint p = ev->touchPoints().at(0);
QPoint delta = p.position().toPoint() - p.pressPosition().toPoint();
if (delta.manhattanLength() <= TapRadius)
return QGestureRecognizer::MayBeGesture;
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index a3befc4f0a..05bf43d669 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
@@ -563,8 +563,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
}
}
#endif
- if ((event->type() != QEvent::MouseButtonPress)
- || !(event->flags().testFlag(Qt::MouseEventCreatedDoubleClick))) {
+ if ((event->type() != QEvent::MouseButtonPress) || !(QMutableSinglePointEvent::from(event)->isDoubleClick())) {
// if the widget that was pressed is gone, then deliver move events without buttons
const auto buttons = event->type() == QEvent::MouseMove && qt_popup_down_closed
? Qt::NoButton : event->buttons();
@@ -666,8 +665,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
if (!receiver)
return;
- if ((event->type() != QEvent::MouseButtonPress)
- || !(event->flags().testFlag(Qt::MouseEventCreatedDoubleClick))) {
+ if ((event->type() != QEvent::MouseButtonPress) || !QMutableSinglePointEvent::from(event)->isDoubleClick()) {
// The preceding statement excludes MouseButtonPress events which caused
// creation of a MouseButtonDblClick event. QTBUG-25831
@@ -866,7 +864,8 @@ void QWidgetWindow::handleWheelEvent(QWheelEvent *event)
QPoint mapped = widget->mapFrom(rootWidget, pos);
QWheelEvent translated(QPointF(mapped), event->globalPosition(), event->pixelDelta(), event->angleDelta(),
- event->buttons(), event->modifiers(), event->phase(), event->inverted(), event->source());
+ event->buttons(), event->modifiers(), event->phase(), event->inverted(),
+ event->source(), event->pointingDevice());
translated.setTimestamp(event->timestamp());
QGuiApplication::forwardEvent(widget, &translated, event);
}