diff options
author | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-09-05 15:56:37 +0300 |
---|---|---|
committer | Lars Knoll <lars.knoll@nokia.com> | 2011-09-05 15:13:13 +0200 |
commit | 5e9f410eb67175b0f1abe95cabdb64dd30a6e7d7 (patch) | |
tree | a0b3de19307ec6d47429e611a34e993153fbdd6c | |
parent | a4e6b04419d5efa3b1165dc1e8437aac3d09fcb8 (diff) |
Add timestamp to QInputEvent.
The mouse, touch, key events have no timestamp field currently,
meaning that the timestamp passed to QWindowSystemInterface's
handleMouse, Touch, KeyEvent functions will not be stored in the
generated events. The timestamp can be quite valuable in some cases
(e.g. when performing filtering of touch events) so losing this
information is not desirable. The patch adds a timestamp field to
QInputEvent, which is the base for mouse, touch, key, and other
events, and also makes QGuiApplication to store the timestamp in the
generated events.
Change-Id: Icb9de8b238cb341916eac33ce21603f4955baca7
Reviewed-on: http://codereview.qt.nokia.com/4196
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
-rw-r--r-- | src/gui/kernel/qevent.cpp | 2 | ||||
-rw-r--r-- | src/gui/kernel/qevent.h | 3 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 5 | ||||
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 1 | ||||
-rw-r--r-- | src/widgets/kernel/qwidgetwindow_qpa.cpp | 2 |
5 files changed, 12 insertions, 1 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index bee4c4b686..8208f6e04a 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -68,7 +68,7 @@ QT_BEGIN_NAMESPACE \internal */ QInputEvent::QInputEvent(Type type, Qt::KeyboardModifiers modifiers) - : QEvent(type), modState(modifiers) + : QEvent(type), modState(modifiers), ts(0) {} /*! diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 93396d860b..6f180f6365 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -77,8 +77,11 @@ public: ~QInputEvent(); inline Qt::KeyboardModifiers modifiers() const { return modState; } inline void setModifiers(Qt::KeyboardModifiers amodifiers) { modState = amodifiers; } + inline ulong timestamp() const { return ts; } + inline void setTimestamp(ulong atimestamp) { ts = atimestamp; } protected: Qt::KeyboardModifiers modState; + ulong ts; }; class Q_GUI_EXPORT QMouseEvent : public QInputEvent diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 5fc7006a74..f045861191 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -591,6 +591,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo if (window) { QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, buttons, QGuiApplication::keyboardModifiers()); + ev.setTimestamp(e->timestamp); #ifndef QT_NO_CURSOR QList<QWeakPointer<QPlatformCursor> > cursors = QPlatformCursorPrivate::getInstances(); for (int i = 0; i < cursors.count(); ++i) @@ -618,6 +619,7 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh if (window) { QWheelEvent ev(e->localPos, e->globalPos, e->delta, buttons, QGuiApplication::keyboardModifiers(), e->orient); + ev.setTimestamp(e->timestamp); QGuiApplication::sendSpontaneousEvent(window, &ev); return; } @@ -638,9 +640,11 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE if (e->nativeScanCode || e->nativeVirtualKey || e->nativeModifiers) { QKeyEventEx ev(e->keyType, e->key, e->modifiers, e->unicode, e->repeat, e->repeatCount, e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers); + ev.setTimestamp(e->timestamp); QGuiApplication::sendSpontaneousEvent(target, &ev); } else { QKeyEvent ev(e->keyType, e->key, e->modifiers, e->unicode, e->repeat, e->repeatCount); + ev.setTimestamp(e->timestamp); QGuiApplication::sendSpontaneousEvent(target, &ev); } } @@ -843,6 +847,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To QGuiApplication::keyboardModifiers(), it.value().first, it.value().second); + touchEvent.setTimestamp(e->timestamp); for (int i = 0; i < touchEvent.touchPoints().count(); ++i) { QTouchEvent::TouchPoint &touchPoint = touchEvent._touchPoints[i]; diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index af49b658be..043b114c64 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3790,6 +3790,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) QMouseEvent me(mouse->type(), relpos, mouse->windowPos(), mouse->globalPos(), mouse->button(), mouse->buttons(), mouse->modifiers()); me.spont = mouse->spontaneous(); + me.setTimestamp(mouse->timestamp()); // throw away any mouse-tracking-only mouse events if (!w->hasMouseTracking() && mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) { diff --git a/src/widgets/kernel/qwidgetwindow_qpa.cpp b/src/widgets/kernel/qwidgetwindow_qpa.cpp index 4cd6b45989..42ecfd4e3d 100644 --- a/src/widgets/kernel/qwidgetwindow_qpa.cpp +++ b/src/widgets/kernel/qwidgetwindow_qpa.cpp @@ -189,6 +189,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) 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()); + e.setTimestamp(event->timestamp()); QApplicationPrivate::sendMouseEvent(receiver, &e, alien, m_widget, &qt_button_down, qt_last_mouse_receiver); } else { // close disabled popups when a mouse button is pressed or released @@ -254,6 +255,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) } QMouseEvent translated(event->type(), mapped, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers()); + translated.setTimestamp(event->timestamp()); QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget, &qt_button_down, qt_last_mouse_receiver); |