| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qtouchdevice.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 24 | ** | - | ||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | #include "qtouchdevice.h" | - | ||||||||||||
| 41 | #include "qtouchdevice_p.h" | - | ||||||||||||
| 42 | #include <QList> | - | ||||||||||||
| 43 | #include <QMutex> | - | ||||||||||||
| 44 | #include <QCoreApplication> | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | #include <private/qdebug_p.h> | - | ||||||||||||
| 47 | - | |||||||||||||
| 48 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 49 | - | |||||||||||||
| 50 | /*! | - | ||||||||||||
| 51 | \class QTouchDevice | - | ||||||||||||
| 52 | \brief The QTouchDevice class describes the device from which touch events originate. | - | ||||||||||||
| 53 | \since 5.0 | - | ||||||||||||
| 54 | \ingroup touch | - | ||||||||||||
| 55 | \inmodule QtGui | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | Each QTouchEvent contains a QTouchDevice pointer to allow accessing | - | ||||||||||||
| 58 | device-specific properties like type and capabilities. It is the | - | ||||||||||||
| 59 | responsibility of the platform or generic plug-ins to register the | - | ||||||||||||
| 60 | available touch devices via QWindowSystemInterface before generating any | - | ||||||||||||
| 61 | touch events. Applications do not need to instantiate this class, they | - | ||||||||||||
| 62 | should just access the global instances pointed to by QTouchEvent::device(). | - | ||||||||||||
| 63 | */ | - | ||||||||||||
| 64 | - | |||||||||||||
| 65 | /*! \enum QTouchDevice::DeviceType | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | This enum represents the type of device that generated a QTouchEvent. | - | ||||||||||||
| 68 | - | |||||||||||||
| 69 | \value TouchScreen In this type of device, the touch surface and display are integrated. This | - | ||||||||||||
| 70 | means the surface and display typically have the same size, such that there | - | ||||||||||||
| 71 | is a direct relationship between the touch points' physical positions and the | - | ||||||||||||
| 72 | coordinate reported by QTouchEvent::TouchPoint. As a result, Qt allows the | - | ||||||||||||
| 73 | user to interact directly with multiple QWidgets and QGraphicsItems at the | - | ||||||||||||
| 74 | same time. | - | ||||||||||||
| 75 | - | |||||||||||||
| 76 | \value TouchPad In this type of device, the touch surface is separate from the display. There | - | ||||||||||||
| 77 | is not a direct relationship between the physical touch location and the | - | ||||||||||||
| 78 | on-screen coordinates. Instead, they are calculated relative to the current | - | ||||||||||||
| 79 | mouse position, and the user must use the touch-pad to move this reference | - | ||||||||||||
| 80 | point. Unlike touch-screens, Qt allows users to only interact with a single | - | ||||||||||||
| 81 | QWidget or QGraphicsItem at a time. | - | ||||||||||||
| 82 | */ | - | ||||||||||||
| 83 | - | |||||||||||||
| 84 | /*! \enum QTouchDevice::CapabilityFlag | - | ||||||||||||
| 85 | - | |||||||||||||
| 86 | This enum is used with QTouchDevice::capabilities() to indicate what kind of information the | - | ||||||||||||
| 87 | touch device or its driver can provide. | - | ||||||||||||
| 88 | - | |||||||||||||
| 89 | \value Position Indicates that position information is available, meaning | - | ||||||||||||
| 90 | that the pos() family of functions in the touch points return valid points. | - | ||||||||||||
| 91 | - | |||||||||||||
| 92 | \value Area Indicates that touch area information is available, meaning that the rect() family | - | ||||||||||||
| 93 | of functions in the touch points return valid rectangles. | - | ||||||||||||
| 94 | - | |||||||||||||
| 95 | \value Pressure Indicates that pressure information is available, meaning that pressure() | - | ||||||||||||
| 96 | returns a valid value. | - | ||||||||||||
| 97 | - | |||||||||||||
| 98 | \value Velocity Indicates that velocity information is available, meaning that velocity() | - | ||||||||||||
| 99 | returns a valid vector. | - | ||||||||||||
| 100 | - | |||||||||||||
| 101 | \value RawPositions Indicates that the list returned by QTouchEvent::TouchPoint::rawScreenPositions() | - | ||||||||||||
| 102 | may contain one or more positions for each touch point. This is relevant when | - | ||||||||||||
| 103 | the touch input gets filtered or corrected on driver level. | - | ||||||||||||
| 104 | - | |||||||||||||
| 105 | \value NormalizedPosition Indicates that the normalized position is available, meaning that normalizedPos() | - | ||||||||||||
| 106 | returns a valid value. | - | ||||||||||||
| 107 | - | |||||||||||||
| 108 | \value MouseEmulation Indicates that the device synthesizes mouse events. | - | ||||||||||||
| 109 | This enum value has been introduced in Qt 5.5. | - | ||||||||||||
| 110 | */ | - | ||||||||||||
| 111 | - | |||||||||||||
| 112 | /*! | - | ||||||||||||
| 113 | Creates a new touch device instance. | - | ||||||||||||
| 114 | By default the name is empty, the only capability is Position and type is TouchScreen. | - | ||||||||||||
| 115 | */ | - | ||||||||||||
| 116 | QTouchDevice::QTouchDevice() | - | ||||||||||||
| 117 | : d(new QTouchDevicePrivate) | - | ||||||||||||
| 118 | { | - | ||||||||||||
| 119 | } never executed: end of block | 0 | ||||||||||||
| 120 | - | |||||||||||||
| 121 | /*! | - | ||||||||||||
| 122 | Destroys a touch device instance. | - | ||||||||||||
| 123 | */ | - | ||||||||||||
| 124 | QTouchDevice::~QTouchDevice() | - | ||||||||||||
| 125 | { | - | ||||||||||||
| 126 | delete d; | - | ||||||||||||
| 127 | } never executed: end of block | 0 | ||||||||||||
| 128 | - | |||||||||||||
| 129 | /*! | - | ||||||||||||
| 130 | Returns the touch device type. | - | ||||||||||||
| 131 | */ | - | ||||||||||||
| 132 | QTouchDevice::DeviceType QTouchDevice::type() const | - | ||||||||||||
| 133 | { | - | ||||||||||||
| 134 | return d->type; never executed: return d->type; | 0 | ||||||||||||
| 135 | } | - | ||||||||||||
| 136 | - | |||||||||||||
| 137 | /*! | - | ||||||||||||
| 138 | Returns the touch device capabilities. | - | ||||||||||||
| 139 | */ | - | ||||||||||||
| 140 | QTouchDevice::Capabilities QTouchDevice::capabilities() const | - | ||||||||||||
| 141 | { | - | ||||||||||||
| 142 | return d->caps; never executed: return d->caps; | 0 | ||||||||||||
| 143 | } | - | ||||||||||||
| 144 | - | |||||||||||||
| 145 | /*! | - | ||||||||||||
| 146 | Returns the maximum number of simultaneous touch points (fingers) that | - | ||||||||||||
| 147 | can be detected. | - | ||||||||||||
| 148 | \since 5.2 | - | ||||||||||||
| 149 | */ | - | ||||||||||||
| 150 | int QTouchDevice::maximumTouchPoints() const | - | ||||||||||||
| 151 | { | - | ||||||||||||
| 152 | return d->maxTouchPoints; never executed: return d->maxTouchPoints; | 0 | ||||||||||||
| 153 | } | - | ||||||||||||
| 154 | - | |||||||||||||
| 155 | /*! | - | ||||||||||||
| 156 | Returns the touch device name. | - | ||||||||||||
| 157 | - | |||||||||||||
| 158 | This string may often be empty. It is however useful for systems that have | - | ||||||||||||
| 159 | more than one touch input device because there it can be used to | - | ||||||||||||
| 160 | differentiate between the devices (i.e. to tell from which device a | - | ||||||||||||
| 161 | QTouchEvent originates from). | - | ||||||||||||
| 162 | */ | - | ||||||||||||
| 163 | QString QTouchDevice::name() const | - | ||||||||||||
| 164 | { | - | ||||||||||||
| 165 | return d->name; never executed: return d->name; | 0 | ||||||||||||
| 166 | } | - | ||||||||||||
| 167 | - | |||||||||||||
| 168 | /*! | - | ||||||||||||
| 169 | Sets the device type \a devType. | - | ||||||||||||
| 170 | */ | - | ||||||||||||
| 171 | void QTouchDevice::setType(DeviceType devType) | - | ||||||||||||
| 172 | { | - | ||||||||||||
| 173 | d->type = devType; | - | ||||||||||||
| 174 | } never executed: end of block | 0 | ||||||||||||
| 175 | - | |||||||||||||
| 176 | /*! | - | ||||||||||||
| 177 | Sets the capabilities \a caps supported by the device and its driver. | - | ||||||||||||
| 178 | */ | - | ||||||||||||
| 179 | void QTouchDevice::setCapabilities(Capabilities caps) | - | ||||||||||||
| 180 | { | - | ||||||||||||
| 181 | d->caps = caps; | - | ||||||||||||
| 182 | } never executed: end of block | 0 | ||||||||||||
| 183 | - | |||||||||||||
| 184 | /*! | - | ||||||||||||
| 185 | Sets the maximum number of simultaneous touchpoints \a max | - | ||||||||||||
| 186 | supported by the device and its driver. | - | ||||||||||||
| 187 | */ | - | ||||||||||||
| 188 | void QTouchDevice::setMaximumTouchPoints(int max) | - | ||||||||||||
| 189 | { | - | ||||||||||||
| 190 | d->maxTouchPoints = max; | - | ||||||||||||
| 191 | } never executed: end of block | 0 | ||||||||||||
| 192 | - | |||||||||||||
| 193 | /*! | - | ||||||||||||
| 194 | Sets the \a name (a unique identifier) for the device. In most systems it is | - | ||||||||||||
| 195 | enough to leave this unset and keep the default empty name. This identifier | - | ||||||||||||
| 196 | becomes important when having multiple touch devices and a need to | - | ||||||||||||
| 197 | differentiate between them. | - | ||||||||||||
| 198 | */ | - | ||||||||||||
| 199 | void QTouchDevice::setName(const QString &name) | - | ||||||||||||
| 200 | { | - | ||||||||||||
| 201 | d->name = name; | - | ||||||||||||
| 202 | } never executed: end of block | 0 | ||||||||||||
| 203 | - | |||||||||||||
| 204 | typedef QList<const QTouchDevice *> TouchDevices; | - | ||||||||||||
| 205 | Q_GLOBAL_STATIC(TouchDevices, deviceList) never executed: end of blocknever executed: guard.store(QtGlobalStatic::Destroyed);never executed: return &holder.value;
| 0 | ||||||||||||
| 206 | static QBasicMutex devicesMutex; | - | ||||||||||||
| 207 | - | |||||||||||||
| 208 | static void cleanupDevicesList() | - | ||||||||||||
| 209 | { | - | ||||||||||||
| 210 | QMutexLocker lock(&devicesMutex); | - | ||||||||||||
| 211 | qDeleteAll(*deviceList()); | - | ||||||||||||
| 212 | deviceList()->clear(); | - | ||||||||||||
| 213 | } never executed: end of block | 0 | ||||||||||||
| 214 | - | |||||||||||||
| 215 | /*! | - | ||||||||||||
| 216 | Returns a list of all registered devices. | - | ||||||||||||
| 217 | - | |||||||||||||
| 218 | \note The returned list cannot be used to add new devices. Use QWindowSystemInterface::registerTouchDevice() instead. | - | ||||||||||||
| 219 | */ | - | ||||||||||||
| 220 | QList<const QTouchDevice *> QTouchDevice::devices() | - | ||||||||||||
| 221 | { | - | ||||||||||||
| 222 | QMutexLocker lock(&devicesMutex); | - | ||||||||||||
| 223 | return *deviceList(); never executed: return *deviceList(); | 0 | ||||||||||||
| 224 | } | - | ||||||||||||
| 225 | - | |||||||||||||
| 226 | /*! | - | ||||||||||||
| 227 | \internal | - | ||||||||||||
| 228 | */ | - | ||||||||||||
| 229 | bool QTouchDevicePrivate::isRegistered(const QTouchDevice *dev) | - | ||||||||||||
| 230 | { | - | ||||||||||||
| 231 | QMutexLocker locker(&devicesMutex); | - | ||||||||||||
| 232 | return deviceList()->contains(dev); never executed: return deviceList()->contains(dev); | 0 | ||||||||||||
| 233 | } | - | ||||||||||||
| 234 | - | |||||||||||||
| 235 | /*! | - | ||||||||||||
| 236 | \internal | - | ||||||||||||
| 237 | */ | - | ||||||||||||
| 238 | void QTouchDevicePrivate::registerDevice(const QTouchDevice *dev) | - | ||||||||||||
| 239 | { | - | ||||||||||||
| 240 | QMutexLocker lock(&devicesMutex); | - | ||||||||||||
| 241 | if (deviceList()->isEmpty())
| 0 | ||||||||||||
| 242 | qAddPostRoutine(cleanupDevicesList); never executed: qAddPostRoutine(cleanupDevicesList); | 0 | ||||||||||||
| 243 | deviceList()->append(dev); | - | ||||||||||||
| 244 | } never executed: end of block | 0 | ||||||||||||
| 245 | - | |||||||||||||
| 246 | /*! | - | ||||||||||||
| 247 | \internal | - | ||||||||||||
| 248 | */ | - | ||||||||||||
| 249 | void QTouchDevicePrivate::unregisterDevice(const QTouchDevice *dev) | - | ||||||||||||
| 250 | { | - | ||||||||||||
| 251 | QMutexLocker lock(&devicesMutex); | - | ||||||||||||
| 252 | bool wasRemoved = deviceList()->removeOne(dev); | - | ||||||||||||
| 253 | if (wasRemoved && deviceList()->isEmpty())
| 0 | ||||||||||||
| 254 | qRemovePostRoutine(cleanupDevicesList); never executed: qRemovePostRoutine(cleanupDevicesList); | 0 | ||||||||||||
| 255 | } never executed: end of block | 0 | ||||||||||||
| 256 | - | |||||||||||||
| 257 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||
| 258 | QDebug operator<<(QDebug debug, const QTouchDevice *device) | - | ||||||||||||
| 259 | { | - | ||||||||||||
| 260 | QDebugStateSaver saver(debug); | - | ||||||||||||
| 261 | debug.nospace(); | - | ||||||||||||
| 262 | debug.noquote(); | - | ||||||||||||
| 263 | debug << "QTouchDevice("; | - | ||||||||||||
| 264 | if (device) {
| 0 | ||||||||||||
| 265 | debug << '"' << device->name() << "\", type="; | - | ||||||||||||
| 266 | QtDebugUtils::formatQEnum(debug, device->type()); | - | ||||||||||||
| 267 | debug << ", capabilities="; | - | ||||||||||||
| 268 | QtDebugUtils::formatQFlags(debug, device->capabilities()); | - | ||||||||||||
| 269 | debug << ", maximumTouchPoints=" << device->maximumTouchPoints(); | - | ||||||||||||
| 270 | } else { never executed: end of block | 0 | ||||||||||||
| 271 | debug << '0'; | - | ||||||||||||
| 272 | } never executed: end of block | 0 | ||||||||||||
| 273 | debug << ')'; | - | ||||||||||||
| 274 | return debug; never executed: return debug; | 0 | ||||||||||||
| 275 | } | - | ||||||||||||
| 276 | #endif // !QT_NO_DEBUG_STREAM | - | ||||||||||||
| 277 | - | |||||||||||||
| 278 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |