1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qmlproximitysensor_p.h" |
5 | #include <QtSensors/QProximitySensor> |
6 | |
7 | /*! |
8 | \qmltype ProximitySensor |
9 | //! \instantiates QmlProximitySensor |
10 | \ingroup qml-sensors_type |
11 | \inqmlmodule QtSensors |
12 | \since QtSensors 5.0 |
13 | \inherits Sensor |
14 | \brief The ProximitySensor element reports on object proximity. |
15 | |
16 | The ProximitySensor element reports on object proximity. |
17 | |
18 | This element wraps the QProximitySensor class. Please see the documentation for |
19 | QProximitySensor for details. |
20 | |
21 | \sa ProximityReading |
22 | */ |
23 | |
24 | QmlProximitySensor::QmlProximitySensor(QObject *parent) |
25 | : QmlSensor(parent) |
26 | , m_sensor(new QProximitySensor(this)) |
27 | { |
28 | } |
29 | |
30 | QmlProximitySensor::~QmlProximitySensor() |
31 | { |
32 | } |
33 | |
34 | QmlSensorReading *QmlProximitySensor::createReading() const |
35 | { |
36 | return new QmlProximitySensorReading(m_sensor); |
37 | } |
38 | |
39 | QSensor *QmlProximitySensor::sensor() const |
40 | { |
41 | return m_sensor; |
42 | } |
43 | |
44 | /*! |
45 | \qmltype ProximityReading |
46 | //! \instantiates QmlProximitySensorReading |
47 | \ingroup qml-sensors_reading |
48 | \inqmlmodule QtSensors |
49 | \since QtSensors 5.0 |
50 | \inherits SensorReading |
51 | \brief The ProximityReading element holds the most recent ProximitySensor reading. |
52 | |
53 | The ProximityReading element holds the most recent ProximitySensor reading. |
54 | |
55 | This element wraps the QProximityReading class. Please see the documentation for |
56 | QProximityReading for details. |
57 | |
58 | This element cannot be directly created. |
59 | */ |
60 | |
61 | QmlProximitySensorReading::QmlProximitySensorReading(QProximitySensor *sensor) |
62 | : m_sensor(sensor) |
63 | { |
64 | } |
65 | |
66 | QmlProximitySensorReading::~QmlProximitySensorReading() |
67 | { |
68 | } |
69 | |
70 | /*! |
71 | \qmlproperty bool ProximityReading::near |
72 | This property holds a value indicating if something is near. |
73 | |
74 | Please see QProximityReading::near for information about this property. |
75 | */ |
76 | |
77 | bool QmlProximitySensorReading::near() const |
78 | { |
79 | return m_near; |
80 | } |
81 | |
82 | QBindable<bool> QmlProximitySensorReading::bindableNear() const |
83 | { |
84 | return &m_near; |
85 | } |
86 | |
87 | QSensorReading *QmlProximitySensorReading::reading() const |
88 | { |
89 | return m_sensor->reading(); |
90 | } |
91 | |
92 | void QmlProximitySensorReading::readingUpdate() |
93 | { |
94 | m_near = m_sensor->reading()->close(); |
95 | } |
96 | |