From bae7435f61e68711b6b8ce056957a146dc1a335e Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 24 Jun 2014 14:06:18 +0200 Subject: [PATCH] Propagate source/flags of QMouseEvent to QGraphicsSceneMouseEvent. It is useful to be able to detect synthesized mouse events in GraphicsView as well. [ChangeLog][QtWidgets][QGraphicsSceneMouseEvent] Accessors for Qt::MouseEventSource and Qt::MouseEventFlags were added to QGraphicsSceneMouseEvent to enable detection of synthesized mouse events. Task-number: QTBUG-39814 Change-Id: Ib5835fef1f484005f9b0fc86518ed32ea79cd80f Reviewed-by: Shawn Rutledge Reviewed-by: Laszlo Agocs --- src/gui/kernel/qevent.cpp | 4 ++ .../graphicsview/qgraphicssceneevent.cpp | 58 ++++++++++++++++++- .../graphicsview/qgraphicssceneevent.h | 6 ++ src/widgets/graphicsview/qgraphicsview.cpp | 8 +++ src/widgets/statemachine/qguistatemachine.cpp | 2 + src/widgets/util/qflickgesture.cpp | 2 + 6 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 78e61058d1..f76166af18 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -287,6 +287,8 @@ QMouseEvent::~QMouseEvent() \l Qt::MouseEventNotSynthesized is returned always. \sa Qt::MouseEventSource + \sa QGraphicsSceneMouseEvent::source() + \sa QGraphicsSceneMouseEvent::setSource() */ Qt::MouseEventSource QMouseEvent::source() const { @@ -301,6 +303,8 @@ Qt::MouseEventSource QMouseEvent::source() const The mouse event flags provide additional information about a mouse event. \sa Qt::MouseEventFlag + \sa QGraphicsSceneMouseEvent::flags() + \sa QGraphicsSceneMouseEvent::setFlags() */ Qt::MouseEventFlags QMouseEvent::flags() const { diff --git a/src/widgets/graphicsview/qgraphicssceneevent.cpp b/src/widgets/graphicsview/qgraphicssceneevent.cpp index 631aa7bf19..be91c63fad 100644 --- a/src/widgets/graphicsview/qgraphicssceneevent.cpp +++ b/src/widgets/graphicsview/qgraphicssceneevent.cpp @@ -348,7 +348,7 @@ class QGraphicsSceneMouseEventPrivate : public QGraphicsSceneEventPrivate public: inline QGraphicsSceneMouseEventPrivate() : button(Qt::NoButton), - buttons(0), modifiers(0) + buttons(0), modifiers(0), source(Qt::MouseEventNotSynthesized), flags(0) { } QPointF pos; @@ -363,6 +363,8 @@ public: Qt::MouseButton button; Qt::MouseButtons buttons; Qt::KeyboardModifiers modifiers; + Qt::MouseEventSource source; + Qt::MouseEventFlags flags; }; /*! @@ -625,6 +627,60 @@ Qt::KeyboardModifiers QGraphicsSceneMouseEvent::modifiers() const return d->modifiers; } +/*! + \since 5.4 + + 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. + + \sa Qt::MouseEventSource + \sa QMouseEvent::source() + */ +Qt::MouseEventSource QGraphicsSceneMouseEvent::source() const +{ + Q_D(const QGraphicsSceneMouseEvent); + return d->source; +} + +/*! + \since 5.4 + \internal + */ +void QGraphicsSceneMouseEvent::setSource(Qt::MouseEventSource source) +{ + Q_D(QGraphicsSceneMouseEvent); + d->source = source; +} + +/*! + \since 5.4 + + Returns the mouse event flags. + + The mouse event flags provide additional information about a mouse event. + + \sa Qt::MouseEventFlag + \sa QMouseEvent::flags() + */ +Qt::MouseEventFlags QGraphicsSceneMouseEvent::flags() const +{ + Q_D(const QGraphicsSceneMouseEvent); + return d->flags; +} + +/*! + \since 5.4 + \internal + */ +void QGraphicsSceneMouseEvent::setFlags(Qt::MouseEventFlags flags) +{ + Q_D(QGraphicsSceneMouseEvent); + d->flags = flags; +} + /*! \internal */ diff --git a/src/widgets/graphicsview/qgraphicssceneevent.h b/src/widgets/graphicsview/qgraphicssceneevent.h index e744d08edf..2c9c1f3f50 100644 --- a/src/widgets/graphicsview/qgraphicssceneevent.h +++ b/src/widgets/graphicsview/qgraphicssceneevent.h @@ -121,6 +121,12 @@ public: Qt::KeyboardModifiers modifiers() const; void setModifiers(Qt::KeyboardModifiers modifiers); + Qt::MouseEventSource source() const; + void setSource(Qt::MouseEventSource source); + + Qt::MouseEventFlags flags() const; + void setFlags(Qt::MouseEventFlags); + private: Q_DECLARE_PRIVATE(QGraphicsSceneMouseEvent) Q_DISABLE_COPY(QGraphicsSceneMouseEvent) diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index 5bcf52b6a3..9cd684a408 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -655,6 +655,8 @@ void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event) mouseEvent.setButtons(event->buttons()); mouseEvent.setButton(event->button()); mouseEvent.setModifiers(event->modifiers()); + mouseEvent.setSource(event->source()); + mouseEvent.setFlags(event->flags()); lastMouseMoveScenePoint = mouseEvent.scenePos(); lastMouseMoveScreenPoint = mouseEvent.screenPos(); mouseEvent.setAccepted(false); @@ -3217,6 +3219,8 @@ void QGraphicsView::mouseDoubleClickEvent(QMouseEvent *event) mouseEvent.setAccepted(false); mouseEvent.setButton(event->button()); mouseEvent.setModifiers(event->modifiers()); + mouseEvent.setSource(event->source()); + mouseEvent.setFlags(event->flags()); if (event->spontaneous()) qt_sendSpontaneousEvent(d->scene, &mouseEvent); else @@ -3265,6 +3269,8 @@ void QGraphicsView::mousePressEvent(QMouseEvent *event) mouseEvent.setButtons(event->buttons()); mouseEvent.setButton(event->button()); mouseEvent.setModifiers(event->modifiers()); + mouseEvent.setSource(event->source()); + mouseEvent.setFlags(event->flags()); mouseEvent.setAccepted(false); if (event->spontaneous()) qt_sendSpontaneousEvent(d->scene, &mouseEvent); @@ -3392,6 +3398,8 @@ void QGraphicsView::mouseReleaseEvent(QMouseEvent *event) mouseEvent.setButtons(event->buttons()); mouseEvent.setButton(event->button()); mouseEvent.setModifiers(event->modifiers()); + mouseEvent.setSource(event->source()); + mouseEvent.setFlags(event->flags()); mouseEvent.setAccepted(false); if (event->spontaneous()) qt_sendSpontaneousEvent(d->scene, &mouseEvent); diff --git a/src/widgets/statemachine/qguistatemachine.cpp b/src/widgets/statemachine/qguistatemachine.cpp index d737a1e323..9824b96334 100644 --- a/src/widgets/statemachine/qguistatemachine.cpp +++ b/src/widgets/statemachine/qguistatemachine.cpp @@ -312,6 +312,8 @@ static QEvent *cloneEvent(QEvent *e) me2->setButtons(me->buttons()); me2->setButton(me->button()); me2->setModifiers(me->modifiers()); + me2->setSource(me->source()); + me2->setFlags(me->flags()); return me2; } diff --git a/src/widgets/util/qflickgesture.cpp b/src/widgets/util/qflickgesture.cpp index b0cd4a9540..a372a7fe0d 100644 --- a/src/widgets/util/qflickgesture.cpp +++ b/src/widgets/util/qflickgesture.cpp @@ -101,6 +101,8 @@ static QMouseEvent *copyMouseEvent(QEvent *e) copy->setButtons(me->buttons()); copy->setButton(me->button()); copy->setModifiers(me->modifiers()); + copy->setSource(me->source()); + copy->setFlags(me->flags()); return copy; #endif }