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 <shawn.rutledge@digia.com>
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
This commit is contained in:
Friedemann Kleint 2014-06-24 14:06:18 +02:00
parent 4696e9dbaa
commit bae7435f61
6 changed files with 79 additions and 1 deletions

View File

@ -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
{

View File

@ -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
*/

View File

@ -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)

View File

@ -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);

View File

@ -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;
}

View File

@ -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
}