summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-08-25 14:36:49 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-08-26 14:32:26 +0200
commit98d65c8d423c2ff7f5ee1a511f34b111943c5a8a (patch)
treeac495fafaea086d5dc69b6b87fbf34f4d4a85473 /src
parent842ece2117f245c42bfd713a726fe2dd1a8998e7 (diff)
QGraphicsView: send timestamp information through QGraphicsSceneEvent
Qt relies on event timestamp information to detect double click events. The information was not passed through QGraphicsSceneEvent, so the synthesized QMouseEvent delivered for the second press of a double click to an embedded widget was never recognized as a double click. This requires addition of a new setter/getter to QGraphicsSceneEvent. Event though not all QGraphicsSceneEvent instances will have a valid timestamp, this provides us with more flexibility than adding the API to several QGraphicsSceneEvent types (mouse, touch, wheel). Pick-to: 6.2 Fixes: QTBUG-96009 Change-Id: I343f25902286157f6d6670641dfad9c92dd44250 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/graphicsview/qgraphicsproxywidget.cpp3
-rw-r--r--src/widgets/graphicsview/qgraphicssceneevent.cpp21
-rw-r--r--src/widgets/graphicsview/qgraphicssceneevent.h3
-rw-r--r--src/widgets/graphicsview/qgraphicsview.cpp7
4 files changed, 34 insertions, 0 deletions
diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp
index d7eb62407d..9a577455a6 100644
--- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp
+++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp
@@ -239,6 +239,7 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneHoverEvent
mouseEvent.setButton(Qt::NoButton);
mouseEvent.setButtons({ });
mouseEvent.setModifiers(event->modifiers());
+ mouseEvent.setTimestamp(event->timestamp());
sendWidgetMouseEvent(&mouseEvent);
event->setAccepted(mouseEvent.isAccepted());
}
@@ -304,6 +305,7 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent
QMouseEvent mouseEvent(type, pos, receiver->mapTo(receiver->topLevelWidget(), pos.toPoint()),
receiver->mapToGlobal(pos.toPoint()),
event->button(), event->buttons(), event->modifiers(), event->source());
+ mouseEvent.setTimestamp(event->timestamp());
QWidget *embeddedMouseGrabberPtr = (QWidget *)embeddedMouseGrabber;
QApplicationPrivate::sendMouseEvent(receiver, &mouseEvent, alienWidget, widget,
@@ -1047,6 +1049,7 @@ void QGraphicsProxyWidget::contextMenuEvent(QGraphicsSceneContextMenuEvent *even
// Send mouse event. ### Doesn't propagate the event.
QContextMenuEvent contextMenuEvent(QContextMenuEvent::Reason(event->reason()),
pos.toPoint(), globalPos, event->modifiers());
+ contextMenuEvent.setTimestamp(event->timestamp());
QCoreApplication::sendEvent(receiver, &contextMenuEvent);
event->setAccepted(contextMenuEvent.isAccepted());
diff --git a/src/widgets/graphicsview/qgraphicssceneevent.cpp b/src/widgets/graphicsview/qgraphicssceneevent.cpp
index e33f38c7c9..2608d2d5f1 100644
--- a/src/widgets/graphicsview/qgraphicssceneevent.cpp
+++ b/src/widgets/graphicsview/qgraphicssceneevent.cpp
@@ -287,6 +287,7 @@ public:
QWidget *widget;
QGraphicsSceneEvent *q_ptr;
+ quint64 timestamp = 0;
};
/*!
@@ -339,6 +340,26 @@ void QGraphicsSceneEvent::setWidget(QWidget *widget)
d_ptr->widget = widget;
}
+/*!
+ \since 6.2
+
+ Returns the timestamp of the original event, or 0 if the
+ original event does not report a time stamp.
+*/
+quint64 QGraphicsSceneEvent::timestamp() const
+{
+ return d_ptr->timestamp;
+}
+/*!
+ \internal
+
+ Sets the timestamp for the event to \a ts.
+*/
+void QGraphicsSceneEvent::setTimestamp(quint64 ts)
+{
+ d_ptr->timestamp = ts;
+}
+
class QGraphicsSceneMouseEventPrivate : public QGraphicsSceneEventPrivate
{
Q_DECLARE_PUBLIC(QGraphicsSceneMouseEvent)
diff --git a/src/widgets/graphicsview/qgraphicssceneevent.h b/src/widgets/graphicsview/qgraphicssceneevent.h
index 639b9c750e..f9de1d148b 100644
--- a/src/widgets/graphicsview/qgraphicssceneevent.h
+++ b/src/widgets/graphicsview/qgraphicssceneevent.h
@@ -67,6 +67,9 @@ public:
QWidget *widget() const;
void setWidget(QWidget *widget);
+ quint64 timestamp() const;
+ void setTimestamp(quint64 ts);
+
protected:
QGraphicsSceneEvent(QGraphicsSceneEventPrivate &dd, Type type = None);
QScopedPointer<QGraphicsSceneEventPrivate> d_ptr;
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp
index b6ed0080d7..47e3c8f372 100644
--- a/src/widgets/graphicsview/qgraphicsview.cpp
+++ b/src/widgets/graphicsview/qgraphicsview.cpp
@@ -671,6 +671,7 @@ void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event)
mouseEvent.setModifiers(event->modifiers());
mouseEvent.setSource(event->source());
mouseEvent.setFlags(event->flags());
+ mouseEvent.setTimestamp(event->timestamp());
lastMouseMoveScenePoint = mouseEvent.scenePos();
lastMouseMoveScreenPoint = mouseEvent.screenPos();
mouseEvent.setAccepted(false);
@@ -873,6 +874,7 @@ void QGraphicsViewPrivate::storeDragDropEvent(const QGraphicsSceneDragDropEvent
lastDragDropEvent->setMimeData(event->mimeData());
lastDragDropEvent->setWidget(event->widget());
lastDragDropEvent->setSource(event->source());
+ lastDragDropEvent->setTimestamp(event->timestamp());
}
/*!
@@ -2973,6 +2975,7 @@ void QGraphicsView::contextMenuEvent(QContextMenuEvent *event)
contextEvent.setModifiers(event->modifiers());
contextEvent.setReason((QGraphicsSceneContextMenuEvent::Reason)(event->reason()));
contextEvent.setAccepted(event->isAccepted());
+ contextEvent.setTimestamp(event->timestamp());
QCoreApplication::sendEvent(d->scene, &contextEvent);
event->setAccepted(contextEvent.isAccepted());
}
@@ -3188,6 +3191,7 @@ void QGraphicsView::mouseDoubleClickEvent(QMouseEvent *event)
mouseEvent.setModifiers(event->modifiers());
mouseEvent.setSource(event->source());
mouseEvent.setFlags(event->flags());
+ mouseEvent.setTimestamp(event->timestamp());
if (event->spontaneous())
qt_sendSpontaneousEvent(d->scene, &mouseEvent);
else
@@ -3239,6 +3243,7 @@ void QGraphicsView::mousePressEvent(QMouseEvent *event)
mouseEvent.setSource(event->source());
mouseEvent.setFlags(event->flags());
mouseEvent.setAccepted(false);
+ mouseEvent.setTimestamp(event->timestamp());
if (event->spontaneous())
qt_sendSpontaneousEvent(d->scene, &mouseEvent);
else
@@ -3362,6 +3367,7 @@ void QGraphicsView::mouseReleaseEvent(QMouseEvent *event)
mouseEvent.setSource(event->source());
mouseEvent.setFlags(event->flags());
mouseEvent.setAccepted(false);
+ mouseEvent.setTimestamp(event->timestamp());
if (event->spontaneous())
qt_sendSpontaneousEvent(d->scene, &mouseEvent);
else
@@ -3405,6 +3411,7 @@ void QGraphicsView::wheelEvent(QWheelEvent *event)
wheelEvent.setInverted(event->isInverted());
wheelEvent.setOrientation(horizontal ? Qt::Horizontal : Qt::Vertical);
wheelEvent.setAccepted(false);
+ wheelEvent.setTimestamp(event->timestamp());
QCoreApplication::sendEvent(d->scene, &wheelEvent);
event->setAccepted(wheelEvent.isAccepted());
if (!event->isAccepted())