From 77e00909951f9274bccec20be950425ba9dbe744 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Wed, 22 Apr 2015 18:43:33 +0300 Subject: QMouseEvent: add constructor which takes the source as a parameter Simplify the code by passing the source of a mouse event directly to the constructor instead of setting it by QGuiApplicationPrivate::setMouseEventSource(). Change-Id: I1774cf39a211d36d3adf0ff30f3bd2fb7c5fb429 Reviewed-by: Laszlo Agocs --- src/gui/kernel/qevent.cpp | 30 ++++++++++++++++++++++++++++++ src/gui/kernel/qevent.h | 3 +++ src/gui/kernel/qguiapplication.cpp | 6 ++---- 3 files changed, 35 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 11f7f13552..006f4d6245 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -262,6 +262,36 @@ QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &wind : QInputEvent(type, modifiers), l(localPos), w(windowPos), s(screenPos), b(button), mouseState(buttons), caps(0) {} +/*! + \since 5.6 + + 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 windowPos and \a screenPos specify the + mouse cursor's position relative to the receiving widget or item, + window, and screen, 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 + 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 &windowPos, const QPointF &screenPos, + Qt::MouseButton button, Qt::MouseButtons buttons, + Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source) + : QInputEvent(type, modifiers), l(localPos), w(windowPos), s(screenPos), b(button), mouseState(buttons), caps(0) +{ + QGuiApplicationPrivate::setMouseEventSource(this, source); +} + /*! \internal */ diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index e931e28a2e..0cf0601db9 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -106,6 +106,9 @@ public: QMouseEvent(Type type, const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); + QMouseEvent(Type type, const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos, + Qt::MouseButton button, Qt::MouseButtons buttons, + Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source); ~QMouseEvent(); #ifndef QT_NO_INTEGER_EVENT_COORDINATES diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 926ec16f19..af93a93cfe 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1766,9 +1766,8 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo if (!window) return; - QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, buttons, e->modifiers); + QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, buttons, e->modifiers, e->source); ev.setTimestamp(e->timestamp); - setMouseEventSource(&ev, e->source); #ifndef QT_NO_CURSOR if (!e->synthetic()) { if (const QScreen *screen = window->screen()) @@ -1827,9 +1826,8 @@ 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 = frameStrut ? QEvent::NonClientAreaMouseButtonDblClick : QEvent::MouseButtonDblClick; QMouseEvent dblClickEvent(doubleClickType, localPoint, localPoint, globalPoint, - button, buttons, e->modifiers); + button, buttons, e->modifiers, e->source); dblClickEvent.setTimestamp(e->timestamp); - setMouseEventSource(&dblClickEvent, e->source); QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent); } } -- cgit v1.2.3