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 "qmlambientlightsensor_p.h" |
5 | #include <QtSensors/QAmbientLightSensor> |
6 | |
7 | /*! |
8 | \qmltype AmbientLightSensor |
9 | //! \instantiates QmlAmbientLightSensor |
10 | \ingroup qml-sensors_type |
11 | \inqmlmodule QtSensors |
12 | \since QtSensors 5.0 |
13 | \inherits Sensor |
14 | \brief The AmbientLightSensor element repors on ambient lighting conditions. |
15 | |
16 | The AmbientLightSensor element repors on ambient lighting conditions. |
17 | |
18 | This element wraps the QAmbientLightSensor class. Please see the documentation for |
19 | QAmbientLightSensor for details. |
20 | |
21 | \sa AmbientLightReading |
22 | */ |
23 | |
24 | QmlAmbientLightSensor::QmlAmbientLightSensor(QObject *parent) |
25 | : QmlSensor(parent) |
26 | , m_sensor(new QAmbientLightSensor(this)) |
27 | { |
28 | } |
29 | |
30 | QmlAmbientLightSensor::~QmlAmbientLightSensor() |
31 | { |
32 | } |
33 | |
34 | QmlSensorReading *QmlAmbientLightSensor::createReading() const |
35 | { |
36 | return new QmlAmbientLightSensorReading(m_sensor); |
37 | } |
38 | |
39 | QSensor *QmlAmbientLightSensor::sensor() const |
40 | { |
41 | return m_sensor; |
42 | } |
43 | |
44 | /*! |
45 | \qmltype AmbientLightReading |
46 | //! \instantiates QmlAmbientLightSensorReading |
47 | \ingroup qml-sensors_reading |
48 | \inqmlmodule QtSensors |
49 | \since QtSensors 5.0 |
50 | \inherits SensorReading |
51 | \brief The AmbientLightReading element holds the most AmbientLightSensor reading. |
52 | |
53 | The AmbientLightReading element holds the most AmbientLightSensor reading. |
54 | |
55 | This element wraps the QAmbientLightReading class. Please see the documentation for |
56 | QAmbientLightReading for details. |
57 | |
58 | This element cannot be directly created. |
59 | */ |
60 | |
61 | QmlAmbientLightSensorReading::QmlAmbientLightSensorReading(QAmbientLightSensor *sensor) |
62 | : m_sensor(sensor) |
63 | { |
64 | } |
65 | |
66 | QmlAmbientLightSensorReading::~QmlAmbientLightSensorReading() |
67 | { |
68 | } |
69 | |
70 | /*! |
71 | \qmlproperty LightLevel AmbientLightReading::lightLevel |
72 | This property holds the ambient light level. |
73 | |
74 | Please see QAmbientLightReading::lightLevel for information about this property. |
75 | |
76 | Note that LightLevel constants are exposed through the AmbientLightReading class. |
77 | \code |
78 | AmbientLightSensor { |
79 | onReadingChanged: { |
80 | if (reading.lightLevel == AmbientLightReading.Dark) |
81 | // do something |
82 | } |
83 | } |
84 | \endcode |
85 | */ |
86 | |
87 | QAmbientLightReading::LightLevel QmlAmbientLightSensorReading::lightLevel() const |
88 | { |
89 | return m_lightLevel; |
90 | } |
91 | |
92 | QBindable<QAmbientLightReading::LightLevel> QmlAmbientLightSensorReading::bindableLightLevel() const |
93 | { |
94 | return &m_lightLevel; |
95 | } |
96 | |
97 | QSensorReading *QmlAmbientLightSensorReading::reading() const |
98 | { |
99 | return m_sensor->reading(); |
100 | } |
101 | |
102 | void QmlAmbientLightSensorReading::readingUpdate() |
103 | { |
104 | m_lightLevel = m_sensor->reading()->lightLevel(); |
105 | } |
106 |