| 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 "qmllightsensor_p.h" |
| 5 | #include <QtSensors/QLightSensor> |
| 6 | |
| 7 | /*! |
| 8 | \qmltype LightSensor |
| 9 | //! \nativetype QmlLightSensor |
| 10 | \ingroup qml-sensors_type |
| 11 | \inqmlmodule QtSensors |
| 12 | \since QtSensors 5.0 |
| 13 | \inherits Sensor |
| 14 | \brief The LightSensor element reports on light levels using LUX. |
| 15 | |
| 16 | The LightSensor element reports on light levels using LUX. |
| 17 | |
| 18 | This element wraps the QLightSensor class. Please see the documentation for |
| 19 | QLightSensor for details. |
| 20 | |
| 21 | \sa LightReading |
| 22 | */ |
| 23 | |
| 24 | QmlLightSensor::QmlLightSensor(QObject *parent) |
| 25 | : QmlSensor(parent) |
| 26 | , m_sensor(new QLightSensor(this)) |
| 27 | { |
| 28 | connect(sender: m_sensor, SIGNAL(fieldOfViewChanged(qreal)), |
| 29 | receiver: this, SIGNAL(fieldOfViewChanged(qreal))); |
| 30 | } |
| 31 | |
| 32 | QmlLightSensor::~QmlLightSensor() |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | QmlSensorReading *QmlLightSensor::createReading() const |
| 37 | { |
| 38 | return new QmlLightSensorReading(m_sensor); |
| 39 | } |
| 40 | |
| 41 | QSensor *QmlLightSensor::sensor() const |
| 42 | { |
| 43 | return m_sensor; |
| 44 | } |
| 45 | |
| 46 | /*! |
| 47 | \qmlproperty real LightSensor::fieldOfView |
| 48 | This property holds a value indicating the field of view. |
| 49 | |
| 50 | Please see QLightSensor::fieldOfView for information about this property. |
| 51 | */ |
| 52 | |
| 53 | qreal QmlLightSensor::fieldOfView() const |
| 54 | { |
| 55 | return m_sensor->fieldOfView(); |
| 56 | } |
| 57 | |
| 58 | /*! |
| 59 | \qmltype LightReading |
| 60 | //! \nativetype QmlLightSensorReading |
| 61 | \ingroup qml-sensors_reading |
| 62 | \inqmlmodule QtSensors |
| 63 | \since QtSensors 5.0 |
| 64 | \inherits SensorReading |
| 65 | \brief The LightReading element holds the most recent LightSensor reading. |
| 66 | |
| 67 | The LightReading element holds the most recent LightSensor reading. |
| 68 | |
| 69 | This element wraps the QLightReading class. Please see the documentation for |
| 70 | QLightReading for details. |
| 71 | |
| 72 | This element cannot be directly created. |
| 73 | */ |
| 74 | |
| 75 | QmlLightSensorReading::QmlLightSensorReading(QLightSensor *sensor) |
| 76 | : m_sensor(sensor) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | QmlLightSensorReading::~QmlLightSensorReading() |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | /*! |
| 85 | \qmlproperty real LightReading::illuminance |
| 86 | This property holds the light level. |
| 87 | |
| 88 | Please see QLightReading::illuminance for information about this property. |
| 89 | */ |
| 90 | |
| 91 | qreal QmlLightSensorReading::illuminance() const |
| 92 | { |
| 93 | return m_illuminance; |
| 94 | } |
| 95 | |
| 96 | QBindable<qreal> QmlLightSensorReading::bindableIlluminance() const |
| 97 | { |
| 98 | return &m_illuminance; |
| 99 | } |
| 100 | |
| 101 | QSensorReading *QmlLightSensorReading::reading() const |
| 102 | { |
| 103 | return m_sensor->reading(); |
| 104 | } |
| 105 | |
| 106 | void QmlLightSensorReading::readingUpdate() |
| 107 | { |
| 108 | m_illuminance = m_sensor->reading()->lux(); |
| 109 | } |
| 110 | |