From 4222603f8ea3a0d0ef5b9a190605ad86e00f27f6 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Sun, 27 Nov 2011 17:42:23 +0200 Subject: Extend touch events. The capability flags indicate which information is valid in the touch points. Previously there was no way to tell if e.g. the value returned by pressure() is actually the value provided by the driver/device or it is just something bogus due to pressure not being supported. The points' flags return information about the individual touch points. One use case is to differentiate between touches made by finger and pen. Velocity, if available, is now also exposed. Each touch point can now contain an additional list of "raw" positions. These points are not reported individually but are taken into account in some way by the underlying device and drivers to generate the final, "accurate" touch point. In case the underlying drivers expose these additional positions, they are made available in the lists returned by the touch points' rawScreenPosition(). The raw positions are only available in screen coordinates to prevent wasting time with mapping from global positions in applications that do not use this data. Instead, apps can query the QWindow to which the touch event was sent via QTouchEvent::window() and can call mapFromGlobal() manually if they need local raw positions. The capability and device type information is now held in a new QTouchDevice class. Each touch event will contain only a pointer to one of the global QTouchDevice instances. On top of type and capability, the new class also contains a name which can be used to differentiate between multiple touch input devices (i.e. to tell from which one a given QTouchEvent originates from). The introduction of QTouchDevice has three implications: The QTouchEvent constructor and QWindowSystemInterface::handleTouchEvent need to be changed (to pass a QTouchDevice pointer instead of merely a device type value), and each platform or generic plug-in is now responsible for registering one or more devices using the new API QWindowSystemInterface::registerTouchDevice. Change-Id: Ic1468d3e43933d8b5691d75aa67c43e1bc7ffe3e Reviewed-by: Lars Knoll --- dist/changes-5.0.0 | 29 +++ src/gui/kernel/kernel.pri | 7 +- src/gui/kernel/qevent.cpp | 127 ++++++++++-- src/gui/kernel/qevent.h | 29 ++- src/gui/kernel/qevent_p.h | 3 + src/gui/kernel/qguiapplication.cpp | 8 +- src/gui/kernel/qtouchdevice.cpp | 224 +++++++++++++++++++++ src/gui/kernel/qtouchdevice.h | 96 +++++++++ src/gui/kernel/qtouchdevice_p.h | 74 +++++++ src/gui/kernel/qwindowsysteminterface_qpa.cpp | 24 ++- src/gui/kernel/qwindowsysteminterface_qpa.h | 13 +- src/gui/kernel/qwindowsysteminterface_qpa_p.h | 8 +- .../generic/touchscreen/qtoucheventsenderqpa.cpp | 6 +- .../generic/touchscreen/qtoucheventsenderqpa.h | 3 + src/plugins/platforms/cocoa/qnsview.mm | 16 +- .../platforms/windows/qwindowsmousehandler.cpp | 12 +- .../platforms/windows/qwindowsmousehandler.h | 2 + src/plugins/platforms/xcb/qxcbconnection_maemo.cpp | 15 +- src/testlib/qtesttouch.h | 32 +-- src/widgets/graphicsview/qgraphicsscene.cpp | 8 +- src/widgets/kernel/qapplication.cpp | 13 +- src/widgets/kernel/qapplication_p.h | 8 +- src/widgets/kernel/qwidget.cpp | 2 +- src/widgets/kernel/qwidgetwindow_qpa.cpp | 2 +- src/widgets/util/qflickgesture.cpp | 2 +- .../gui/kernel/qtouchevent/tst_qtouchevent.cpp | 106 ++++++---- tests/auto/other/gestures/tst_gestures.cpp | 5 +- .../qgraphicsitem/tst_qgraphicsitem.cpp | 5 +- .../kernel/qapplication/tst_qapplication.cpp | 44 ++-- .../auto/widgets/util/qscroller/tst_qscroller.cpp | 18 +- 30 files changed, 793 insertions(+), 148 deletions(-) create mode 100644 src/gui/kernel/qtouchdevice.cpp create mode 100644 src/gui/kernel/qtouchdevice.h create mode 100644 src/gui/kernel/qtouchdevice_p.h diff --git a/dist/changes-5.0.0 b/dist/changes-5.0.0 index 89c6fbef0d..cec264337f 100644 --- a/dist/changes-5.0.0 +++ b/dist/changes-5.0.0 @@ -90,6 +90,32 @@ information about a particular change. - QSound has been moved from QtGui to QtMultimedia +- QTouchEvent: + + * The DeviceType enum and deviceType() have been deprecated due to + the introduction of QTouchDevice. + + * The signature of the constructor has changed. It now takes a + QTouchDevice pointer instead of just a DeviceType value. + + * TouchPointState no longer includes TouchPointStateMask and + TouchPointPrimary. The primary flag is now stored together with + other touch point flags and is accessible through + TouchPoint::isPrimary() or TouchPoint::flags(). As a result the + internally used state mask is no longer necessary. + + * QWidget *widget() has been removed and is replaced by QObject + *target() in order to avoid QWidget dependencies. + +- QWindowSystemInterface: + + * The signature of all handleTouchEvent() variants have changed, + taking a QTouchDevice* instead of just a DeviceType value. + Platform or generic plug-ins have to create and register at least + one QTouchDevice before sending the first touch event. + + * The event type parameter is removed from handleTouchEvent(). + **************************************************************************** * General * **************************************************************************** @@ -127,6 +153,9 @@ QtGui proper parent/child functions instead of using navigate which has been deprecated for this purpose. Table and cell interfaces have been added to qaccessible2.h +* Touch events and points have been extended to hold additional + information like capability flags, point-specific flags, velocity, + and raw positions. QtWidgets --------- diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index c6f6cab5da..57ed3a983a 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -50,7 +50,9 @@ HEADERS += \ kernel/qsessionmanager.h \ kernel/qwindowdefs.h \ kernel/qscreen.h \ - kernel/qstylehints.h + kernel/qstylehints.h \ + kernel/qtouchdevice.h \ + kernel/qtouchdevice_p.h SOURCES += \ kernel/qclipboard_qpa.cpp \ @@ -91,6 +93,7 @@ SOURCES += \ kernel/qguivariant.cpp \ kernel/qscreen.cpp \ kernel/qshortcutmap.cpp \ - kernel/qstylehints.cpp + kernel/qstylehints.cpp \ + kernel/qtouchdevice.cpp win32:HEADERS+=kernel/qwindowdefs_win.h diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 0d26268030..035f1b2666 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3450,34 +3450,25 @@ QWindowStateChangeEvent::~QWindowStateChangeEvent() This enum represents the type of device that generated a QTouchEvent. - \value TouchScreen In this type of device, the touch surface and display are integrated. This - means the surface and display typically have the same size, such that there - is a direct relationship between the touch points' physical positions and the - coordinate reported by QTouchEvent::TouchPoint. As a result, Qt allows the - user to interact directly with multiple QWidgets and QGraphicsItems at the - same time. + This enum has been deprecated. Use QTouchDevice::DeviceType instead. - \value TouchPad In this type of device, the touch surface is separate from the display. There - is not a direct relationship between the physical touch location and the - on-screen coordinates. Instead, they are calculated relative to the current - mouse position, and the user must use the touch-pad to move this reference - point. Unlike touch-screens, Qt allows users to only interact with a single - QWidget or QGraphicsItem at a time. + \sa QTouchDevice::DeviceType, QTouchDevice::type(), QTouchEvent::device() */ /*! - Constructs a QTouchEvent with the given \a eventType, \a deviceType, and \a touchPoints. - The \a touchPointStates and \a modifiers are the current touch point states and keyboard - modifiers at the time of the event. + Constructs a QTouchEvent with the given \a eventType, \a deviceType, \a + touchPoints and \a device. The \a touchPointStates and \a modifiers + are the current touch point states and keyboard modifiers at the time of + the event. */ QTouchEvent::QTouchEvent(QEvent::Type eventType, - QTouchEvent::DeviceType deviceType, + QTouchDevice *device, Qt::KeyboardModifiers modifiers, Qt::TouchPointStates touchPointStates, const QList &touchPoints) : QInputEvent(eventType, modifiers), _widget(0), - _deviceType(deviceType), + _device(device), _touchPointStates(touchPointStates), _touchPoints(touchPoints) { } @@ -3493,6 +3484,22 @@ QTouchEvent::~QTouchEvent() Returns the widget on which the event occurred. */ +/*! \fn QWindow *QTouchEvent::window() const + + Returns the window on which the event occurred. Useful for doing + global-local mapping on data like rawScreenPositions() which, + for performance reasons, only stores the global positions in the + touch event. +*/ + +/*! \fn QTouchEvent::DeviceType QTouchEvent::deviceType() const + + Returns the touch device Type, which is of type \l {QTouchEvent::DeviceType} {DeviceType}. + + This function has been deprecated. Use QTouchDevice::type() instead. + + \sa QTouchDevice::type(), QTouchEvent::device() +*/ /*! \fn Qt::TouchPointStates QTouchEvent::touchPointStates() const @@ -3509,6 +3516,11 @@ QTouchEvent::~QTouchEvent() Returns the touch device Type, which is of type \l {QTouchEvent::DeviceType} {DeviceType}. */ +/*! \fn QTouchDevice* QTouchEvent::device() const + + Returns the touch device from which this touch event originates. +*/ + /*! \fn void QTouchEvent::setWidget(QWidget *widget) \internal @@ -3516,6 +3528,13 @@ QTouchEvent::~QTouchEvent() Sets the widget for this event. */ +/*! \fn void QTouchEvent::setWindow(QWindow *window) + + \internal + + Sets the window for this event. +*/ + /*! \fn void QTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPointStates) \internal @@ -3538,11 +3557,25 @@ QTouchEvent::~QTouchEvent() {DeviceType}. */ +/*! \fn void QTouchEvent::setTouchDevice(QTouchDevice *device) + + \internal + + Sets the touch event's device to the given one. +*/ + /*! \class QTouchEvent::TouchPoint \brief The TouchPoint class provides information about a touch point in a QTouchEvent. \since 4.6 */ +/*! \enum QTouchEvent::TouchPoint::InfoFlags + + The values of this enum describe additional information about a touch point. + + \value Pen Indicates that the contact has been made by a designated pointing device (e.g. a pen) instead of a finger. +*/ + /*! \internal Constructs a QTouchEvent::TouchPoint for use in a QTouchEvent. @@ -3795,6 +3828,42 @@ qreal QTouchEvent::TouchPoint::pressure() const return d->pressure; } +/*! + Returns a velocity vector for this touch point. + The vector is in the screen's coordinate system, using pixels per seconds for the magnitude. + + \note The returned vector is only valid if the touch device's capabilities include QTouchDevice::Velocity. + + \sa QTouchDevice::capabilities(), device() +*/ +QVector2D QTouchEvent::TouchPoint::velocity() const +{ + return d->velocity; +} + +/*! + Returns additional information about the touch point. + + \sa QTouchEvent::TouchPoint::InfoFlags + */ +QTouchEvent::TouchPoint::InfoFlags QTouchEvent::TouchPoint::flags() const +{ + return d->flags; +} + +/*! + Returns the raw, unfiltered positions for the touch point. The positions are in screen coordinates. + To get local coordinates you can use mapFromGlobal() of the QWindow returned by QTouchEvent::window(). + + \note Returns an empty list if the touch device's capabilities do not include QTouchDevice::RawPositions. + + \sa QTouchDevice::capabilities(), device(), window() + */ +QList QTouchEvent::TouchPoint::rawScreenPositions() const +{ + return d->rawScreenPositions; +} + /*! \internal */ void QTouchEvent::TouchPoint::setId(int id) { @@ -3939,6 +4008,30 @@ void QTouchEvent::TouchPoint::setPressure(qreal pressure) d->pressure = pressure; } +/*! \internal */ +void QTouchEvent::TouchPoint::setVelocity(const QVector2D &v) +{ + if (d->ref.load() != 1) + d = d->detach(); + d->velocity = v; +} + +/*! \internal */ +void QTouchEvent::TouchPoint::setRawScreenPositions(const QList &positions) +{ + if (d->ref.load() != 1) + d = d->detach(); + d->rawScreenPositions = positions; +} + +/* \internal */ +void QTouchEvent::TouchPoint::setFlags(InfoFlags flags) +{ + if (d->ref.load() != 1) + d = d->detach(); + d->flags = flags; +} + /*! \internal */ QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::TouchPoint &other) { diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index a79a56b771..6a0442509c 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -54,7 +54,8 @@ #include #include #include - +#include +#include QT_BEGIN_HEADER @@ -692,6 +693,11 @@ public: class Q_GUI_EXPORT TouchPoint { public: + enum InfoFlag { + Pen = 0x0001 + }; + Q_DECLARE_FLAGS(InfoFlags, InfoFlag) + TouchPoint(int id = -1); TouchPoint(const QTouchEvent::TouchPoint &other); ~TouchPoint(); @@ -722,6 +728,9 @@ public: QRectF screenRect() const; qreal pressure() const; + QVector2D velocity() const; + InfoFlags flags() const; + QList rawScreenPositions() const; // internal void setId(int id); @@ -742,6 +751,9 @@ public: void setSceneRect(const QRectF &sceneRect); void setScreenRect(const QRectF &screenRect); void setPressure(qreal pressure); + void setVelocity(const QVector2D &v); + void setFlags(InfoFlags flags); + void setRawScreenPositions(const QList &positions); QTouchEvent::TouchPoint &operator=(const QTouchEvent::TouchPoint &other); private: @@ -752,32 +764,36 @@ public: friend class QApplicationPrivate; }; - enum DeviceType { + QT_DEPRECATED enum DeviceType { TouchScreen, TouchPad }; QTouchEvent(QEvent::Type eventType, - QTouchEvent::DeviceType deviceType = TouchScreen, + QTouchDevice *device = 0, Qt::KeyboardModifiers modifiers = Qt::NoModifier, Qt::TouchPointStates touchPointStates = 0, const QList &touchPoints = QList()); ~QTouchEvent(); inline QWidget *widget() const { return _widget; } - inline QTouchEvent::DeviceType deviceType() const { return _deviceType; } + inline QWindow *window() const { return _window; } + QT_DEPRECATED inline QTouchEvent::DeviceType deviceType() const { return static_cast(int(_device->type())); } inline Qt::TouchPointStates touchPointStates() const { return _touchPointStates; } inline const QList &touchPoints() const { return _touchPoints; } + inline QTouchDevice *device() const { return _device; } // internal inline void setWidget(QWidget *awidget) { _widget = awidget; } - inline void setDeviceType(DeviceType adeviceType) { _deviceType = adeviceType; } + inline void setWindow(QWindow *awindow) { _window = awindow; } inline void setTouchPointStates(Qt::TouchPointStates aTouchPointStates) { _touchPointStates = aTouchPointStates; } inline void setTouchPoints(const QList &atouchPoints) { _touchPoints = atouchPoints; } + inline void setDevice(QTouchDevice *device) { _device = device; } protected: QWidget *_widget; - QTouchEvent::DeviceType _deviceType; + QWindow *_window; + QTouchDevice *_device; Qt::TouchPointStates _touchPointStates; QList _touchPoints; @@ -787,6 +803,7 @@ protected: friend class QApplicationPrivate; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QTouchEvent::TouchPoint::InfoFlags) class QScrollPrepareEventPrivate; class Q_GUI_EXPORT QScrollPrepareEvent : public QEvent diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index fa6b675c86..1eee92d176 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -105,6 +105,9 @@ public: startPos, startScenePos, startScreenPos, startNormalizedPos, lastPos, lastScenePos, lastScreenPos, lastNormalizedPos; qreal pressure; + QVector2D velocity; + QTouchEvent::TouchPoint::InfoFlags flags; + QList rawScreenPositions; }; class QFileOpenEventPrivate diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index da981b577b..6d5e210e82 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -841,7 +841,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To QTouchEvent::TouchPoint previousTouchPoint; switch (touchPoint.state()) { case Qt::TouchPointPressed: - if (e->devType == QTouchEvent::TouchPad) { + if (e->device->type() == QTouchDevice::TouchPad) { // on touch-pads, send all touch points to the same widget w = d->windowForTouchPointId.isEmpty() ? QWeakPointer() @@ -944,13 +944,15 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To } QTouchEvent touchEvent(eventType, - e->devType, + e->device, e->modifiers, it.value().first, it.value().second); touchEvent.setTimestamp(e->timestamp); + touchEvent.setWindow(w); - for (int i = 0; i < touchEvent.touchPoints().count(); ++i) { + const int pointCount = touchEvent.touchPoints().count(); + for (int i = 0; i < pointCount; ++i) { QTouchEvent::TouchPoint &touchPoint = touchEvent._touchPoints[i]; // preserve the sub-pixel resolution diff --git a/src/gui/kernel/qtouchdevice.cpp b/src/gui/kernel/qtouchdevice.cpp new file mode 100644 index 0000000000..abf1acc310 --- /dev/null +++ b/src/gui/kernel/qtouchdevice.cpp @@ -0,0 +1,224 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtouchdevice.h" +#include "qtouchdevice_p.h" +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \class QTouchDevice + \brief The QTouchDevice class describes the device from with touch events originate. + \since 5.0 + \ingroup touch + + Each QTouchEvent contains a QTouchDevice pointer to allow accessing + device-specific properties like type and capabilities. It is the + responsibility of the platform or generic plug-ins to register the + available touch devices via QWindowSystemInterface before generating any + touch events. Applications do not need to instantiate this class, they + should just access the global instances pointed to by QTouchEvent::device(). +*/ + +/*! \enum QTouchDevice::DeviceType + + This enum represents the type of device that generated a QTouchEvent. + + \value TouchScreen In this type of device, the touch surface and display are integrated. This + means the surface and display typically have the same size, such that there + is a direct relationship between the touch points' physical positions and the + coordinate reported by QTouchEvent::TouchPoint. As a result, Qt allows the + user to interact directly with multiple QWidgets and QGraphicsItems at the + same time. + + \value TouchPad In this type of device, the touch surface is separate from the display. There + is not a direct relationship between the physical touch location and the + on-screen coordinates. Instead, they are calculated relative to the current + mouse position, and the user must use the touch-pad to move this reference + point. Unlike touch-screens, Qt allows users to only interact with a single + QWidget or QGraphicsItem at a time. +*/ + +/*! \enum QTouchDevice::CapabilityFlag + + This enum is used with QTouchDevice::capabilities() to indicate what kind of information the + touch device or its driver can provide. + + \value Position Indicates that position information is available, meaning + that the pos() family of functions in the touch points return valid points. + + \value Area Indicates that touch area information is available, meaning that the rect() family + of functions in the touch points return valid rectangles. + + \value Pressure Indicates that pressure information is available, meaning that pressure() + returns a valid value. + + \value Velocity Indicates that velocity information is available, meaning that velocity() + returns a valid vector. + + \value RawPositions Indicates that the list returned by QTouchEvent::TouchPoint::rawScreenPositions() + may contain one or more positions for each touch point. This is relevant when + the touch input gets filtered or corrected on driver level. + + \value NormalizedPosition Indicates that the normalized position is available, meaning that normalizedPos() + returns a valid value. +*/ + +/*! + Creates a new touch device instance. + By default the name is empty, the only capability is Position and type is TouchScreen. + */ +QTouchDevice::QTouchDevice() + : d(new QTouchDevicePrivate) +{ +} + +QTouchDevice::~QTouchDevice() +{ + delete d; +} + +/*! + Returns the touch device type. +*/ +QTouchDevice::DeviceType QTouchDevice::type() const +{ + return d->type; +} + +/*! + Returns the touch device capabilities. + */ +QTouchDevice::Capabilities QTouchDevice::capabilities() const +{ + return d->caps; +} + +/*! + Returns the touch device name. + + This string may often be empty. It is however useful for systems that have + more than one touch input device because there it can be used to + differentiate between the devices (i.e. to tell from which device a + QTouchEvent originates from). +*/ +QString QTouchDevice::name() const +{ + return d->name; +} + +/*! + Sets the device type. + */ +void QTouchDevice::setType(DeviceType devType) +{ + d->type = devType; +} + +/*! + Sets the capabilities supported by the device and its driver. + */ +void QTouchDevice::setCapabilities(Capabilities caps) +{ + d->caps = caps; +} + +/*! + Sets the name (a unique identifier) for the device. In most systems it is + enough to leave this unset and keep the default empty name. This identifier + becomes important when having multiple touch devices and a need to + differentiate between them. + */ +void QTouchDevice::setName(const QString &name) +{ + d->name = name; +} + +typedef QList TouchDevices; +Q_GLOBAL_STATIC(TouchDevices, deviceList) +Q_GLOBAL_STATIC(QMutex, devicesMutex) + +static void cleanupDevicesList() +{ + QMutexLocker lock(devicesMutex()); + qDeleteAll(*deviceList()); + deviceList()->clear(); +} + +/*! + Returns a list of all registered devices. + + \note The returned list cannot be used to add new devices. Use QWindowSystemInterface::registerTouchDevice() instead. + */ +QList QTouchDevice::devices() +{ + QMutexLocker lock(devicesMutex()); + QList *devList = deviceList(); + QList constDevList; + for (int i = 0, count = devList->count(); i != count; ++i) + constDevList.append(devList->at(i)); + return constDevList; +} + +/*! + \internal + */ +bool QTouchDevicePrivate::isRegistered(QTouchDevice *dev) +{ + QMutexLocker lock(devicesMutex()); + return deviceList()->contains(dev); +} + +/*! + \internal + */ +void QTouchDevicePrivate::registerDevice(QTouchDevice *dev) +{ + QMutexLocker lock(devicesMutex()); + if (deviceList()->isEmpty()) + qAddPostRoutine(cleanupDevicesList); + deviceList()->append(dev); +} + +QT_END_NAMESPACE diff --git a/src/gui/kernel/qtouchdevice.h b/src/gui/kernel/qtouchdevice.h new file mode 100644 index 0000000000..496bb7a522 --- /dev/null +++ b/src/gui/kernel/qtouchdevice.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTOUCHDEVICE_H +#define QTOUCHDEVICE_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QTouchDevicePrivate; + +class Q_GUI_EXPORT QTouchDevice +{ +public: + enum DeviceType { + TouchScreen, + TouchPad + }; + + enum CapabilityFlag { + Position = 0x0001, + Area = 0x0002, + Pressure = 0x0004, + Velocity = 0x0008, + RawPositions = 0x0010, + NormalizedPosition = 0x0020 + }; + Q_DECLARE_FLAGS(Capabilities, CapabilityFlag) + + QTouchDevice(); + ~QTouchDevice(); + + static QList devices(); + + QString name() const; + DeviceType type() const; + Capabilities capabilities() const; + + void setName(const QString &name); + void setType(DeviceType devType); + void setCapabilities(Capabilities caps); + +private: + QTouchDevicePrivate *d; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(QTouchDevice::Capabilities) + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QTOUCHDEVICE_H diff --git a/src/gui/kernel/qtouchdevice_p.h b/src/gui/kernel/qtouchdevice_p.h new file mode 100644 index 0000000000..f782d1585d --- /dev/null +++ b/src/gui/kernel/qtouchdevice_p.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTOUCHDEVICE_P_H +#define QTOUCHDEVICE_P_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QTouchDevicePrivate +{ +public: + QTouchDevicePrivate() + : type(QTouchDevice::TouchScreen), + caps(QTouchDevice::Position) + { } + + QTouchDevice::DeviceType type; + QTouchDevice::Capabilities caps; + QString name; + + static void registerDevice(QTouchDevice *dev); + static bool isRegistered(QTouchDevice *dev); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QTOUCHDEVICE_P_H diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp index 979a168c05..016446780b 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp +++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp @@ -41,6 +41,7 @@ #include "qwindowsysteminterface_qpa.h" #include "qwindowsysteminterface_qpa_p.h" #include "private/qguiapplication_p.h" +#include "private/qtouchdevice_p.h" #include #include @@ -213,16 +214,28 @@ void QWindowSystemInterfacePrivate::queueWindowSystemEvent(QWindowSystemInterfac dispatcher->wakeUp(); } -void QWindowSystemInterface::handleTouchEvent(QWindow *w, QEvent::Type type, QTouchEvent::DeviceType devType, const QList &points, Qt::KeyboardModifiers mods) { +void QWindowSystemInterface::registerTouchDevice(QTouchDevice *device) +{ + QTouchDevicePrivate::registerDevice(device); +} + +void QWindowSystemInterface::handleTouchEvent(QWindow *w, QEvent::Type type, QTouchDevice *device, + const QList &points, Qt::KeyboardModifiers mods) +{ unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - handleTouchEvent(w, time, type, devType, points, mods); + handleTouchEvent(w, time, type, device, points, mods); } -void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QEvent::Type type, QTouchEvent::DeviceType devType, const QList &points, Qt::KeyboardModifiers mods) +void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QEvent::Type type, + QTouchDevice *device, + const QList &points, Qt::KeyboardModifiers mods) { if (!points.size()) // Touch events must have at least one point return; + if (!QTouchDevicePrivate::isRegistered(device)) // Disallow passing bogus, non-registered devices. + return; + QList touchPoints; Qt::TouchPointStates states; QTouchEvent::TouchPoint p; @@ -247,13 +260,16 @@ void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QEv // when the event gets processed by QGuiApplication. p.setNormalizedPos(point->normalPosition); + p.setVelocity(point->velocity); + p.setFlags(point->flags); + p.setRawScreenPositions(point->rawPositions); touchPoints.append(p); ++point; } QWindowSystemInterfacePrivate::TouchEvent *e = - new QWindowSystemInterfacePrivate::TouchEvent(tlw, timestamp, type, devType, touchPoints, mods); + new QWindowSystemInterfacePrivate::TouchEvent(tlw, timestamp, type, device, touchPoints, mods); QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); } diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.h b/src/gui/kernel/qwindowsysteminterface_qpa.h index d00f0af37c..423281955c 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa.h @@ -51,12 +51,14 @@ #include #include #include +#include QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QMimeData; +class QTouchDevice; QT_MODULE(Gui) @@ -84,16 +86,23 @@ public: static void handleWheelEvent(QWindow *w, ulong timestamp, const QPointF & local, const QPointF & global, int d, Qt::Orientation o, Qt::KeyboardModifiers mods = Qt::NoModifier); struct TouchPoint { + TouchPoint() : id(0), isPrimary(false), pressure(0), state(Qt::TouchPointStationary), flags(0) { } int id; // for application use bool isPrimary; // for application use QPointF normalPosition; // touch device coordinates, (0 to 1, 0 to 1) QRectF area; // the touched area, centered at position in screen coordinates qreal pressure; // 0 to 1 Qt::TouchPointState state; //Qt::TouchPoint{Pressed|Moved|Stationary|Released} + QVector2D velocity; // in screen coordinate system, pixels / seconds + QTouchEvent::TouchPoint::InfoFlags flags; + QList rawPositions; // in screen coordinates }; - static void handleTouchEvent(QWindow *w, QEvent::Type type, QTouchEvent::DeviceType devType, const QList &points, Qt::KeyboardModifiers mods = Qt::NoModifier); - static void handleTouchEvent(QWindow *w, ulong timestamp, QEvent::Type type, QTouchEvent::DeviceType devType, const QList &points, Qt::KeyboardModifiers mods = Qt::NoModifier); + static void registerTouchDevice(QTouchDevice *device); + static void handleTouchEvent(QWindow *w, QEvent::Type type, QTouchDevice *device, + const QList &points, Qt::KeyboardModifiers mods = Qt::NoModifier); + static void handleTouchEvent(QWindow *w, ulong timestamp, QEvent::Type type, QTouchDevice *device, + const QList &points, Qt::KeyboardModifiers mods = Qt::NoModifier); static void handleGeometryChange(QWindow *w, const QRect &newRect); static void handleSynchronousGeometryChange(QWindow *w, const QRect &newRect); diff --git a/src/gui/kernel/qwindowsysteminterface_qpa_p.h b/src/gui/kernel/qwindowsysteminterface_qpa_p.h index 7d5455c06b..5580104c3b 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa_p.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa_p.h @@ -187,12 +187,12 @@ public: class TouchEvent : public InputEvent { public: - TouchEvent(QWindow *w, ulong time, QEvent::Type t, QTouchEvent::DeviceType d, const QList &p, Qt::KeyboardModifiers mods) - :InputEvent(w, time, Touch, mods), devType(d), points(p), touchType(t) { } - QTouchEvent::DeviceType devType; + TouchEvent(QWindow *w, ulong time, QEvent::Type t, QTouchDevice *dev, + const QList &p, Qt::KeyboardModifiers mods) + :InputEvent(w, time, Touch, mods), device(dev), points(p), touchType(t) { } + QTouchDevice *device; QList points; QEvent::Type touchType; - }; class ScreenOrientationEvent : public WindowSystemEvent { diff --git a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp index d9ec92cda7..08db058e10 100644 --- a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp +++ b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp @@ -52,6 +52,10 @@ QT_BEGIN_NAMESPACE QTouchEventSenderQPA::QTouchEventSenderQPA(const QString &spec) { m_forceToActiveWindow = spec.split(QLatin1Char(':')).contains(QLatin1String("force_window")); + m_device = new QTouchDevice; + m_device->setType(QTouchDevice::TouchScreen); + m_device->setCapabilities(QTouchDevice::Position | QTouchDevice::Area); + QWindowSystemInterface::registerTouchDevice(m_device); } void QTouchEventSenderQPA::touch_configure(int x_min, int x_max, int y_min, int y_max) @@ -103,7 +107,7 @@ void QTouchEventSenderQPA::touch_point(QEvent::Type state, #endif } - QWindowSystemInterface::handleTouchEvent(0, state, QTouchEvent::TouchScreen, touchPoints); + QWindowSystemInterface::handleTouchEvent(0, state, m_device, touchPoints); } QT_END_NAMESPACE diff --git a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h index 91a6b4f3bb..b6e1613b24 100644 --- a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h +++ b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h @@ -48,6 +48,8 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE +class QTouchDevice; + class QTouchEventSenderQPA : public QTouchScreenObserver { public: @@ -61,6 +63,7 @@ private: int hw_range_x_max; int hw_range_y_min; int hw_range_y_max; + QTouchDevice *m_device; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 7c9873a908..4ae268dda5 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -54,6 +54,8 @@ #include #endif +static QTouchDevice *touchDevice = 0; + @interface NSEvent (Qt_Compile_Leopard_DeviceDelta) - (CGFloat)deviceDeltaX; - (CGFloat)deviceDeltaY; @@ -69,6 +71,12 @@ m_cgImage = 0; m_window = 0; m_buttons = Qt::NoButton; + if (!touchDevice) { + touchDevice = new QTouchDevice; + touchDevice->setType(QTouchDevice::TouchPad); + touchDevice->setCapabilities(QTouchDevice::Position | QTouchDevice::NormalizedPosition); + QWindowSystemInterface::registerTouchDevice(touchDevice); + } } return self; } @@ -287,28 +295,28 @@ { const NSTimeInterval timestamp = [event timestamp]; const QList points = QCocoaTouch::getCurrentTouchPointList(event, /*acceptSingleTouch= ### true or false?*/false); - QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchBegin, QTouchEvent::TouchPad, points); + QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchBegin, touchDevice, points); } - (void)touchesMovedWithEvent:(NSEvent *)event { const NSTimeInterval timestamp = [event timestamp]; const QList points = QCocoaTouch::getCurrentTouchPointList(event, /*acceptSingleTouch= ### true or false?*/false); - QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchUpdate, QTouchEvent::TouchPad, points); + QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchUpdate, touchDevice, points); } - (void)touchesEndedWithEvent:(NSEvent *)event { const NSTimeInterval timestamp = [event timestamp]; const QList points = QCocoaTouch::getCurrentTouchPointList(event, /*acceptSingleTouch= ### true or false?*/false); - QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchEnd, QTouchEvent::TouchPad, points); + QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchEnd, touchDevice, points); } - (void)touchesCancelledWithEvent:(NSEvent *)event { const NSTimeInterval timestamp = [event timestamp]; const QList points = QCocoaTouch::getCurrentTouchPointList(event, /*acceptSingleTouch= ### true or false?*/false); - QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchEnd, QTouchEvent::TouchPad, points); + QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchEnd, touchDevice, points); } #ifndef QT_NO_WHEELEVENT diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index 3ac4b24f1e..a2b6aa8d68 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -124,7 +124,8 @@ static inline void compressMouseMove(MSG *msg) */ QWindowsMouseHandler::QWindowsMouseHandler() : - m_windowUnderMouse(0) + m_windowUnderMouse(0), + m_touchDevice(0) { } @@ -277,10 +278,17 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND, if ((allStates & Qt::TouchPointStateMask) == Qt::TouchPointReleased) m_touchInputIDToTouchPointID.clear(); + if (!m_touchDevice) { + m_touchDevice = new QTouchDevice; + m_touchDevice->setType(QTouchDevice::TouchScreen); + m_touchDevice->setCapabilities(QTouchDevice::Position | QTouchDevice::Area | QTouchDevice::NormalizedPosition); + QWindowSystemInterface::registerTouchDevice(m_touchDevice); + } + // TODO: Device used to be hardcoded to screen in previous code. // What is the correct event type? Which parts of translateRawTouchEvent() are required? QWindowSystemInterface::handleTouchEvent(window, QEvent::TouchBegin, - QTouchEvent::TouchScreen, + m_touchDevice, touchPoints); return true; } diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.h b/src/plugins/platforms/windows/qwindowsmousehandler.h index 8d62becb74..178936e2ec 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.h +++ b/src/plugins/platforms/windows/qwindowsmousehandler.h @@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE class QWindow; +class QTouchDevice; class QWindowsMouseHandler { @@ -76,6 +77,7 @@ private: QPointer m_windowUnderMouse; QHash m_touchInputIDToTouchPointID; + QTouchDevice *m_touchDevice; }; Qt::MouseButtons QWindowsMouseHandler::keyStateToMouseButtons(int wParam) diff --git a/src/plugins/platforms/xcb/qxcbconnection_maemo.cpp b/src/plugins/platforms/xcb/qxcbconnection_maemo.cpp index 327f7c54f6..719fc85ae2 100644 --- a/src/plugins/platforms/xcb/qxcbconnection_maemo.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection_maemo.cpp @@ -62,6 +62,7 @@ struct XInput2Data { , xideviceinfo(0) , xibuttonclassinfo(0) , xiMaxContacts(0) + , qtTouchDevice(0) { } // true if Qt is compiled w/ XInput2 or Tablet support and we have a tablet. @@ -74,6 +75,7 @@ struct XInput2Data { XIButtonClassInfo *xibuttonclassinfo; int xiMaxContacts; QList allTouchPoints; + QTouchDevice *qtTouchDevice; }; bool QXcbConnection::isUsingXInput2() @@ -277,8 +279,17 @@ void QXcbConnection::handleGenericEvent(xcb_ge_event_t *event) if (!(active & (1 << i)) && touchPoints.at(i).state != Qt::TouchPointReleased) touchPoints[i].state = Qt::TouchPointReleased; - if (QXcbWindow *platformWindow = platformWindowFromId(xideviceevent->event)) - QWindowSystemInterface::handleTouchEvent(platformWindow->window(), xideviceevent->time, (QEvent::Type)0 /*None*/, QTouchEvent::TouchScreen, touchPoints); + if (QXcbWindow *platformWindow = platformWindowFromId(xideviceevent->event)) { + QTouchDevice *dev = m_xinputData->qtTouchDevice; + if (!dev) { + dev = new QTouchDevice; + dev->setType(QTouchDevice::TouchScreen); + dev->setCapabilities(QTouchDevice::Position | QTouchDevice::Area | QTouchDevice::Pressure | QTouchDevice::NormalizedPosition); + QWindowSystemInterface::registerTouchDevice(dev); + m_xinputData->qtTouchDevice = dev; + } + QWindowSystemInterface::handleTouchEvent(platformWindow->window(), xideviceevent->time, (QEvent::Type)0 /*None*/, dev, touchPoints); + } if (xideviceevent->evtype == XI_ButtonRelease) { // final event, forget touch state diff --git a/src/testlib/qtesttouch.h b/src/testlib/qtesttouch.h index bee1566d22..6a9909b617 100644 --- a/src/testlib/qtesttouch.h +++ b/src/testlib/qtesttouch.h @@ -64,7 +64,7 @@ QT_MODULE(Test) #ifdef QT_WIDGETS_LIB extern Q_GUI_EXPORT void qt_translateRawTouchEvent(QWidget *window, - QTouchEvent::DeviceType deviceType, + QTouchDevice *device, const QList &touchPoints, ulong timestamp); #endif @@ -136,13 +136,13 @@ namespace QTest if (!points.isEmpty()) { if (targetWindow) { - QWindowSystemInterface::handleTouchEvent(targetWindow,QEvent::None,deviceType, touchPointList(points.values())); + QWindowSystemInterface::handleTouchEvent(targetWindow,QEvent::None, device, touchPointList(points.values())); QTest::qWait(10); } #ifdef QT_WIDGETS_LIB else if (targetWidget) { - qt_translateRawTouchEvent(targetWidget, deviceType, points.values(), 0); + qt_translateRawTouchEvent(targetWidget, device, points.values(), 0); } #endif } @@ -152,17 +152,17 @@ namespace QTest private: #ifdef QT_WIDGETS_LIB - QTouchEventSequence(QWidget *widget, QTouchEvent::DeviceType aDeviceType) - : targetWidget(widget), targetWindow(0), deviceType(aDeviceType) + QTouchEventSequence(QWidget *widget, QTouchDevice *aDevice) + : targetWidget(widget), targetWindow(0), device(aDevice) { } #endif - QTouchEventSequence(QWindow *window, QTouchEvent::DeviceType aDeviceType) + QTouchEventSequence(QWindow *window, QTouchDevice *aDevice) : #ifdef QT_WIDGETS_LIB targetWidget(0), #endif - targetWindow(window), deviceType(aDeviceType) + targetWindow(window), device(aDevice) { } @@ -226,26 +226,26 @@ namespace QTest QWidget *targetWidget; #endif QWindow *targetWindow; - QTouchEvent::DeviceType deviceType; + QTouchDevice *device; #ifdef QT_WIDGETS_LIB - friend QTouchEventSequence touchEvent(QWidget *, QTouchEvent::DeviceType); + friend QTouchEventSequence touchEvent(QWidget *, QTouchDevice*); #endif - friend QTouchEventSequence touchEvent(QWindow *, QTouchEvent::DeviceType); + friend QTouchEventSequence touchEvent(QWindow *, QTouchDevice*); }; #ifdef QT_WIDGETS_LIB inline - QTouchEventSequence touchEvent(QWidget *widget = 0, - QTouchEvent::DeviceType deviceType = QTouchEvent::TouchScreen) + QTouchEventSequence touchEvent(QWidget *widget, + QTouchDevice *device) { - return QTouchEventSequence(widget, deviceType); + return QTouchEventSequence(widget, device); } #endif inline - QTouchEventSequence touchEvent(QWindow *window = 0, - QTouchEvent::DeviceType deviceType = QTouchEvent::TouchScreen) + QTouchEventSequence touchEvent(QWindow *window, + QTouchDevice *device) { - return QTouchEventSequence(window, deviceType); + return QTouchEventSequence(window, device); } } diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index f99b72ffd0..791f25aa27 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -5808,7 +5808,7 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent) // update state QGraphicsItem *item = 0; if (touchPoint.state() == Qt::TouchPointPressed) { - if (sceneTouchEvent->deviceType() == QTouchEvent::TouchPad) { + if (sceneTouchEvent->device()->type() == QTouchDevice::TouchPad) { // on touch-pad devices, send all touch points to the same item item = itemForTouchPointId.isEmpty() ? 0 @@ -5823,7 +5823,7 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent) item = cachedItemsUnderMouse.isEmpty() ? 0 : cachedItemsUnderMouse.first(); } - if (sceneTouchEvent->deviceType() == QTouchEvent::TouchScreen) { + if (sceneTouchEvent->device()->type() == QTouchDevice::TouchScreen) { // on touch-screens, combine this touch point with the closest one we find int closestTouchPointId = findClosestTouchPointId(touchPoint.scenePos()); QGraphicsItem *closestItem = itemForTouchPointId.value(closestTouchPointId); @@ -5889,10 +5889,12 @@ void QGraphicsScenePrivate::touchEventHandler(QTouchEvent *sceneTouchEvent) QTouchEvent touchEvent(eventType); touchEvent.setWidget(sceneTouchEvent->widget()); - touchEvent.setDeviceType(sceneTouchEvent->deviceType()); + touchEvent.setDevice(sceneTouchEvent->device()); touchEvent.setModifiers(sceneTouchEvent->modifiers()); touchEvent.setTouchPointStates(it.value().first); touchEvent.setTouchPoints(it.value().second); + touchEvent.setTimestamp(sceneTouchEvent->timestamp()); + touchEvent.setWindow(sceneTouchEvent->window()); switch (touchEvent.type()) { case QEvent::TouchBegin: diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 472f19a3c1..afd5fb70e1 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -5214,7 +5214,7 @@ int QApplicationPrivate::findClosestTouchPointId(const QPointF &screenPos) } void QApplicationPrivate::translateRawTouchEvent(QWidget *window, - QTouchEvent::DeviceType deviceType, + QTouchDevice *device, const QList &touchPoints, ulong timestamp) { @@ -5234,7 +5234,7 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window, switch (touchPoint.state()) { case Qt::TouchPointPressed: { - if (deviceType == QTouchEvent::TouchPad) { + if (device->type() == QTouchDevice::TouchPad) { // on touch-pads, send all touch points to the same widget widget = d->widgetForTouchPointId.isEmpty() ? QWeakPointer() @@ -5252,7 +5252,7 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window, widget = window; } - if (deviceType == QTouchEvent::TouchScreen) { + if (device->type() == QTouchDevice::TouchScreen) { int closestTouchPointId = d->findClosestTouchPointId(touchPoint.screenPos()); QWidget *closestWidget = d->widgetForTouchPointId.value(closestTouchPointId).data(); if (closestWidget @@ -5348,12 +5348,13 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window, } QTouchEvent touchEvent(eventType, - deviceType, + device, QApplication::keyboardModifiers(), it.value().first, it.value().second); updateTouchPointsForWidget(widget, &touchEvent); touchEvent.setTimestamp(timestamp); + touchEvent.setWindow(window->windowHandle()); switch (touchEvent.type()) { case QEvent::TouchBegin: @@ -5376,11 +5377,11 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window, } Q_WIDGETS_EXPORT void qt_translateRawTouchEvent(QWidget *window, - QTouchEvent::DeviceType deviceType, + QTouchDevice *device, const QList &touchPoints, ulong timestamp) { - QApplicationPrivate::translateRawTouchEvent(window, deviceType, touchPoints, timestamp); + QApplicationPrivate::translateRawTouchEvent(window, device, touchPoints, timestamp); } #ifndef QT_NO_GESTURES diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index 7b663608f7..3841cef62f 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -83,6 +83,7 @@ class QInputContext; class QObject; class QWidget; class QSocketNotifier; +class QTouchDevice; #ifndef QT_NO_GESTURES class QGestureManager; #endif @@ -482,7 +483,7 @@ public: void appendTouchPoint(const QTouchEvent::TouchPoint &touchPoint); void removeTouchPoint(int touchPointId); static void translateRawTouchEvent(QWidget *widget, - QTouchEvent::DeviceType deviceType, + QTouchDevice *device, const QList &touchPoints, ulong timestamp); @@ -554,8 +555,9 @@ private: }; Q_WIDGETS_EXPORT void qt_translateRawTouchEvent(QWidget *window, - QTouchEvent::DeviceType deviceType, - const QList &touchPoints); + QTouchDevice *device, + const QList &touchPoints, + ulong timestamp); #if defined(Q_WS_WIN) extern void qt_win_set_cursor(QWidget *, bool); diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index e5ebfba851..7ec37bb929 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -8251,7 +8251,7 @@ bool QWidget::event(QEvent *event) #ifndef Q_WS_MAC QTouchEvent *touchEvent = static_cast(event); const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first(); - if (touchPoint.isPrimary() || touchEvent->deviceType() == QTouchEvent::TouchPad) + if (touchPoint.isPrimary() || touchEvent->device()->type() == QTouchDevice::TouchPad) break; // fake a mouse event! diff --git a/src/widgets/kernel/qwidgetwindow_qpa.cpp b/src/widgets/kernel/qwidgetwindow_qpa.cpp index 5b7ded9ece..e3178db8c9 100644 --- a/src/widgets/kernel/qwidgetwindow_qpa.cpp +++ b/src/widgets/kernel/qwidgetwindow_qpa.cpp @@ -289,7 +289,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) void QWidgetWindow::handleTouchEvent(QTouchEvent *event) { - QApplicationPrivate::translateRawTouchEvent(m_widget, event->deviceType(), event->touchPoints(), event->timestamp()); + QApplicationPrivate::translateRawTouchEvent(m_widget, event->device(), event->touchPoints(), event->timestamp()); } void QWidgetWindow::handleKeyEvent(QKeyEvent *event) diff --git a/src/widgets/util/qflickgesture.cpp b/src/widgets/util/qflickgesture.cpp index a028b27d72..fbbefcf89f 100644 --- a/src/widgets/util/qflickgesture.cpp +++ b/src/widgets/util/qflickgesture.cpp @@ -551,7 +551,7 @@ QGestureRecognizer::Result QFlickGestureRecognizer::recognize(QGesture *state, if (!inputType) inputType = QScroller::InputMove; - if (te->deviceType() == QTouchEvent::TouchPad) { + if (te->device()->type() == QTouchDevice::TouchPad) { if (te->touchPoints().count() != 2) // 2 fingers on pad return Ignore; diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp index 4583e79561..07afe4a89c 100644 --- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp +++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp @@ -51,6 +51,7 @@ public: bool acceptTouchBegin, acceptTouchUpdate, acceptTouchEnd; bool deleteInTouchBegin, deleteInTouchUpdate, deleteInTouchEnd; ulong timestamp; + QTouchDevice *deviceFromEvent; tst_QTouchEventWidget() : QWidget() @@ -78,6 +79,7 @@ public: seenTouchBegin = !seenTouchBegin && !seenTouchUpdate && !seenTouchEnd; touchBeginPoints = static_cast(event)->touchPoints(); timestamp = static_cast(event)->timestamp(); + deviceFromEvent = static_cast(event)->device(); event->setAccepted(acceptTouchBegin); if (deleteInTouchBegin) delete this; @@ -88,6 +90,7 @@ public: seenTouchUpdate = seenTouchBegin && !seenTouchEnd; touchUpdatePoints = static_cast(event)->touchPoints(); timestamp = static_cast(event)->timestamp(); + deviceFromEvent = static_cast(event)->device(); event->setAccepted(acceptTouchUpdate); if (deleteInTouchUpdate) delete this; @@ -98,6 +101,7 @@ public: seenTouchEnd = seenTouchBegin && !seenTouchEnd; touchEndPoints = static_cast(event)->touchPoints(); timestamp = static_cast(event)->timestamp(); + deviceFromEvent = static_cast(event)->device(); event->setAccepted(acceptTouchEnd); if (deleteInTouchEnd) delete this; @@ -190,7 +194,7 @@ class tst_QTouchEvent : public QObject { Q_OBJECT public: - tst_QTouchEvent() { } + tst_QTouchEvent(); ~tst_QTouchEvent() { } private slots: @@ -205,8 +209,21 @@ private slots: void deleteInRawEventTranslation(); void crashInQGraphicsSceneAfterNotHandlingTouchBegin(); void touchBeginWithGraphicsWidget(); + +private: + QTouchDevice *touchScreenDevice; + QTouchDevice *touchPadDevice; }; +tst_QTouchEvent::tst_QTouchEvent() +{ + touchScreenDevice = new QTouchDevice; + touchPadDevice = new QTouchDevice; + touchPadDevice->setType(QTouchDevice::TouchPad); + QWindowSystemInterface::registerTouchDevice(touchScreenDevice); + QWindowSystemInterface::registerTouchDevice(touchPadDevice); +} + void tst_QTouchEvent::touchDisabledByDefault() { // QWidget @@ -219,7 +236,7 @@ void tst_QTouchEvent::touchDisabledByDefault() QList touchPoints; touchPoints.append(QTouchEvent::TouchPoint(0)); QTouchEvent touchEvent(QEvent::TouchBegin, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointPressed, touchPoints); @@ -248,7 +265,7 @@ void tst_QTouchEvent::touchDisabledByDefault() touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint())); touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint())); QTouchEvent touchEvent(QEvent::TouchBegin, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointPressed, (QList() << touchPoint)); @@ -272,7 +289,7 @@ void tst_QTouchEvent::touchEventAcceptedByDefault() QList touchPoints; touchPoints.append(QTouchEvent::TouchPoint(0)); QTouchEvent touchEvent(QEvent::TouchBegin, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointPressed, touchPoints); @@ -310,7 +327,7 @@ void tst_QTouchEvent::touchEventAcceptedByDefault() touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint())); touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint())); QTouchEvent touchEvent(QEvent::TouchBegin, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointPressed, (QList() << touchPoint)); @@ -338,7 +355,7 @@ void tst_QTouchEvent::touchBeginPropagatesWhenIgnored() QList touchPoints; touchPoints.append(QTouchEvent::TouchPoint(0)); QTouchEvent touchEvent(QEvent::TouchBegin, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointPressed, touchPoints); @@ -390,7 +407,7 @@ void tst_QTouchEvent::touchBeginPropagatesWhenIgnored() touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint())); touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint())); QTouchEvent touchEvent(QEvent::TouchBegin, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointPressed, (QList() << touchPoint)); @@ -426,7 +443,7 @@ void tst_QTouchEvent::touchBeginPropagatesWhenIgnored() touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint())); touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint())); QTouchEvent touchEvent(QEvent::TouchBegin, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointPressed, (QList() << touchPoint)); @@ -454,7 +471,7 @@ void tst_QTouchEvent::touchUpdateAndEndNeverPropagate() QList touchPoints; touchPoints.append(QTouchEvent::TouchPoint(0)); QTouchEvent touchBeginEvent(QEvent::TouchBegin, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointPressed, touchPoints); @@ -466,7 +483,7 @@ void tst_QTouchEvent::touchUpdateAndEndNeverPropagate() // send the touch update to the child, but ignore it, it doesn't propagate QTouchEvent touchUpdateEvent(QEvent::TouchUpdate, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointMoved, touchPoints); @@ -478,7 +495,7 @@ void tst_QTouchEvent::touchUpdateAndEndNeverPropagate() // send the touch end, same thing should happen as with touch update QTouchEvent touchEndEvent(QEvent::TouchEnd, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointReleased, touchPoints); @@ -513,7 +530,7 @@ void tst_QTouchEvent::touchUpdateAndEndNeverPropagate() touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint())); touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint())); QTouchEvent touchBeginEvent(QEvent::TouchBegin, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointPressed, (QList() << touchPoint)); @@ -526,7 +543,7 @@ void tst_QTouchEvent::touchUpdateAndEndNeverPropagate() // send the touch update to the child, but ignore it, it doesn't propagate touchPoint.setState(Qt::TouchPointMoved); QTouchEvent touchUpdateEvent(QEvent::TouchUpdate, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointMoved, (QList() << touchPoint)); @@ -540,7 +557,7 @@ void tst_QTouchEvent::touchUpdateAndEndNeverPropagate() // send the touch end, same thing should happen as with touch update touchPoint.setState(Qt::TouchPointReleased); QTouchEvent touchEndEvent(QEvent::TouchEnd, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointReleased, (QList() << touchPoint)); @@ -576,9 +593,12 @@ void tst_QTouchEvent::basicRawEventTranslation() rawTouchPoint.setState(Qt::TouchPointPressed); rawTouchPoint.setScreenPos(screenPos); rawTouchPoint.setNormalizedPos(normalized(rawTouchPoint.pos(), screenGeometry)); + QList rawPosList; + rawPosList << QPointF(12, 34) << QPointF(56, 78); + rawTouchPoint.setRawScreenPositions(rawPosList); const ulong timestamp = 1234; qt_translateRawTouchEvent(&touchWidget, - QTouchEvent::TouchScreen, + touchScreenDevice, QList() << rawTouchPoint, timestamp); QVERIFY(touchWidget.seenTouchBegin); @@ -605,13 +625,15 @@ void tst_QTouchEvent::basicRawEventTranslation() QCOMPARE(touchBeginPoint.screenRect(), QRectF(rawTouchPoint.screenPos(), QSizeF(0, 0))); QCOMPARE(touchBeginPoint.sceneRect(), touchBeginPoint.screenRect()); QCOMPARE(touchBeginPoint.pressure(), qreal(1.)); + QCOMPARE(touchBeginPoint.velocity(), QVector2D()); + QCOMPARE(touchBeginPoint.rawScreenPositions(), rawPosList); // moving the point should translate to TouchUpdate rawTouchPoint.setState(Qt::TouchPointMoved); rawTouchPoint.setScreenPos(screenPos + delta); rawTouchPoint.setNormalizedPos(normalized(rawTouchPoint.pos(), screenGeometry)); qt_translateRawTouchEvent(&touchWidget, - QTouchEvent::TouchScreen, + touchScreenDevice, QList() << rawTouchPoint, 0); QVERIFY(touchWidget.seenTouchBegin); @@ -643,7 +665,7 @@ void tst_QTouchEvent::basicRawEventTranslation() rawTouchPoint.setScreenPos(screenPos + delta + delta); rawTouchPoint.setNormalizedPos(normalized(rawTouchPoint.pos(), screenGeometry)); qt_translateRawTouchEvent(&touchWidget, - QTouchEvent::TouchScreen, + touchScreenDevice, QList() << rawTouchPoint, 0); QVERIFY(touchWidget.seenTouchBegin); @@ -709,7 +731,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() rawTouchPoints[1].setState(Qt::TouchPointPressed); rawTouchPoints[1].setScreenPos(rightScreenPos); rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints, 0); + qt_translateRawTouchEvent(&touchWidget, touchScreenDevice, rawTouchPoints, 0); QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -770,7 +792,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() rawTouchPoints[1].setState(Qt::TouchPointMoved); rawTouchPoints[1].setScreenPos(centerScreenPos); rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints, 0); + qt_translateRawTouchEvent(&touchWidget, touchScreenDevice, rawTouchPoints, 0); QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -831,7 +853,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() rawTouchPoints[1].setState(Qt::TouchPointReleased); rawTouchPoints[1].setScreenPos(centerScreenPos); rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints, 0); + qt_translateRawTouchEvent(&touchWidget, touchScreenDevice, rawTouchPoints, 0); QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -924,7 +946,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() rawTouchPoints[1].setState(Qt::TouchPointPressed); rawTouchPoints[1].setScreenPos(rightScreenPos); rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints, 0); + qt_translateRawTouchEvent(&touchWidget, touchPadDevice, rawTouchPoints, 0); QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -985,7 +1007,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() rawTouchPoints[1].setState(Qt::TouchPointMoved); rawTouchPoints[1].setScreenPos(centerScreenPos); rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints, 0); + qt_translateRawTouchEvent(&touchWidget, touchPadDevice, rawTouchPoints, 0); QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -1046,7 +1068,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() rawTouchPoints[1].setState(Qt::TouchPointReleased); rawTouchPoints[1].setScreenPos(centerScreenPos); rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry)); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints, 0); + qt_translateRawTouchEvent(&touchWidget, touchPadDevice, rawTouchPoints, 0); QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -1123,17 +1145,17 @@ void tst_QTouchEvent::deleteInEventHandler() QList touchPoints; touchPoints.append(QTouchEvent::TouchPoint(0)); QTouchEvent touchBeginEvent(QEvent::TouchBegin, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointPressed, touchPoints); QTouchEvent touchUpdateEvent(QEvent::TouchUpdate, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointStationary, touchPoints); QTouchEvent touchEndEvent(QEvent::TouchEnd, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointReleased, touchPoints); @@ -1200,19 +1222,19 @@ void tst_QTouchEvent::deleteInEventHandler() QList touchPoints; touchPoints.append(touchPoint); QTouchEvent touchBeginEvent(QEvent::TouchBegin, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointPressed, touchPoints); touchPoints[0].setState(Qt::TouchPointMoved); QTouchEvent touchUpdateEvent(QEvent::TouchUpdate, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointMoved, touchPoints); touchPoints[0].setState(Qt::TouchPointReleased); QTouchEvent touchEndEvent(QEvent::TouchEnd, - QTouchEvent::TouchScreen, + touchScreenDevice, Qt::NoModifier, Qt::TouchPointReleased, touchPoints); @@ -1304,20 +1326,20 @@ void tst_QTouchEvent::deleteInRawEventTranslation() rawTouchPoints[2].setNormalizedPos(normalized(rawTouchPoints[2].pos(), screenGeometry)); // generate begin events on all widgets, the left widget should die - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints, 0); + qt_translateRawTouchEvent(&touchWidget, touchScreenDevice, rawTouchPoints, 0); QVERIFY(pl.isNull() && !pc.isNull() && !pr.isNull()); // generate update events on all widget, the center widget should die rawTouchPoints[0].setState(Qt::TouchPointMoved); rawTouchPoints[1].setState(Qt::TouchPointMoved); rawTouchPoints[2].setState(Qt::TouchPointMoved); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints, 0); + qt_translateRawTouchEvent(&touchWidget, touchScreenDevice, rawTouchPoints, 0); // generate end events on all widget, the right widget should die rawTouchPoints[0].setState(Qt::TouchPointReleased); rawTouchPoints[1].setState(Qt::TouchPointReleased); rawTouchPoints[2].setState(Qt::TouchPointReleased); - qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints, 0); + qt_translateRawTouchEvent(&touchWidget, touchScreenDevice, rawTouchPoints, 0); } void tst_QTouchEvent::crashInQGraphicsSceneAfterNotHandlingTouchBegin() @@ -1343,11 +1365,11 @@ void tst_QTouchEvent::crashInQGraphicsSceneAfterNotHandlingTouchBegin() QPoint centerPos = view.mapFromScene(rect->boundingRect().center()); // Touch the button - QTest::touchEvent(view.viewport()).press(0, centerPos, static_cast(0)); - QTest::touchEvent(view.viewport()).release(0, centerPos, static_cast(0)); + QTest::touchEvent(view.viewport(), touchScreenDevice).press(0, centerPos, static_cast(0)); + QTest::touchEvent(view.viewport(), touchScreenDevice).release(0, centerPos, static_cast(0)); // Touch outside of the button - QTest::touchEvent(view.viewport()).press(0, view.mapFromScene(QPoint(10, 10)), static_cast(0)); - QTest::touchEvent(view.viewport()).release(0, view.mapFromScene(QPoint(10, 10)), static_cast(0)); + QTest::touchEvent(view.viewport(), touchScreenDevice).press(0, view.mapFromScene(QPoint(10, 10)), static_cast(0)); + QTest::touchEvent(view.viewport(), touchScreenDevice).release(0, view.mapFromScene(QPoint(10, 10)), static_cast(0)); } void tst_QTouchEvent::touchBeginWithGraphicsWidget() @@ -1368,12 +1390,12 @@ void tst_QTouchEvent::touchBeginWithGraphicsWidget() QTest::qWaitForWindowShown(&view); view.fitInView(scene.sceneRect()); - QTest::touchEvent(static_cast(0)) + QTest::touchEvent(static_cast(0), touchScreenDevice) .press(0, view.mapFromScene(root->mapToScene(3,3)), view.viewport()); - QTest::touchEvent(static_cast(0)) + QTest::touchEvent(static_cast(0), touchScreenDevice) .stationary(0) .press(1, view.mapFromScene(root->mapToScene(6,6)), view.viewport()); - QTest::touchEvent(static_cast(0)) + QTest::touchEvent(static_cast(0), touchScreenDevice) .release(0, view.mapFromScene(root->mapToScene(3,3)), view.viewport()) .release(1, view.mapFromScene(root->mapToScene(6,6)), view.viewport()); @@ -1385,12 +1407,12 @@ void tst_QTouchEvent::touchBeginWithGraphicsWidget() root->reset(); glassWidget->setWindowFlags(Qt::Window); // make the glassWidget a panel - QTest::touchEvent(static_cast(0)) + QTest::touchEvent(static_cast(0), touchScreenDevice) .press(0, view.mapFromScene(root->mapToScene(3,3)), view.viewport()); - QTest::touchEvent(static_cast(0)) + QTest::touchEvent(static_cast(0), touchScreenDevice) .stationary(0) .press(1, view.mapFromScene(root->mapToScene(6,6)), view.viewport()); - QTest::touchEvent(static_cast(0)) + QTest::touchEvent(static_cast(0), touchScreenDevice) .release(0, view.mapFromScene(root->mapToScene(3,3)), view.viewport()) .release(1, view.mapFromScene(root->mapToScene(6,6)), view.viewport()); diff --git a/tests/auto/other/gestures/tst_gestures.cpp b/tests/auto/other/gestures/tst_gestures.cpp index 098f84b399..1a71f9170a 100644 --- a/tests/auto/other/gestures/tst_gestures.cpp +++ b/tests/auto/other/gestures/tst_gestures.cpp @@ -2335,7 +2335,10 @@ void tst_Gestures::bug_13501_gesture_not_accepted() w.show(); QTest::qWaitForWindowShown(&w); //QTest::mousePress(&ignoreEvent, Qt::LeftButton); - QTest::touchEvent(&w).press(0, QPoint(10, 10), &w); + QTouchDevice *device = new QTouchDevice; + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device); + QTest::touchEvent(&w, device).press(0, QPoint(10, 10), &w); } QTEST_MAIN(tst_Gestures) diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 8a2fdc97f3..8474293a54 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -10791,7 +10791,10 @@ void tst_QGraphicsItem::touchEventPropagation() touchPoints << tp; sendMousePress(&scene, tp.scenePos()); - QTouchEvent touchBegin(QEvent::TouchBegin, QTouchEvent::TouchScreen, Qt::NoModifier, Qt::TouchPointPressed, touchPoints); + QTouchDevice *device = new QTouchDevice; + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device); + QTouchEvent touchBegin(QEvent::TouchBegin, device, Qt::NoModifier, Qt::TouchPointPressed, touchPoints); qApp->sendEvent(&scene, &touchBegin); QCOMPARE(touchEventReceiver->touchBeginEventCount, expectedCount); diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 8cf85dd8ea..81cdffe4e5 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -1933,27 +1933,31 @@ void tst_QApplication::touchEventPropagation() release.setState(Qt::TouchPointReleased); releasedTouchPoints << release; + QTouchDevice *device = new QTouchDevice; + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device); + { // touch event behavior on a window TouchEventPropagationTestWidget window; window.setObjectName("1. window"); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, releasedTouchPoints, 0); QVERIFY(!window.seenTouchEvent); QVERIFY(!window.seenMouseEvent); window.reset(); window.setAttribute(Qt::WA_AcceptTouchEvents); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, releasedTouchPoints, 0); QVERIFY(window.seenTouchEvent); QVERIFY(!window.seenMouseEvent); window.reset(); window.acceptTouchEvent = true; - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, releasedTouchPoints, 0); QVERIFY(window.seenTouchEvent); QVERIFY(!window.seenMouseEvent); } @@ -1965,8 +1969,8 @@ void tst_QApplication::touchEventPropagation() TouchEventPropagationTestWidget widget(&window); widget.setObjectName("2. widget"); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, releasedTouchPoints, 0); QVERIFY(!widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(!window.seenTouchEvent); @@ -1975,8 +1979,8 @@ void tst_QApplication::touchEventPropagation() window.reset(); widget.reset(); widget.setAttribute(Qt::WA_AcceptTouchEvents); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, releasedTouchPoints, 0); QVERIFY(widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(!window.seenTouchEvent); @@ -1985,8 +1989,8 @@ void tst_QApplication::touchEventPropagation() window.reset(); widget.reset(); widget.acceptMouseEvent = true; - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, releasedTouchPoints, 0); QVERIFY(widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(!window.seenTouchEvent); @@ -1995,8 +1999,8 @@ void tst_QApplication::touchEventPropagation() window.reset(); widget.reset(); widget.acceptTouchEvent = true; - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, releasedTouchPoints, 0); QVERIFY(widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(!window.seenTouchEvent); @@ -2006,8 +2010,8 @@ void tst_QApplication::touchEventPropagation() widget.reset(); widget.setAttribute(Qt::WA_AcceptTouchEvents, false); window.setAttribute(Qt::WA_AcceptTouchEvents); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, releasedTouchPoints, 0); QVERIFY(!widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(window.seenTouchEvent); @@ -2016,8 +2020,8 @@ void tst_QApplication::touchEventPropagation() window.reset(); widget.reset(); window.acceptTouchEvent = true; - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, releasedTouchPoints, 0); QVERIFY(!widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(window.seenTouchEvent); @@ -2027,8 +2031,8 @@ void tst_QApplication::touchEventPropagation() widget.reset(); widget.acceptMouseEvent = true; // doesn't matter, touch events are propagated first window.acceptTouchEvent = true; - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, pressedTouchPoints, 0); - qt_translateRawTouchEvent(&window, QTouchEvent::TouchScreen, releasedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, pressedTouchPoints, 0); + qt_translateRawTouchEvent(&window, device, releasedTouchPoints, 0); QVERIFY(!widget.seenTouchEvent); QVERIFY(!widget.seenMouseEvent); QVERIFY(window.seenTouchEvent); diff --git a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp index c8c8136f44..a7912aedc1 100644 --- a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp +++ b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp @@ -162,8 +162,11 @@ void tst_QScroller::kineticScroll( tst_QScrollerWidget *sw, QPointF from, QPoint touchPoint.setPos(touchStart); touchPoint.setScenePos(touchStart); touchPoint.setScreenPos(touchStart); + QTouchDevice *device = new QTouchDevice; + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device); QTouchEvent touchEvent1(QEvent::TouchBegin, - QTouchEvent::TouchScreen, + device, Qt::NoModifier, Qt::TouchPointPressed, (QList() << touchPoint)); @@ -177,7 +180,7 @@ void tst_QScroller::kineticScroll( tst_QScrollerWidget *sw, QPointF from, QPoint touchPoint.setScenePos(touchUpdate); touchPoint.setScreenPos(touchUpdate); QTouchEvent touchEvent2(QEvent::TouchUpdate, - QTouchEvent::TouchScreen, + device, Qt::NoModifier, Qt::TouchPointMoved, (QList() << touchPoint)); @@ -202,7 +205,7 @@ void tst_QScroller::kineticScroll( tst_QScrollerWidget *sw, QPointF from, QPoint touchPoint.setScenePos(touchEnd); touchPoint.setScreenPos(touchEnd); QTouchEvent touchEvent5(QEvent::TouchEnd, - QTouchEvent::TouchScreen, + device, Qt::NoModifier, Qt::TouchPointReleased, (QList() << touchPoint)); @@ -233,8 +236,11 @@ void tst_QScroller::kineticScrollNoTest( tst_QScrollerWidget *sw, QPointF from, touchPoint.setPos(touchStart); touchPoint.setScenePos(touchStart); touchPoint.setScreenPos(touchStart); + QTouchDevice *device = new QTouchDevice; + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device); QTouchEvent touchEvent1(QEvent::TouchBegin, - QTouchEvent::TouchScreen, + device, Qt::NoModifier, Qt::TouchPointPressed, (QList() << touchPoint)); @@ -246,7 +252,7 @@ void tst_QScroller::kineticScrollNoTest( tst_QScrollerWidget *sw, QPointF from, touchPoint.setScenePos(touchUpdate); touchPoint.setScreenPos(touchUpdate); QTouchEvent touchEvent2(QEvent::TouchUpdate, - QTouchEvent::TouchScreen, + device, Qt::NoModifier, Qt::TouchPointMoved, (QList() << touchPoint)); @@ -259,7 +265,7 @@ void tst_QScroller::kineticScrollNoTest( tst_QScrollerWidget *sw, QPointF from, touchPoint.setScenePos(touchEnd); touchPoint.setScreenPos(touchEnd); QTouchEvent touchEvent5(QEvent::TouchEnd, - QTouchEvent::TouchScreen, + device, Qt::NoModifier, Qt::TouchPointReleased, (QList() << touchPoint)); -- cgit v1.2.3