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 "qambientlightsensor.h" |
41 | #include "qambientlightsensor_p.h" |
42 | |
43 | QT_BEGIN_NAMESPACE |
44 | |
45 | IMPLEMENT_READING(QAmbientLightReading) |
46 | |
47 | /*! |
48 | \class QAmbientLightReading |
49 | \ingroup sensors_reading |
50 | \inmodule QtSensors |
51 | \since 5.1 |
52 | |
53 | \brief The QAmbientLightReading class represents one reading from the |
54 | ambient light sensor. |
55 | |
56 | \section2 QAmbientLightReading Units |
57 | The ambient light sensor returns the intensity of the ambient light |
58 | using the pre-defined values found in the QAmbientLightReading::LightLevel |
59 | enum. |
60 | */ |
61 | |
62 | /*! |
63 | \enum QAmbientLightReading::LightLevel |
64 | |
65 | This enum represents the ambient light level. |
66 | |
67 | \value Undefined The light level is unknown. |
68 | \value Dark It is dark. |
69 | \value Twilight It is moderately dark. |
70 | \value Light It is light (eg. internal lights). |
71 | \value Bright It is bright (eg. shade). |
72 | \value Sunny It is very bright (eg. direct sunlight). |
73 | */ |
74 | |
75 | /*! |
76 | \property QAmbientLightReading::lightLevel |
77 | \brief the ambient light level. |
78 | |
79 | The value represents the ambient light and comes from QAmbientLightReading::LightLevel. |
80 | \sa {QAmbientLightReading Units} |
81 | */ |
82 | |
83 | QAmbientLightReading::LightLevel QAmbientLightReading::lightLevel() const |
84 | { |
85 | return static_cast<LightLevel>(d->lightLevel); |
86 | } |
87 | |
88 | /*! |
89 | Sets the ambient light level to \a lightLevel. |
90 | */ |
91 | void QAmbientLightReading::setLightLevel(QAmbientLightReading::LightLevel lightLevel) |
92 | { |
93 | switch (lightLevel) { |
94 | case Dark: |
95 | case Twilight: |
96 | case Light: |
97 | case Bright: |
98 | case Sunny: |
99 | d->lightLevel = lightLevel; |
100 | break; |
101 | default: |
102 | d->lightLevel = Undefined; |
103 | break; |
104 | } |
105 | } |
106 | |
107 | // ===================================================================== |
108 | |
109 | /*! |
110 | \class QAmbientLightFilter |
111 | \ingroup sensors_filter |
112 | \inmodule QtSensors |
113 | \since 5.1 |
114 | |
115 | \brief The QAmbientLightFilter class is a convenience wrapper around QSensorFilter. |
116 | |
117 | The only difference is that the filter() method features a pointer to QAmbientLightReading |
118 | instead of QSensorReading. |
119 | */ |
120 | |
121 | /*! |
122 | \fn QAmbientLightFilter::filter(QAmbientLightReading *reading) |
123 | |
124 | Called when \a reading changes. Returns false to prevent the reading from propagating. |
125 | |
126 | \sa QSensorFilter::filter() |
127 | */ |
128 | |
129 | bool QAmbientLightFilter::filter(QSensorReading *reading) |
130 | { |
131 | return filter(reading: static_cast<QAmbientLightReading*>(reading)); |
132 | } |
133 | |
134 | char const * const QAmbientLightSensor::type("QAmbientLightSensor" ); |
135 | |
136 | /*! |
137 | \class QAmbientLightSensor |
138 | \ingroup sensors_type |
139 | \inmodule QtSensors |
140 | \since 5.1 |
141 | |
142 | \brief The QAmbientLightSensor class is a convenience wrapper around QSensor. |
143 | |
144 | The only behavioural difference is that this class sets the type properly. |
145 | |
146 | This class also features a reading() function that returns a QAmbientLightReading instead of a QSensorReading. |
147 | |
148 | For details about how the sensor works, see \l QAmbientLightReading. |
149 | |
150 | \sa QAmbientLightReading |
151 | */ |
152 | |
153 | /*! |
154 | Construct the sensor as a child of \a parent. |
155 | */ |
156 | QAmbientLightSensor::QAmbientLightSensor(QObject *parent) |
157 | : QSensor(QAmbientLightSensor::type, parent) |
158 | { |
159 | } |
160 | |
161 | /*! |
162 | Destroy the sensor. Stops the sensor if it has not already been stopped. |
163 | */ |
164 | QAmbientLightSensor::~QAmbientLightSensor() |
165 | { |
166 | } |
167 | |
168 | /*! |
169 | \fn QAmbientLightSensor::reading() const |
170 | |
171 | Returns the reading class for this sensor. |
172 | |
173 | \sa QSensor::reading() |
174 | */ |
175 | |
176 | QAmbientLightReading *QAmbientLightSensor::reading() const |
177 | { |
178 | return static_cast<QAmbientLightReading*>(QSensor::reading()); |
179 | } |
180 | |
181 | QT_END_NAMESPACE |
182 | |
183 | #include "moc_qambientlightsensor.cpp" |
184 | |