summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>2011-11-27 17:42:23 +0200
committerQt by Nokia <qt-info@nokia.com>2011-12-09 14:15:37 +0100
commit4222603f8ea3a0d0ef5b9a190605ad86e00f27f6 (patch)
tree2ace610731b845e4e04e6ea8f0def0ce3aee31a4 /src
parent2c4879a7676d6a75379ac6ff24ac4c2a6c2b9658 (diff)
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 <lars.knoll@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/kernel/kernel.pri7
-rw-r--r--src/gui/kernel/qevent.cpp127
-rw-r--r--src/gui/kernel/qevent.h29
-rw-r--r--src/gui/kernel/qevent_p.h3
-rw-r--r--src/gui/kernel/qguiapplication.cpp8
-rw-r--r--src/gui/kernel/qtouchdevice.cpp224
-rw-r--r--src/gui/kernel/qtouchdevice.h96
-rw-r--r--src/gui/kernel/qtouchdevice_p.h74
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa.cpp24
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa.h13
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa_p.h8
-rw-r--r--src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp6
-rw-r--r--src/plugins/generic/touchscreen/qtoucheventsenderqpa.h3
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm16
-rw-r--r--src/plugins/platforms/windows/qwindowsmousehandler.cpp12
-rw-r--r--src/plugins/platforms/windows/qwindowsmousehandler.h2
-rw-r--r--src/plugins/platforms/xcb/qxcbconnection_maemo.cpp15
-rw-r--r--src/testlib/qtesttouch.h32
-rw-r--r--src/widgets/graphicsview/qgraphicsscene.cpp8
-rw-r--r--src/widgets/kernel/qapplication.cpp13
-rw-r--r--src/widgets/kernel/qapplication_p.h8
-rw-r--r--src/widgets/kernel/qwidget.cpp2
-rw-r--r--src/widgets/kernel/qwidgetwindow_qpa.cpp2
-rw-r--r--src/widgets/util/qflickgesture.cpp2
24 files changed, 656 insertions, 78 deletions
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<QTouchEvent::TouchPoint> &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<QPointF> QTouchEvent::TouchPoint::rawScreenPositions() const
+{
+ return d->rawScreenPositions;
+}
+
/*! \internal */
void QTouchEvent::TouchPoint::setId(int id)
{
@@ -3940,6 +4009,30 @@ void QTouchEvent::TouchPoint::setPressure(qreal 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<QPointF> &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)
{
other.d->ref.ref();
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 <QtCore/qvector.h>
#include <QtCore/qset.h>
#include <QtCore/qfile.h>
-
+#include <QtGui/qvector2d.h>
+#include <QtGui/qtouchdevice.h>
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<QPointF> 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<QPointF> &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<QTouchEvent::TouchPoint> &touchPoints = QList<QTouchEvent::TouchPoint>());
~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<DeviceType>(int(_device->type())); }
inline Qt::TouchPointStates touchPointStates() const { return _touchPointStates; }
inline const QList<QTouchEvent::TouchPoint> &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<QTouchEvent::TouchPoint> &atouchPoints) { _touchPoints = atouchPoints; }
+ inline void setDevice(QTouchDevice *device) { _device = device; }
protected:
QWidget *_widget;
- QTouchEvent::DeviceType _deviceType;
+ QWindow *_window;
+ QTouchDevice *_device;
Qt::TouchPointStates _touchPointStates;
QList<QTouchEvent::TouchPoint> _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<QPointF> 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<QWindow>()
@@ -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 <QList>
+#include <QMutex>
+#include <QCoreApplication>
+
+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<QTouchDevice *> 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<const QTouchDevice *> QTouchDevice::devices()
+{
+ QMutexLocker lock(devicesMutex());
+ QList<QTouchDevice *> *devList = deviceList();
+ QList<const QTouchDevice *> 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 <QtCore/qobject.h>
+
+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<const QTouchDevice *> 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 <QtCore/qobject.h>
+#include <QtGui/qtouchdevice.h>
+
+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 <QAbstractEventDispatcher>
#include <qdebug.h>
@@ -213,16 +214,28 @@ void QWindowSystemInterfacePrivate::queueWindowSystemEvent(QWindowSystemInterfac
dispatcher->wakeUp();
}
-void QWindowSystemInterface::handleTouchEvent(QWindow *w, QEvent::Type type, QTouchEvent::DeviceType devType, const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods) {
+void QWindowSystemInterface::registerTouchDevice(QTouchDevice *device)
+{
+ QTouchDevicePrivate::registerDevice(device);
+}
+
+void QWindowSystemInterface::handleTouchEvent(QWindow *w, QEvent::Type type, QTouchDevice *device,
+ const QList<struct TouchPoint> &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<struct TouchPoint> &points, Qt::KeyboardModifiers mods)
+void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QEvent::Type type,
+ QTouchDevice *device,
+ const QList<struct TouchPoint> &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<QTouchEvent::TouchPoint> 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 <QtCore/QMutex>
#include <QtGui/QTouchEvent>
#include <QtCore/QEventLoop>
+#include <QtGui/QVector2D>
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<QPointF> rawPositions; // in screen coordinates
};
- static void handleTouchEvent(QWindow *w, QEvent::Type type, QTouchEvent::DeviceType devType, const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier);
- static void handleTouchEvent(QWindow *w, ulong timestamp, QEvent::Type type, QTouchEvent::DeviceType devType, const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier);
+ static void registerTouchDevice(QTouchDevice *device);
+ static void handleTouchEvent(QWindow *w, QEvent::Type type, QTouchDevice *device,
+ const QList<struct TouchPoint> &points, Qt::KeyboardModifiers mods = Qt::NoModifier);
+ static void handleTouchEvent(QWindow *w, ulong timestamp, QEvent::Type type, QTouchDevice *device,
+ const QList<struct TouchPoint> &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<QTouchEvent::TouchPoint> &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<QTouchEvent::TouchPoint> &p, Qt::KeyboardModifiers mods)
+ :InputEvent(w, time, Touch, mods), device(dev), points(p), touchType(t) { }
+ QTouchDevice *device;
QList<QTouchEvent::TouchPoint> 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 <accessibilityinspector.h>
#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<QWindowSystemInterface::TouchPoint> 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<QWindowSystemInterface::TouchPoint> 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<QWindowSystemInterface::TouchPoint> 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<QWindowSystemInterface::TouchPoint> 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<QWindow> m_windowUnderMouse;
QHash<DWORD, int> 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<QWindowSystemInterface::TouchPoint> 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<QTouchEvent::TouchPoint> &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<QTouchEvent::TouchPoint> &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<QWidget>()
@@ -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<QTouchEvent::TouchPoint> &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<QTouchEvent::TouchPoint> &touchPoints,
ulong timestamp);
@@ -554,8 +555,9 @@ private:
};
Q_WIDGETS_EXPORT void qt_translateRawTouchEvent(QWidget *window,
- QTouchEvent::DeviceType deviceType,
- const QList<QTouchEvent::TouchPoint> &touchPoints);
+ QTouchDevice *device,
+ const QList<QTouchEvent::TouchPoint> &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<QTouchEvent *>(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;