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>
This commit is contained in:
parent
a4e6b04419
commit
5e9f410eb6
@ -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)
|
||||
{}
|
||||
|
||||
/*!
|
||||
|
@ -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
|
||||
|
@ -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];
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user