summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-03-27 16:06:11 +0000
committerShawn Rutledge <shawn.rutledge@qt.io>2020-07-10 14:32:56 +0200
commit4e400369c08db251cd489fec1229398c224d02b4 (patch)
tree6279489dce7b0469d590461798deccf5d1193e29 /src/widgets
parent773a6bffd78b363577d27604e17f4ee08ff07e77 (diff)
Refactor pointer event hierarchy
Some goals that have hopefully been achieved are: - make QPointerEvent and QEventPoint resemble their Qt Quick counterparts to such an extent that we can remove those wrappers and go back to delivering the original events in Qt Quick - make QEventPoint much smaller than QTouchEvent::TouchPoint, with no pimpl - remove most public setters - reduce the usage of complex constructors that take many arguments - don't repeat ourselves: move accessors and storage upwards rather than having redundant ones in subclasses - standardize the set of accessors in QPointerEvent - maintain source compatibility as much as possible: do not require modifying event-handling code in any QWidget subclass To avoid public setters we now introduce a few QMutable* subclasses. This is a bit like the Builder pattern except that it doesn't involve constructing a separate disposable object: the main event type can be cast to the mutable type at any time to enable modifications, iff the code is linked with gui-private. Therefore event classes can have less-"complete" constructors, because internal Qt code can use setters the same way it could use the ones in QTouchEvent before; and the event classes don't need many friends. Even some read-accessors can be kept private unless we are sure we want to expose them. Task-number: QTBUG-46266 Fixes: QTBUG-72173 Change-Id: I740e4e40165b7bc41223d38b200bbc2b403e07b6 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets')
-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
10 files changed, 78 insertions, 96 deletions
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);
}