Fix QGuiApplication::keyboardModifiers() and QGuiApplication::mouseButtons()
Previous commitbb10b2363a935cfixed keyboardModifiers() after QPA event processing, but broke QTestLib, which expects spontaneous input events sent to qApp->notify() to update keyboardModifiers() and mouseButtons(). The commit also did not fix mouseButtons() after QPA event processing, and missed keyboardModifiers() after QPA Tablet event processing. This commit fixes all these shortcommings inb2363a935c. Includes test case by David Faure <faure@kde.org> Task-Number: QTBUG-26887 Change-Id: I8518b06c4ce86ea7b35120e3353a45ea2a81d356 Reviewed-by: David Faure (KDE) <faure@kde.org> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
parent
f415d86d1e
commit
cf2a75e41b
|
|
@ -1392,7 +1392,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
|
|||
// Ignore mouse events that don't change the current state.
|
||||
return;
|
||||
}
|
||||
buttons = e->buttons;
|
||||
mouse_buttons = buttons = e->buttons;
|
||||
if (button & e->buttons) {
|
||||
ulong doubleClickInterval = static_cast<ulong>(qApp->styleHints()->mouseDoubleClickInterval());
|
||||
doubleClick = e->timestamp - mousePressTime < doubleClickInterval && button == mousePressButton;
|
||||
|
|
@ -1688,7 +1688,10 @@ void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::T
|
|||
type = e->down ? QEvent::TabletPress : QEvent::TabletRelease;
|
||||
tabletState = e->down;
|
||||
}
|
||||
|
||||
QWindow *window = e->window.data();
|
||||
modifier_buttons = e->modifiers;
|
||||
|
||||
bool localValid = true;
|
||||
// If window is null, pick one based on the global position and make sure all
|
||||
// subsequent events up to the release are delivered to that same window.
|
||||
|
|
@ -1719,7 +1722,7 @@ void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::T
|
|||
QTabletEvent ev(type, local, e->global,
|
||||
e->device, e->pointerType, e->pressure, e->xTilt, e->yTilt,
|
||||
e->tangentialPressure, e->rotation, e->z,
|
||||
e->mods, e->uid);
|
||||
e->modifiers, e->uid);
|
||||
ev.setTimestamp(e->timestamp);
|
||||
QGuiApplication::sendSpontaneousEvent(window, &ev);
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -302,10 +302,10 @@ public:
|
|||
TabletEvent(QWindow *w, ulong time, bool down, const QPointF &local, const QPointF &global,
|
||||
int device, int pointerType, qreal pressure, int xTilt, int yTilt, qreal tpressure,
|
||||
qreal rotation, int z, qint64 uid, Qt::KeyboardModifiers mods)
|
||||
: InputEvent(w, time, Tablet, Qt::NoModifier),
|
||||
: InputEvent(w, time, Tablet, mods),
|
||||
down(down), local(local), global(global), device(device), pointerType(pointerType),
|
||||
pressure(pressure), xTilt(xTilt), yTilt(yTilt), tangentialPressure(tpressure),
|
||||
rotation(rotation), z(z), uid(uid), mods(mods) { }
|
||||
rotation(rotation), z(z), uid(uid) { }
|
||||
bool down;
|
||||
QPointF local;
|
||||
QPointF global;
|
||||
|
|
@ -318,7 +318,6 @@ public:
|
|||
qreal rotation;
|
||||
int z;
|
||||
qint64 uid;
|
||||
Qt::KeyboardModifiers mods;
|
||||
};
|
||||
|
||||
class TabletEnterProximityEvent : public InputEvent {
|
||||
|
|
|
|||
|
|
@ -2709,16 +2709,48 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
|
|||
if (receiver->isWindowType())
|
||||
QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(static_cast<QWindow *>(receiver), e);
|
||||
|
||||
// capture the current mouse/keyboard state
|
||||
if(e->spontaneous()) {
|
||||
if (e->type() == QEvent::MouseButtonPress
|
||||
|| e->type() == QEvent::MouseButtonRelease) {
|
||||
// Capture the current mouse and keyboard states. Doing so here is
|
||||
// required in order to support QTestLib synthesized events. Real mouse
|
||||
// and keyboard state updates from the platform plugin are managed by
|
||||
// QGuiApplicationPrivate::process(Mouse|Wheel|Key|Touch|Tablet)Event();
|
||||
switch (e->type()) {
|
||||
case QEvent::MouseButtonPress:
|
||||
{
|
||||
QMouseEvent *me = static_cast<QMouseEvent*>(e);
|
||||
if(me->type() == QEvent::MouseButtonPress)
|
||||
QApplicationPrivate::mouse_buttons |= me->button();
|
||||
else
|
||||
QApplicationPrivate::mouse_buttons &= ~me->button();
|
||||
QApplicationPrivate::modifier_buttons = me->modifiers();
|
||||
QApplicationPrivate::mouse_buttons |= me->button();
|
||||
break;
|
||||
}
|
||||
case QEvent::MouseButtonRelease:
|
||||
{
|
||||
QMouseEvent *me = static_cast<QMouseEvent*>(e);
|
||||
QApplicationPrivate::modifier_buttons = me->modifiers();
|
||||
QApplicationPrivate::mouse_buttons &= ~me->button();
|
||||
break;
|
||||
}
|
||||
case QEvent::KeyPress:
|
||||
case QEvent::KeyRelease:
|
||||
case QEvent::MouseMove:
|
||||
#ifndef QT_NO_WHEELEVENT
|
||||
case QEvent::Wheel:
|
||||
#endif
|
||||
case QEvent::TouchBegin:
|
||||
case QEvent::TouchUpdate:
|
||||
case QEvent::TouchEnd:
|
||||
#ifndef QT_NO_TABLETEVENT
|
||||
case QEvent::TabletMove:
|
||||
case QEvent::TabletPress:
|
||||
case QEvent::TabletRelease:
|
||||
#endif
|
||||
{
|
||||
QInputEvent *ie = static_cast<QInputEvent*>(e);
|
||||
QApplicationPrivate::modifier_buttons = ie->modifiers();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef QT_NO_GESTURES
|
||||
|
|
|
|||
|
|
@ -399,6 +399,9 @@ private slots:
|
|||
void styleSheetPropagation();
|
||||
|
||||
void destroyedSignal();
|
||||
|
||||
void keyboardModifiers();
|
||||
|
||||
private:
|
||||
bool ensureScreenSize(int width, int height);
|
||||
QWidget *testWidget;
|
||||
|
|
@ -10001,5 +10004,28 @@ void tst_QWidget::taskQTBUG_27643_enterEvents()
|
|||
}
|
||||
#endif // QTEST_NO_CURSOR
|
||||
|
||||
class KeyboardWidget : public QWidget
|
||||
{
|
||||
public:
|
||||
KeyboardWidget(QWidget* parent = 0) : QWidget(parent), m_eventCounter(0) {}
|
||||
virtual void mousePressEvent(QMouseEvent* ev) Q_DECL_OVERRIDE {
|
||||
m_modifiers = ev->modifiers();
|
||||
m_appModifiers = QApplication::keyboardModifiers();
|
||||
++m_eventCounter;
|
||||
}
|
||||
Qt::KeyboardModifiers m_modifiers;
|
||||
Qt::KeyboardModifiers m_appModifiers;
|
||||
int m_eventCounter;
|
||||
};
|
||||
|
||||
void tst_QWidget::keyboardModifiers()
|
||||
{
|
||||
KeyboardWidget* w = new KeyboardWidget;
|
||||
QTest::mouseClick(w, Qt::LeftButton, Qt::ControlModifier);
|
||||
QCOMPARE(w->m_eventCounter, 1);
|
||||
QCOMPARE(int(w->m_modifiers), int(Qt::ControlModifier));
|
||||
QCOMPARE(int(w->m_appModifiers), int(Qt::ControlModifier));
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QWidget)
|
||||
#include "tst_qwidget.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue