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 "qmltiltsensor.h"
41#include <QtSensors/qtiltsensor.h>
42
43QT_BEGIN_NAMESPACE
44QT_END_NAMESPACE
45
46/*!
47 \qmltype TiltSensor
48 \instantiates QmlTiltSensor
49 \ingroup qml-sensors_type
50 \inqmlmodule QtSensors
51 \since QtSensors 5.0
52 \inherits Sensor
53 \brief The TiltSensor element reports tilt events
54 along the X and Y axes.
55
56 The TiltSensor element reports tilt events along the X and Y axes.
57
58 This element wraps the QTiltSensor class. Please see the documentation for
59 QTiltSensor for details.
60
61 \sa TiltReading
62*/
63
64QmlTiltSensor::QmlTiltSensor(QObject *parent)
65 : QmlSensor(parent)
66 , m_sensor(new QTiltSensor(this))
67{
68}
69
70QmlTiltSensor::~QmlTiltSensor()
71{
72}
73
74QmlSensorReading *QmlTiltSensor::createReading() const
75{
76 return new QmlTiltSensorReading(m_sensor);
77}
78
79QSensor *QmlTiltSensor::sensor() const
80{
81 return m_sensor;
82}
83
84/*!
85 \qmlmethod TiltSensor::calibrate()
86 Calibrate the tilt sensor.
87
88 Please see QTiltSensor::calibrate() for information about this property.
89*/
90void QmlTiltSensor::calibrate()
91{
92 m_sensor->calibrate();
93}
94
95/*!
96 \qmltype TiltReading
97 \instantiates QmlTiltSensorReading
98 \ingroup qml-sensors_reading
99 \inqmlmodule QtSensors
100 \since QtSensors 5.0
101 \inherits SensorReading
102 \brief The TiltReading element holds the most recent TiltSensor reading.
103
104 The TiltReading element holds the most recent TiltSensor reading.
105
106 This element wraps the QTiltReading class. Please see the documentation for
107 QTiltReading for details.
108
109 This element cannot be directly created.
110*/
111
112QmlTiltSensorReading::QmlTiltSensorReading(QTiltSensor *sensor)
113 : QmlSensorReading(sensor)
114 , m_sensor(sensor)
115{
116}
117
118QmlTiltSensorReading::~QmlTiltSensorReading()
119{
120}
121
122/*!
123 \qmlproperty qreal TiltReading::yRotation
124 This property holds the amount of tilt on the Y axis.
125
126 Please see QTiltReading::yRotation for information about this property.
127*/
128
129qreal QmlTiltSensorReading::yRotation() const
130{
131 return m_yRotation;
132}
133
134/*!
135 \qmlproperty qreal TiltReading::xRotation
136 This property holds the amount of tilt on the X axis.
137
138 Please see QTiltReading::xRotation for information about this property.
139*/
140
141qreal QmlTiltSensorReading::xRotation() const
142{
143 return m_xRotation;
144}
145
146QSensorReading *QmlTiltSensorReading::reading() const
147{
148 return m_sensor->reading();
149}
150
151void QmlTiltSensorReading::readingUpdate()
152{
153 qreal tiltY = m_sensor->reading()->yRotation();
154 if (m_yRotation != tiltY) {
155 m_yRotation = tiltY;
156 Q_EMIT yRotationChanged();
157 }
158 qreal tiltX = m_sensor->reading()->xRotation();
159 if (m_xRotation != tiltX) {
160 m_xRotation = tiltX;
161 Q_EMIT xRotationChanged();
162 }
163}
164

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