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