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 "qambientlightsensor.h"
5#include "qambientlightsensor_p.h"
6
7QT_BEGIN_NAMESPACE
8
9IMPLEMENT_READING(QAmbientLightReading)
10
11/*!
12 \class QAmbientLightReading
13 \ingroup sensors_reading
14 \inmodule QtSensors
15 \since 5.1
16
17 \brief The QAmbientLightReading class represents one reading from the
18 ambient light sensor.
19
20 \section2 QAmbientLightReading Units
21 The ambient light sensor returns the intensity of the ambient light
22 using the pre-defined values found in the QAmbientLightReading::LightLevel
23 enum.
24*/
25
26/*!
27 \enum QAmbientLightReading::LightLevel
28
29 This enum represents the ambient light level.
30
31 \value Undefined The light level is unknown.
32 \value Dark It is dark.
33 \value Twilight It is moderately dark.
34 \value Light It is light (eg. internal lights).
35 \value Bright It is bright (eg. shade).
36 \value Sunny It is very bright (eg. direct sunlight).
37*/
38
39/*!
40 \property QAmbientLightReading::lightLevel
41 \brief the ambient light level.
42
43 The value represents the ambient light and comes from QAmbientLightReading::LightLevel.
44 \sa {QAmbientLightReading Units}
45*/
46
47QAmbientLightReading::LightLevel QAmbientLightReading::lightLevel() const
48{
49 return static_cast<LightLevel>(d->lightLevel);
50}
51
52/*!
53 Sets the ambient light level to \a lightLevel.
54*/
55void QAmbientLightReading::setLightLevel(QAmbientLightReading::LightLevel lightLevel)
56{
57 switch (lightLevel) {
58 case Dark:
59 case Twilight:
60 case Light:
61 case Bright:
62 case Sunny:
63 d->lightLevel = lightLevel;
64 break;
65 default:
66 d->lightLevel = Undefined;
67 break;
68 }
69}
70
71// =====================================================================
72
73/*!
74 \class QAmbientLightFilter
75 \ingroup sensors_filter
76 \inmodule QtSensors
77 \since 5.1
78
79 \brief The QAmbientLightFilter class is a convenience wrapper around QSensorFilter.
80
81 The only difference is that the filter() method features a pointer to QAmbientLightReading
82 instead of QSensorReading.
83*/
84
85/*!
86 \fn QAmbientLightFilter::filter(QAmbientLightReading *reading)
87
88 Called when \a reading changes. Returns false to prevent the reading from propagating.
89
90 \sa QSensorFilter::filter()
91*/
92
93bool QAmbientLightFilter::filter(QSensorReading *reading)
94{
95 return filter(reading: static_cast<QAmbientLightReading*>(reading));
96}
97
98char const * const QAmbientLightSensor::sensorType("QAmbientLightSensor");
99
100/*!
101 \class QAmbientLightSensor
102 \ingroup sensors_type
103 \inmodule QtSensors
104 \since 5.1
105
106 \brief The QAmbientLightSensor class is a convenience wrapper around QSensor.
107
108 The only behavioural difference is that this class sets the type properly.
109
110 This class also features a reading() function that returns a QAmbientLightReading instead of a QSensorReading.
111
112 For details about how the sensor works, see \l QAmbientLightReading.
113
114 \sa QAmbientLightReading
115*/
116
117/*!
118 Construct the sensor as a child of \a parent.
119*/
120QAmbientLightSensor::QAmbientLightSensor(QObject *parent)
121 : QSensor(QAmbientLightSensor::sensorType, parent)
122{
123}
124
125/*!
126 Destroy the sensor. Stops the sensor if it has not already been stopped.
127*/
128QAmbientLightSensor::~QAmbientLightSensor()
129{
130}
131
132/*!
133 \fn QAmbientLightSensor::reading() const
134
135 Returns the reading class for this sensor.
136
137 \sa QSensor::reading()
138*/
139
140QAmbientLightReading *QAmbientLightSensor::reading() const
141{
142 return static_cast<QAmbientLightReading*>(QSensor::reading());
143}
144
145QT_END_NAMESPACE
146
147#include "moc_qambientlightsensor.cpp"
148

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