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 "qmlirproximitysensor.h" 41 #include <QtSensors/QIRProximitySensor> 42 43 /*! 44 \qmltype IRProximitySensor 45 \instantiates QmlIRProximitySensor 46 \ingroup qml-sensors_type 47 \inqmlmodule QtSensors 48 \since QtSensors 5.0 49 \inherits Sensor 50 \brief The IRProximitySensor element reports on infra-red reflectance values. 51 52 This element wraps the QIRProximitySensor class. Please see the documentation for 53 QIRProximitySensor for details. 54 55 \sa IRProximityReading 56 */ 57 QmlIRProximitySensor(QObject * parent)58QmlIRProximitySensor::QmlIRProximitySensor(QObject *parent) 59 : QmlSensor(parent) 60 , m_sensor(new QIRProximitySensor(this)) 61 { 62 } 63 ~QmlIRProximitySensor()64QmlIRProximitySensor::~QmlIRProximitySensor() 65 { 66 } 67 createReading() const68QmlSensorReading *QmlIRProximitySensor::createReading() const 69 { 70 return new QmlIRProximitySensorReading(m_sensor); 71 } 72 sensor() const73QSensor *QmlIRProximitySensor::sensor() const 74 { 75 return m_sensor; 76 } 77 78 /*! 79 \qmltype IRProximityReading 80 \instantiates QmlIRProximitySensorReading 81 \ingroup qml-sensors_reading 82 \inqmlmodule QtSensors 83 \since QtSensors 5.0 84 \inherits SensorReading 85 \brief The IRProximityReading element holds the most recent IR proximity reading. 86 87 The IRProximityReading element holds the most recent IR proximity reading. 88 89 This element wraps the QIRProximityReading class. Please see the documentation for 90 QIRProximityReading for details. 91 92 This element cannot be directly created. 93 */ 94 QmlIRProximitySensorReading(QIRProximitySensor * sensor)95QmlIRProximitySensorReading::QmlIRProximitySensorReading(QIRProximitySensor *sensor) 96 : QmlSensorReading(sensor) 97 , m_sensor(sensor) 98 { 99 } 100 ~QmlIRProximitySensorReading()101QmlIRProximitySensorReading::~QmlIRProximitySensorReading() 102 { 103 } 104 105 /*! 106 \qmlproperty qreal IRProximityReading::reflectance 107 This property holds the reflectance value. 108 109 Please see QIRProximityReading::reflectance for information about this property. 110 */ 111 reflectance() const112qreal QmlIRProximitySensorReading::reflectance() const 113 { 114 return m_reflectance; 115 } 116 reading() const117QSensorReading *QmlIRProximitySensorReading::reading() const 118 { 119 return m_sensor->reading(); 120 } 121 readingUpdate()122void QmlIRProximitySensorReading::readingUpdate() 123 { 124 qreal fl = m_sensor->reading()->reflectance(); 125 if (m_reflectance != fl) { 126 m_reflectance = fl; 127 Q_EMIT reflectanceChanged(); 128 } 129 } 130