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 "qmltapsensor.h"
41#include <QtSensors/QTapSensor>
42
43/*!
44 \qmltype TapSensor
45 \instantiates QmlTapSensor
46 \ingroup qml-sensors_type
47 \inqmlmodule QtSensors
48 \since QtSensors 5.0
49 \inherits Sensor
50 \brief The TapSensor element reports tap and double tap events
51 along the X, Y and Z axes.
52
53 The TapSensor element reports tap and double tap events
54 along the X, Y and Z axes.
55
56 This element wraps the QTapSensor class. Please see the documentation for
57 QTapSensor for details.
58
59 \sa TapReading
60*/
61
62QmlTapSensor::QmlTapSensor(QObject *parent)
63 : QmlSensor(parent)
64 , m_sensor(new QTapSensor(this))
65{
66 connect(sender: m_sensor, SIGNAL(returnDoubleTapEventsChanged(bool)),
67 receiver: this, SIGNAL(returnDoubleTapEventsChanged(bool)));
68}
69
70QmlTapSensor::~QmlTapSensor()
71{
72}
73
74QmlSensorReading *QmlTapSensor::createReading() const
75{
76 return new QmlTapSensorReading(m_sensor);
77}
78
79QSensor *QmlTapSensor::sensor() const
80{
81 return m_sensor;
82}
83
84/*!
85 \qmlproperty bool TapSensor::returnDoubleTapEvents
86 This property holds a value indicating if double tap events should be reported.
87
88 Please see QTapSensor::returnDoubleTapEvents for information about this property.
89*/
90
91bool QmlTapSensor::returnDoubleTapEvents() const
92{
93 return m_sensor->returnDoubleTapEvents();
94}
95
96void QmlTapSensor::setReturnDoubleTapEvents(bool ret)
97{
98 m_sensor->setReturnDoubleTapEvents(ret);
99}
100
101/*!
102 \qmltype TapReading
103 \instantiates QmlTapSensorReading
104 \ingroup qml-sensors_reading
105 \inqmlmodule QtSensors
106 \since QtSensors 5.0
107 \inherits SensorReading
108 \brief The TapReading element holds the most recent TapSensor reading.
109
110 The TapReading element holds the most recent TapSensor reading.
111
112 This element wraps the QTapReading class. Please see the documentation for
113 QTapReading for details.
114
115 This element cannot be directly created.
116*/
117
118QmlTapSensorReading::QmlTapSensorReading(QTapSensor *sensor)
119 : QmlSensorReading(sensor)
120 , m_sensor(sensor)
121{
122}
123
124QmlTapSensorReading::~QmlTapSensorReading()
125{
126}
127
128/*!
129 \qmlproperty TapDirection TapReading::tapDirection
130 This property holds the direction of the tap.
131
132 Please see QTapReading::tapDirection for information about this property.
133
134 Note that TapDirection constants are exposed through the TapReading class.
135 \code
136 TapSensor {
137 onReadingChanged: {
138 if ((reading.tapDirection & TapReading.X_Both))
139 // do something
140 }
141 }
142 \endcode
143*/
144
145QTapReading::TapDirection QmlTapSensorReading::tapDirection() const
146{
147 return m_tapDirection;
148}
149
150/*!
151 \qmlproperty bool TapReading::doubleTap
152 This property holds a value indicating if there was a single or double tap.
153
154 Please see QTapReading::doubleTap for information about this property.
155*/
156
157bool QmlTapSensorReading::isDoubleTap() const
158{
159 return m_isDoubleTap;
160}
161
162QSensorReading *QmlTapSensorReading::reading() const
163{
164 return const_cast<QTapSensor*>(m_sensor)->reading();
165}
166
167void QmlTapSensorReading::readingUpdate()
168{
169 QTapReading::TapDirection td = m_sensor->reading()->tapDirection();
170 if (m_tapDirection != td) {
171 m_tapDirection = td;
172 Q_EMIT tapDirectionChanged();
173 }
174 bool dTap = m_sensor->reading()->isDoubleTap();
175 if (m_isDoubleTap != dTap) {
176 m_isDoubleTap = dTap;
177 Q_EMIT isDoubleTapChanged();
178 }
179}
180

source code of qtsensors/src/imports/sensors/qmltapsensor.cpp