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 test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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 General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef MOCKCAMERAEXPOSURECONTROL_H
30#define MOCKCAMERAEXPOSURECONTROL_H
31
32#include "qcameraexposurecontrol.h"
33
34class MockCameraExposureControl : public QCameraExposureControl
35{
36 Q_OBJECT
37public:
38 MockCameraExposureControl(QObject *parent = 0):
39 QCameraExposureControl(parent),
40 m_aperture(2.8),
41 m_shutterSpeed(0.01),
42 m_isoSensitivity(100),
43 m_meteringMode(QCameraExposure::MeteringMatrix),
44 m_exposureCompensation(0),
45 m_exposureMode(QCameraExposure::ExposureAuto),
46 m_flashMode(QCameraExposure::FlashAuto),
47 m_spot(0.5, 0.5)
48 {
49 m_isoRanges << 100 << 200 << 400 << 800;
50 m_apertureRanges << 2.8 << 4.0 << 5.6 << 8.0 << 11.0 << 16.0;
51 m_shutterRanges << 0.001 << 0.01 << 0.1 << 1.0;
52 m_exposureRanges << -2.0 << 2.0;
53
54 const QCameraExposure::ExposureMode exposureModes[] = {
55 QCameraExposure::ExposureAuto,
56 QCameraExposure::ExposureManual,
57 QCameraExposure::ExposureBacklight,
58 QCameraExposure::ExposureNight,
59 QCameraExposure::ExposureSpotlight,
60 QCameraExposure::ExposureSports,
61 QCameraExposure::ExposureSnow,
62 QCameraExposure:: ExposureLargeAperture,
63 QCameraExposure::ExposureSmallAperture,
64 QCameraExposure::ExposurePortrait,
65 QCameraExposure::ExposureModeVendor,
66 QCameraExposure::ExposureBeach,
67 };
68
69 for (QCameraExposure::ExposureMode mode : exposureModes)
70 m_exposureModes << QVariant::fromValue<QCameraExposure::ExposureMode>(value: mode);
71
72 m_meteringModes << QVariant::fromValue<QCameraExposure::MeteringMode>(value: QCameraExposure::MeteringMatrix)
73 << QVariant::fromValue<QCameraExposure::MeteringMode>(value: QCameraExposure::MeteringSpot);
74 }
75
76 ~MockCameraExposureControl() {}
77
78 bool isParameterSupported(ExposureParameter parameter) const
79 {
80 switch (parameter) {
81 case QCameraExposureControl::ExposureMode:
82 case QCameraExposureControl::MeteringMode:
83 case QCameraExposureControl::ExposureCompensation:
84 case QCameraExposureControl::ISO:
85 case QCameraExposureControl::Aperture:
86 case QCameraExposureControl::ShutterSpeed:
87 case QCameraExposureControl::SpotMeteringPoint:
88 return true;
89 default:
90 return false;
91 }
92 }
93
94 QVariant requestedValue(ExposureParameter param) const
95 {
96 return m_requestedParameters.value(akey: param);
97 }
98
99 QVariant actualValue(ExposureParameter param) const
100 {
101 switch (param) {
102 case QCameraExposureControl::ExposureMode:
103 return QVariant::fromValue<QCameraExposure::ExposureMode>(value: m_exposureMode);
104 case QCameraExposureControl::MeteringMode:
105 return QVariant::fromValue<QCameraExposure::MeteringMode>(value: m_meteringMode);
106 case QCameraExposureControl::ExposureCompensation:
107 return QVariant(m_exposureCompensation);
108 case QCameraExposureControl::ISO:
109 return QVariant(m_isoSensitivity);
110 case QCameraExposureControl::Aperture:
111 return QVariant(m_aperture);
112 case QCameraExposureControl::ShutterSpeed:
113 return QVariant(m_shutterSpeed);
114 case QCameraExposureControl::SpotMeteringPoint:
115 return QVariant(m_spot);
116 default:
117 return QVariant();
118 }
119 }
120
121 QVariantList supportedParameterRange(ExposureParameter parameter, bool *continuous) const
122 {
123 *continuous = false;
124
125 QVariantList res;
126 switch (parameter) {
127 case QCameraExposureControl::ExposureCompensation:
128 *continuous = true;
129 return m_exposureRanges;
130 case QCameraExposureControl::ISO:
131 return m_isoRanges;
132 case QCameraExposureControl::Aperture:
133 *continuous = true;
134 return m_apertureRanges;
135 case QCameraExposureControl::ShutterSpeed:
136 *continuous = true;
137 return m_shutterRanges;
138 case QCameraExposureControl::ExposureMode:
139 return m_exposureModes;
140 case QCameraExposureControl::MeteringMode:
141 return m_meteringModes;
142 default:
143 break;
144 }
145
146 return res;
147 }
148
149 // Added valueChanged and parameterRangeChanged signal
150 bool setValue(ExposureParameter param, const QVariant& value)
151 {
152 if (!isParameterSupported(parameter: param))
153 return false;
154
155 if (m_requestedParameters.value(akey: param) != value) {
156 m_requestedParameters.insert(key: param, value);
157 emit requestedValueChanged(parameter: param);
158 }
159
160 switch (param) {
161 case QCameraExposureControl::ExposureMode:
162 {
163 QCameraExposure::ExposureMode mode = value.value<QCameraExposure::ExposureMode>();
164 if (mode != m_exposureMode && m_exposureModes.contains(t: value)) {
165 m_exposureMode = mode;
166 emit actualValueChanged(parameter: param);
167 }
168 }
169 break;
170 case QCameraExposureControl::MeteringMode:
171 {
172 QCameraExposure::MeteringMode mode = value.value<QCameraExposure::MeteringMode>();
173 if (mode != m_meteringMode && m_meteringModes.contains(t: value)) {
174 m_meteringMode = mode;
175 emit actualValueChanged(parameter: param);
176 }
177 }
178 break;
179 case QCameraExposureControl::ExposureCompensation:
180 {
181 m_res.clear();
182 m_res << -4.0 << 4.0;
183 qreal exposureCompensationlocal = qBound<qreal>(min: -2.0, val: value.toReal(), max: 2.0);
184 if (actualValue(param).toReal() != exposureCompensationlocal) {
185 m_exposureCompensation = exposureCompensationlocal;
186 emit actualValueChanged(parameter: param);
187 }
188
189 if (m_exposureRanges.last().toReal() != m_res.last().toReal()) {
190 m_exposureRanges.clear();
191 m_exposureRanges = m_res;
192 emit parameterRangeChanged(parameter: param);
193 }
194 }
195 break;
196 case QCameraExposureControl::ISO:
197 {
198 m_res.clear();
199 m_res << 20 << 50;
200 qreal exposureCompensationlocal = 100*qRound(d: qBound(min: 100, val: value.toInt(), max: 800)/100.0);
201 if (actualValue(param).toReal() != exposureCompensationlocal) {
202 m_isoSensitivity = exposureCompensationlocal;
203 emit actualValueChanged(parameter: param);
204 }
205
206 if (m_isoRanges.last().toInt() != m_res.last().toInt()) {
207 m_isoRanges.clear();
208 m_isoRanges = m_res;
209 emit parameterRangeChanged(parameter: param);
210 }
211 }
212 break;
213 case QCameraExposureControl::Aperture:
214 {
215 m_res.clear();
216 m_res << 12.0 << 18.0 << 20.0;
217 qreal exposureCompensationlocal = qBound<qreal>(min: 2.8, val: value.toReal(), max: 16.0);
218 if (actualValue(param).toReal() != exposureCompensationlocal) {
219 m_aperture = exposureCompensationlocal;
220 emit actualValueChanged(parameter: param);
221 }
222
223 if (m_apertureRanges.last().toReal() != m_res.last().toReal()) {
224 m_apertureRanges.clear();
225 m_apertureRanges = m_res;
226 emit parameterRangeChanged(parameter: param);
227 }
228 }
229 break;
230 case QCameraExposureControl::ShutterSpeed:
231 {
232 m_res.clear();
233 m_res << 0.12 << 1.0 << 2.0;
234 qreal exposureCompensationlocal = qBound<qreal>(min: 0.001, val: value.toReal(), max: 1.0);
235 if (actualValue(param).toReal() != exposureCompensationlocal) {
236 m_shutterSpeed = exposureCompensationlocal;
237 emit actualValueChanged(parameter: param);
238 }
239
240 if (m_shutterRanges.last().toReal() != m_res.last().toReal()) {
241 m_shutterRanges.clear();
242 m_shutterRanges = m_res;
243 emit parameterRangeChanged(parameter: param);
244 }
245 }
246 break;
247
248 case QCameraExposureControl::SpotMeteringPoint:
249 {
250 static QRectF valid(0, 0, 1, 1);
251 if (valid.contains(p: value.toPointF())) {
252 m_spot = value.toPointF();
253 emit actualValueChanged(parameter: param);
254 return true;
255 }
256 return false;
257 }
258
259 default:
260 return false;
261 }
262
263 return true;
264 }
265
266private:
267 qreal m_aperture;
268 qreal m_shutterSpeed;
269 int m_isoSensitivity;
270 QCameraExposure::MeteringMode m_meteringMode;
271 qreal m_exposureCompensation;
272 QCameraExposure::ExposureMode m_exposureMode;
273 QCameraExposure::FlashModes m_flashMode;
274 QVariantList m_isoRanges,m_apertureRanges, m_shutterRanges, m_exposureRanges, m_res, m_exposureModes, m_meteringModes;
275 QPointF m_spot;
276
277 QMap<QCameraExposureControl::ExposureParameter, QVariant> m_requestedParameters;
278};
279
280#endif // MOCKCAMERAEXPOSURECONTROL_H
281

source code of qtmultimedia/tests/auto/unit/qmultimedia_common/mockcameraexposurecontrol.h