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 <laszlo.agocs@theqtcompany.com>
This commit is contained in:
parent
ac1b6c0145
commit
77e0090995
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -269,8 +269,7 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent
|
||||
// Send mouse event.
|
||||
QMouseEvent mouseEvent(type, pos, receiver->mapTo(receiver->topLevelWidget(), pos.toPoint()),
|
||||
receiver->mapToGlobal(pos.toPoint()),
|
||||
event->button(), event->buttons(), event->modifiers());
|
||||
QGuiApplicationPrivate::setMouseEventSource(&mouseEvent, event->source());
|
||||
event->button(), event->buttons(), event->modifiers(), event->source());
|
||||
|
||||
QWidget *embeddedMouseGrabberPtr = (QWidget *)embeddedMouseGrabber;
|
||||
QApplicationPrivate::sendMouseEvent(receiver, &mouseEvent, alienWidget, widget,
|
||||
|
@ -1882,8 +1882,7 @@ void QAbstractItemView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
|| (d->pressedIndex != index)) {
|
||||
QMouseEvent me(QEvent::MouseButtonPress,
|
||||
event->localPos(), event->windowPos(), event->screenPos(),
|
||||
event->button(), event->buttons(), event->modifiers());
|
||||
QGuiApplicationPrivate::setMouseEventSource(&me, event->source());
|
||||
event->button(), event->buttons(), event->modifiers(), event->source());
|
||||
mousePressEvent(&me);
|
||||
return;
|
||||
}
|
||||
|
@ -3250,12 +3250,11 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
||||
|
||||
QPointer<QWidget> pw = w;
|
||||
while (w) {
|
||||
QMouseEvent me(mouse->type(), relpos, mouse->windowPos(), mouse->globalPos(), mouse->button(), mouse->buttons(),
|
||||
mouse->modifiers());
|
||||
QMouseEvent me(mouse->type(), relpos, mouse->windowPos(), mouse->globalPos(),
|
||||
mouse->button(), mouse->buttons(), mouse->modifiers(), mouse->source());
|
||||
me.spont = mouse->spontaneous();
|
||||
me.setTimestamp(mouse->timestamp());
|
||||
QGuiApplicationPrivate::setMouseEventFlags(&me, mouse->flags());
|
||||
QGuiApplicationPrivate::setMouseEventSource(&me, mouse->source());
|
||||
// throw away any mouse-tracking-only mouse events
|
||||
if (!w->hasMouseTracking()
|
||||
&& mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) {
|
||||
|
@ -446,8 +446,8 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
|
||||
if (receiver != popup)
|
||||
widgetPos = receiver->mapFromGlobal(event->globalPos());
|
||||
QWidget *alien = m_widget->childAt(m_widget->mapFromGlobal(event->globalPos()));
|
||||
QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers());
|
||||
QGuiApplicationPrivate::setMouseEventSource(&e, QGuiApplicationPrivate::mouseEventSource(event));
|
||||
QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(),
|
||||
event->button(), event->buttons(), event->modifiers(), event->source());
|
||||
e.setTimestamp(event->timestamp());
|
||||
QApplicationPrivate::sendMouseEvent(receiver, &e, alien, m_widget, &qt_button_down, qt_last_mouse_receiver);
|
||||
qt_last_mouse_receiver = receiver;
|
||||
@ -489,9 +489,9 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
|
||||
if (globalGeometry.contains(event->globalPos())) {
|
||||
// Use postEvent() to ensure the local QEventLoop terminates when called from QMenu::exec()
|
||||
const QPoint localPos = win->mapFromGlobal(event->globalPos());
|
||||
QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers());
|
||||
QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(),
|
||||
event->button(), event->buttons(), event->modifiers(), event->source());
|
||||
QCoreApplicationPrivate::setEventSpontaneous(e, true);
|
||||
QGuiApplicationPrivate::setMouseEventSource(e, QGuiApplicationPrivate::mouseEventSource(event));
|
||||
e->setTimestamp(event->timestamp());
|
||||
QCoreApplication::postEvent(win, e);
|
||||
}
|
||||
@ -548,8 +548,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
|
||||
// The preceding statement excludes MouseButtonPress events which caused
|
||||
// creation of a MouseButtonDblClick event. QTBUG-25831
|
||||
QMouseEvent translated(event->type(), mapped, event->windowPos(), event->screenPos(),
|
||||
event->button(), event->buttons(), event->modifiers());
|
||||
QGuiApplicationPrivate::setMouseEventSource(&translated, QGuiApplicationPrivate::mouseEventSource(event));
|
||||
event->button(), event->buttons(), event->modifiers(), event->source());
|
||||
translated.setTimestamp(event->timestamp());
|
||||
QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget,
|
||||
&qt_button_down, qt_last_mouse_receiver);
|
||||
|
@ -66,8 +66,8 @@ static QMouseEvent *copyMouseEvent(QEvent *e)
|
||||
case QEvent::MouseButtonRelease:
|
||||
case QEvent::MouseMove: {
|
||||
QMouseEvent *me = static_cast<QMouseEvent *>(e);
|
||||
QMouseEvent *cme = new QMouseEvent(me->type(), QPoint(0, 0), me->windowPos(), me->screenPos(), me->button(), me->buttons(), me->modifiers());
|
||||
QGuiApplicationPrivate::setMouseEventSource(cme, me->source());
|
||||
QMouseEvent *cme = new QMouseEvent(me->type(), QPoint(0, 0), me->windowPos(), me->screenPos(),
|
||||
me->button(), me->buttons(), me->modifiers(), me->source());
|
||||
return cme;
|
||||
}
|
||||
#ifndef QT_NO_GRAPHICSVIEW
|
||||
@ -78,8 +78,8 @@ static QMouseEvent *copyMouseEvent(QEvent *e)
|
||||
#if 1
|
||||
QEvent::Type met = me->type() == QEvent::GraphicsSceneMousePress ? QEvent::MouseButtonPress :
|
||||
(me->type() == QEvent::GraphicsSceneMouseRelease ? QEvent::MouseButtonRelease : QEvent::MouseMove);
|
||||
QMouseEvent *cme = new QMouseEvent(met, QPoint(0, 0), QPoint(0, 0), me->screenPos(), me->button(), me->buttons(), me->modifiers());
|
||||
QGuiApplicationPrivate::setMouseEventSource(cme, me->source());
|
||||
QMouseEvent *cme = new QMouseEvent(met, QPoint(0, 0), QPoint(0, 0), me->screenPos(),
|
||||
me->button(), me->buttons(), me->modifiers(), me->source());
|
||||
return cme;
|
||||
#else
|
||||
QGraphicsSceneMouseEvent *copy = new QGraphicsSceneMouseEvent(me->type());
|
||||
@ -240,8 +240,7 @@ public:
|
||||
qFGDebug() << "QFG: sending a fake mouse release at far-far-away to " << mouseTarget;
|
||||
QMouseEvent re(QEvent::MouseButtonRelease, QPoint(), farFarAway, farFarAway,
|
||||
mouseButton, QApplication::mouseButtons() & ~mouseButton,
|
||||
QApplication::keyboardModifiers());
|
||||
QGuiApplicationPrivate::setMouseEventSource(&re, mouseEventSource);
|
||||
QApplication::keyboardModifiers(), mouseEventSource);
|
||||
sendMouseEvent(&re, RegrabMouseAfterwards);
|
||||
// don't clear the mouseTarget just yet, since we need to explicitly ungrab the mouse on release!
|
||||
}
|
||||
@ -291,8 +290,7 @@ protected:
|
||||
if (me) {
|
||||
QMouseEvent copy(me->type(), mouseTarget->mapFromGlobal(me->globalPos()),
|
||||
mouseTarget->topLevelWidget()->mapFromGlobal(me->globalPos()), me->screenPos(),
|
||||
me->button(), me->buttons(), me->modifiers());
|
||||
QGuiApplicationPrivate::setMouseEventSource(©, me->source());
|
||||
me->button(), me->buttons(), me->modifiers(), me->source());
|
||||
qt_sendSpontaneousEvent(mouseTarget, ©);
|
||||
}
|
||||
|
||||
|
@ -1110,8 +1110,7 @@ bool QMenuPrivate::mouseEventTaken(QMouseEvent *e)
|
||||
handleEnterLeaveEvents(&previousMouseMenu,qobject_cast<QMenu *>(caused));
|
||||
if(e->type() != QEvent::MouseButtonRelease || mouseDown == caused) {
|
||||
QMouseEvent new_e(e->type(), cpos, caused->mapTo(caused->topLevelWidget(), cpos), e->screenPos(),
|
||||
e->button(), e->buttons(), e->modifiers());
|
||||
QGuiApplicationPrivate::setMouseEventSource(&new_e, e->source());
|
||||
e->button(), e->buttons(), e->modifiers(), e->source());
|
||||
QApplication::sendEvent(caused, &new_e);
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user