diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/kernel.pri | 7 | ||||
-rw-r--r-- | src/gui/kernel/qevent.cpp | 127 | ||||
-rw-r--r-- | src/gui/kernel/qevent.h | 29 | ||||
-rw-r--r-- | src/gui/kernel/qevent_p.h | 3 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 8 | ||||
-rw-r--r-- | src/gui/kernel/qtouchdevice.cpp | 224 | ||||
-rw-r--r-- | src/gui/kernel/qtouchdevice.h | 96 | ||||
-rw-r--r-- | src/gui/kernel/qtouchdevice_p.h | 74 | ||||
-rw-r--r-- | src/gui/kernel/qwindowsysteminterface_qpa.cpp | 24 | ||||
-rw-r--r-- | src/gui/kernel/qwindowsysteminterface_qpa.h | 13 | ||||
-rw-r--r-- | src/gui/kernel/qwindowsysteminterface_qpa_p.h | 8 |
11 files changed, 575 insertions, 38 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 { |