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 "qlightsensor.h"
5#include "qlightsensor_p.h"
6
7QT_BEGIN_NAMESPACE
8
9IMPLEMENT_READING(QLightReading)
10
11/*!
12 \class QLightReading
13 \ingroup sensors_reading
14 \inmodule QtSensors
15 \since 5.1
16
17 \brief The QLightReading class represents one reading from the
18 light sensor.
19
20 \section2 QLightReading Units
21 The light sensor returns the intensity of the light in lux.
22*/
23
24/*!
25 \property QLightReading::lux
26 \brief the light level.
27
28 Measured as lux.
29 \sa {QLightReading Units}
30*/
31
32qreal QLightReading::lux() const
33{
34 return d->lux;
35}
36
37/*!
38 Sets the light level to \a lux.
39*/
40void QLightReading::setLux(qreal lux)
41{
42 d->lux = lux;
43}
44
45// =====================================================================
46
47/*!
48 \class QLightFilter
49 \ingroup sensors_filter
50 \inmodule QtSensors
51 \since 5.1
52
53 \brief The QLightFilter class is a convenience wrapper around QSensorFilter.
54
55 The only difference is that the filter() method features a pointer to QLightReading
56 instead of QSensorReading.
57*/
58
59/*!
60 \fn QLightFilter::filter(QLightReading *reading)
61
62 Called when \a reading changes. Returns false to prevent the reading from propagating.
63
64 \sa QSensorFilter::filter()
65*/
66
67bool QLightFilter::filter(QSensorReading *reading)
68{
69 return filter(reading: static_cast<QLightReading*>(reading));
70}
71
72char const * const QLightSensor::sensorType("QLightSensor");
73
74/*!
75 \class QLightSensor
76 \ingroup sensors_type
77 \inmodule QtSensors
78 \since 5.1
79
80 \brief The QLightSensor class is a convenience wrapper around QSensor.
81
82 The only behavioural difference is that this class sets the type properly.
83
84 This class also features a reading() function that returns a QLightReading instead of a QSensorReading.
85
86 For details about how the sensor works, see \l QLightReading.
87
88 \sa QLightReading
89*/
90
91/*!
92 Construct the sensor as a child of \a parent.
93*/
94QLightSensor::QLightSensor(QObject *parent)
95 : QSensor(QLightSensor::sensorType, *new QLightSensorPrivate, parent)
96{
97}
98
99/*!
100 Destroy the sensor. Stops the sensor if it has not already been stopped.
101*/
102QLightSensor::~QLightSensor()
103{
104}
105
106/*!
107 \fn QLightSensor::reading() const
108
109 Returns the reading class for this sensor.
110
111 \sa QSensor::reading()
112*/
113
114QLightReading *QLightSensor::reading() const
115{
116 return static_cast<QLightReading*>(QSensor::reading());
117}
118
119/*!
120 \property QLightSensor::fieldOfView
121 \brief a value indicating the field of view.
122
123 This is an angle that represents the field of view of the sensor.
124
125 Not all light sensor support retrieving their field of view. For sensors
126 that don't support this property, the value will be 0. Whether the field of
127 view is supported can be checked with QSensor::isFeatureSupported() and the
128 QSensor::FieldOfView flag.
129*/
130
131qreal QLightSensor::fieldOfView() const
132{
133 Q_D(const QLightSensor);
134 return d->fieldOfView;
135}
136
137/*!
138 \since 5.1
139
140 Sets the field of view to \a fieldOfView. This is to be called from the
141 backend.
142*/
143void QLightSensor::setFieldOfView(qreal fieldOfView)
144{
145 Q_D(QLightSensor);
146 if (d->fieldOfView != fieldOfView) {
147 d->fieldOfView = fieldOfView;
148 emit fieldOfViewChanged(fieldOfView);
149 }
150}
151
152QT_END_NAMESPACE
153
154#include "moc_qlightsensor.cpp"
155

source code of qtsensors/src/sensors/qlightsensor.cpp