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 QtSensors 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 "qtapsensor.h" |
41 | #include "qtapsensor_p.h" |
42 | |
43 | QT_BEGIN_NAMESPACE |
44 | |
45 | IMPLEMENT_READING(QTapReading) |
46 | |
47 | /*! |
48 | \class QTapReading |
49 | \ingroup sensors_reading |
50 | \inmodule QtSensors |
51 | \since 5.1 |
52 | |
53 | \brief The QTapReading class represents one reading from the |
54 | tap sensor. |
55 | |
56 | \section2 QTapReading Units |
57 | The tap sensor registers tap events along the 3 axes that originate from the phone. |
58 | The axes are arranged as follows. |
59 | |
60 | \image sensors-coordinates2.jpg |
61 | |
62 | By default it returns only double tap events. The QTapSensor::returnDoubleTapEvents property |
63 | must be set to false to return individual tap events. |
64 | */ |
65 | |
66 | /*! |
67 | \enum QTapReading::TapDirection |
68 | |
69 | The tap direction is indicated using flags. Applications should check for the presence of |
70 | a particular flag as multiple flags may be set at once. |
71 | |
72 | The X, Y and Z flags allow an app to check for taps along an axis without caring about the |
73 | direction. |
74 | |
75 | \code |
76 | if (reading->tapDirection()&QTapReading::X) { |
77 | ... |
78 | } |
79 | \endcode |
80 | |
81 | The *_Pos and *_Neg flags allow checking for taps in a specific direction. Note that some |
82 | devices cannot determine the direction of a tap and will set both the _Pos and _Neg flag for |
83 | the detected axis. Previous versions of the API did not allow this. Applications that check |
84 | for the _Pos and _Neg flags as values should be updated so they can work with all devices. |
85 | |
86 | \oldcode |
87 | if (reading->tapDirection() == QTapReading::X_Pos) { |
88 | ... |
89 | } |
90 | \newcode |
91 | if (reading->tapDirection()&QTapReading::X_Pos) { |
92 | ... |
93 | } |
94 | \endcode |
95 | |
96 | \value Undefined This value means that the direction is unknown. |
97 | \value X This flag is set if the tap was along the X axis. |
98 | \value Y This flag is set if the tap was along the Y axis. |
99 | \value Z This flag is set if the tap was along the Z axis. |
100 | \value X_Pos This flag is set if the tap was towards the positive X direction. |
101 | \value Y_Pos This flag is set if the tap was towards the positive Y direction. |
102 | \value Z_Pos This flag is set if the tap was towards the positive Z direction. |
103 | \value X_Neg This flag is set if the tap was towards the negative X direction. |
104 | \value Y_Neg This flag is set if the tap was towards the negative Y direction. |
105 | \value Z_Neg This flag is set if the tap was towards the negative Z direction. |
106 | \value X_Both Equivalent to \c{X_Pos|X_Neg}. Returned by devices that cannot detect the direction of a tap. |
107 | \value Y_Both Equivalent to \c{Y_Pos|Y_Neg}. Returned by devices that cannot detect the direction of a tap. |
108 | \value Z_Both Equivalent to \c{Z_Pos|Z_Neg}. Returned by devices that cannot detect the direction of a tap. |
109 | */ |
110 | |
111 | /*! |
112 | \property QTapReading::tapDirection |
113 | \brief the direction of the tap. |
114 | |
115 | \sa {QTapReading Units} |
116 | */ |
117 | |
118 | QTapReading::TapDirection QTapReading::tapDirection() const |
119 | { |
120 | return static_cast<QTapReading::TapDirection>(d->tapDirection); |
121 | } |
122 | |
123 | /*! |
124 | Sets the tap direction to \a tapDirection. |
125 | */ |
126 | void QTapReading::setTapDirection(QTapReading::TapDirection tapDirection) |
127 | { |
128 | switch (tapDirection) { |
129 | case X_Pos: |
130 | case Y_Pos: |
131 | case Z_Pos: |
132 | case X_Neg: |
133 | case Y_Neg: |
134 | case Z_Neg: |
135 | case X_Both: |
136 | case Y_Both: |
137 | case Z_Both: |
138 | d->tapDirection = tapDirection; |
139 | break; |
140 | default: |
141 | d->tapDirection = Undefined; |
142 | break; |
143 | } |
144 | } |
145 | |
146 | /*! |
147 | \property QTapReading::doubleTap |
148 | \brief a value indicating if there was a single or double tap. |
149 | |
150 | \list |
151 | \li true - double tap |
152 | \li false - single tap |
153 | \endlist |
154 | \sa {QTapReading Units} |
155 | */ |
156 | |
157 | bool QTapReading::isDoubleTap() const |
158 | { |
159 | return d->doubleTap; |
160 | } |
161 | |
162 | /*! |
163 | Sets the double tap status of the reading to \a doubleTap. |
164 | */ |
165 | void QTapReading::setDoubleTap(bool doubleTap) |
166 | { |
167 | d->doubleTap = doubleTap; |
168 | } |
169 | |
170 | // ===================================================================== |
171 | |
172 | /*! |
173 | \class QTapFilter |
174 | \ingroup sensors_filter |
175 | \inmodule QtSensors |
176 | \since 5.1 |
177 | |
178 | \brief The QTapFilter class is a convenience wrapper around QSensorFilter. |
179 | |
180 | The only difference is that the filter() method features a pointer to QTapReading |
181 | instead of QSensorReading. |
182 | */ |
183 | |
184 | /*! |
185 | \fn QTapFilter::filter(QTapReading *reading) |
186 | |
187 | Called when \a reading changes. Returns false to prevent the reading from propagating. |
188 | |
189 | \sa QSensorFilter::filter() |
190 | */ |
191 | |
192 | bool QTapFilter::filter(QSensorReading *reading) |
193 | { |
194 | return filter(reading: static_cast<QTapReading*>(reading)); |
195 | } |
196 | |
197 | char const * const QTapSensor::type("QTapSensor" ); |
198 | |
199 | /*! |
200 | \class QTapSensor |
201 | \ingroup sensors_type |
202 | \inmodule QtSensors |
203 | \since 5.1 |
204 | |
205 | \brief The QTapSensor class is a convenience wrapper around QSensor. |
206 | |
207 | The only behavioural difference is that this class sets the type properly. |
208 | |
209 | This class also features a reading() function that returns a QTapReading instead of a QSensorReading. |
210 | |
211 | For details about how the sensor works, see \l QTapReading. |
212 | |
213 | \sa QTapReading |
214 | */ |
215 | |
216 | /*! |
217 | Construct the sensor as a child of \a parent. |
218 | */ |
219 | QTapSensor::QTapSensor(QObject *parent) |
220 | : QSensor(QTapSensor::type, *new QTapSensorPrivate, parent) |
221 | { |
222 | } |
223 | |
224 | /*! |
225 | Destroy the sensor. Stops the sensor if it has not already been stopped. |
226 | */ |
227 | QTapSensor::~QTapSensor() |
228 | { |
229 | } |
230 | |
231 | /*! |
232 | \fn QTapSensor::reading() const |
233 | |
234 | Returns the reading class for this sensor. |
235 | |
236 | \sa QSensor::reading() |
237 | */ |
238 | |
239 | QTapReading *QTapSensor::reading() const |
240 | { |
241 | return static_cast<QTapReading*>(QSensor::reading()); |
242 | } |
243 | |
244 | /*! |
245 | \property QTapSensor::returnDoubleTapEvents |
246 | \brief a value indicating if double tap events should be reported. |
247 | |
248 | Set to true (the default) to have the sensor report only on double tap events. |
249 | Set to false to have the sensor report only on individual tap events. |
250 | |
251 | It is not possible to have the sensor report both single and double tap events. |
252 | If both are needed the app should create 2 sensor objects. |
253 | |
254 | The property must be set before calling start(). |
255 | */ |
256 | |
257 | bool QTapSensor::returnDoubleTapEvents() const |
258 | { |
259 | Q_D(const QTapSensor); |
260 | return d->returnDoubleTapEvents; |
261 | } |
262 | |
263 | void QTapSensor::setReturnDoubleTapEvents(bool returnDoubleTapEvents) |
264 | { |
265 | Q_D(QTapSensor); |
266 | if (d->returnDoubleTapEvents != returnDoubleTapEvents) { |
267 | d->returnDoubleTapEvents = returnDoubleTapEvents; |
268 | emit returnDoubleTapEventsChanged(returnDoubleTapEvents); |
269 | } |
270 | } |
271 | |
272 | QT_END_NAMESPACE |
273 | |
274 | #include "moc_qtapsensor.cpp" |
275 | |