From 2764d82dc4b2ffdc2a21bd78c75cec14f59c2adf Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Wed, 13 Sep 2017 20:35:36 +0200 Subject: [PATCH] tablet: use enhanced mouse event when synthesizing mouse All the required data is just there, few lines above. Instead of throwing it away and then deducing again in mouse event handler, use the enhanced mouse constructor. Tablet event handler was the last remaining user of the obsolete mouse event constructor. This patch removes the now unused construtor. Change-Id: I0df7f1b82f0e768f651aa7fbe2d4efce93e992fa Reviewed-by: Paul Olav Tvete --- src/gui/kernel/qguiapplication.cpp | 36 +++++++++++++++-------- src/gui/kernel/qwindowsysteminterface_p.h | 7 ----- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 20fe738469..d967b03fee 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2409,20 +2409,30 @@ void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::T break; } } - QTabletEvent ev(type, local, e->global, - e->device, e->pointerType, e->pressure, e->xTilt, e->yTilt, - e->tangentialPressure, e->rotation, e->z, - e->modifiers, e->uid, button, e->buttons); - ev.setAccepted(false); - ev.setTimestamp(e->timestamp); - QGuiApplication::sendSpontaneousEvent(window, &ev); + QTabletEvent tabletEvent(type, local, e->global, + e->device, e->pointerType, e->pressure, e->xTilt, e->yTilt, + e->tangentialPressure, e->rotation, e->z, + e->modifiers, e->uid, button, e->buttons); + tabletEvent.setAccepted(false); + tabletEvent.setTimestamp(e->timestamp); + QGuiApplication::sendSpontaneousEvent(window, &tabletEvent); pointData.state = e->buttons; - if (!ev.isAccepted() && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse - && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) { - QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp, e->local, e->global, - e->buttons, e->modifiers, Qt::MouseEventSynthesizedByQt); - fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic; - processMouseEvent(&fake); + if (!tabletEvent.isAccepted() + && !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse + && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) { + + const QEvent::Type mouseType = [&]() { + switch (type) { + case QEvent::TabletPress: return QEvent::MouseButtonPress; + case QEvent::TabletMove: return QEvent::MouseMove; + case QEvent::TabletRelease: return QEvent::MouseButtonRelease; + default: Q_UNREACHABLE(); + } + }(); + QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, e->local, + e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventSynthesizedByQt); + mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic; + processMouseEvent(&mouseEvent); } #else Q_UNUSED(e) diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index 4fdf34c7b3..152ea92919 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -225,13 +225,6 @@ public: class MouseEvent : public InputEvent { public: - // TODO - remove this ctor when all usages of it in QGuiApplication are cleaned out - MouseEvent(QWindow * w, ulong time, const QPointF &local, const QPointF &global, - Qt::MouseButtons b, Qt::KeyboardModifiers mods, - Qt::MouseEventSource src = Qt::MouseEventNotSynthesized, bool frame = false) - : InputEvent(w, time, Mouse, mods), localPos(local), globalPos(global), buttons(b), - source(src), nonClientArea(frame), button(Qt::NoButton), buttonType(QEvent::None) { } - MouseEvent(QWindow *w, ulong time, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::KeyboardModifiers mods, Qt::MouseButton b, QEvent::Type type,