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 plugins 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 "qdeclarativecamera_p.h"
41#include "qdeclarativecameraexposure_p.h"
42
43QT_BEGIN_NAMESPACE
44
45/*!
46 \qmltype CameraExposure
47 \instantiates QDeclarativeCameraExposure
48 \brief An interface for exposure related camera settings.
49 \ingroup multimedia_qml
50 \ingroup camera_qml
51 \inqmlmodule QtMultimedia
52
53 CameraExposure allows you to adjust exposure related settings
54 like aperture and shutter speed, metering and ISO speed.
55
56 It should not be constructed separately, instead the
57 \c exposure property of the a \l Camera should be used.
58
59 \qml
60
61 Camera {
62 id: camera
63
64 exposure.exposureCompensation: -1.0
65 exposure.exposureMode: Camera.ExposurePortrait
66 }
67
68 \endqml
69
70 Several settings have both an automatic and a manual mode. In
71 the automatic modes the camera software itself will decide what
72 a reasonable setting is, but in most cases these settings can
73 be overridden with a specific manual setting.
74
75 For example, to select automatic shutter speed selection:
76
77 \code
78 camera.exposure.setAutoShutterSpeed()
79 \endcode
80
81 Or for a specific shutter speed:
82
83 \code
84 camera.exposure.manualShutterSpeed = 0.01 // 10ms
85 \endcode
86
87 You can only choose one or the other mode.
88*/
89
90/*!
91 \internal
92 \class QDeclarativeCameraExposure
93 \brief The CameraExposure provides interface for exposure related camera settings.
94
95*/
96
97/*!
98 Construct a declarative camera exposure object using \a parent object.
99 */
100QDeclarativeCameraExposure::QDeclarativeCameraExposure(QCamera *camera, QObject *parent) :
101 QObject(parent)
102{
103 m_exposure = camera->exposure();
104
105 connect(sender: m_exposure, SIGNAL(isoSensitivityChanged(int)), receiver: this, SIGNAL(isoSensitivityChanged(int)));
106 connect(sender: m_exposure, SIGNAL(apertureChanged(qreal)), receiver: this, SIGNAL(apertureChanged(qreal)));
107 connect(sender: m_exposure, SIGNAL(shutterSpeedChanged(qreal)), receiver: this, SIGNAL(shutterSpeedChanged(qreal)));
108
109 connect(sender: m_exposure, SIGNAL(exposureCompensationChanged(qreal)), receiver: this, SIGNAL(exposureCompensationChanged(qreal)));
110 connect(sender: camera, signal: &QCamera::statusChanged, slot: [this](QCamera::Status status) {
111 if (status != QCamera::UnloadedStatus && status != QCamera::LoadedStatus
112 && status != QCamera::ActiveStatus) {
113 return;
114 }
115
116 emit supportedExposureModesChanged();
117 });
118}
119
120QDeclarativeCameraExposure::~QDeclarativeCameraExposure()
121{
122}
123/*!
124 \property QDeclarativeCameraExposure::exposureCompensation
125
126 This property holds the adjustment value for the automatically calculated exposure. The value is in EV units.
127 */
128/*!
129 \qmlproperty real QtMultimedia::CameraExposure::exposureCompensation
130
131 This property holds the adjustment value for the automatically calculated exposure. The value is
132 in EV units.
133 */
134qreal QDeclarativeCameraExposure::exposureCompensation() const
135{
136 return m_exposure->exposureCompensation();
137}
138
139void QDeclarativeCameraExposure::setExposureCompensation(qreal ev)
140{
141 m_exposure->setExposureCompensation(ev);
142}
143/*!
144 \property QDeclarativeCameraExposure::iso
145
146 This property holds the sensor's ISO sensitivity value.
147 */
148/*!
149 \qmlproperty int QtMultimedia::CameraExposure::iso
150
151 This property holds the sensor's ISO sensitivity value.
152 */
153int QDeclarativeCameraExposure::isoSensitivity() const
154{
155 return m_exposure->isoSensitivity();
156}
157/*!
158 \property QDeclarativeCameraExposure::shutterSpeed
159
160 This property holds the camera's shutter speed value in seconds.
161 To affect the shutter speed you can use the \l manualShutterSpeed
162 property and \l setAutoShutterSpeed().
163
164*/
165/*!
166 \qmlproperty real QtMultimedia::CameraExposure::shutterSpeed
167
168 This property holds the camera's current shutter speed value in seconds.
169 To affect the shutter speed you can use the \l manualShutterSpeed
170 property and \l setAutoShutterSpeed().
171
172*/
173qreal QDeclarativeCameraExposure::shutterSpeed() const
174{
175 return m_exposure->shutterSpeed();
176}
177/*!
178 \property QDeclarativeCameraExposure::aperture
179
180 This property holds the current lens aperture as an F number (the ratio of the focal length to effective aperture diameter).
181
182 \sa manualAperture, setAutoAperture()
183*/
184/*!
185 \qmlproperty real QtMultimedia::CameraExposure::aperture
186
187 This property holds the current lens aperture as an F number (the ratio of
188 the focal length to effective aperture diameter).
189
190 \sa manualAperture, setAutoAperture()
191*/
192qreal QDeclarativeCameraExposure::aperture() const
193{
194 return m_exposure->aperture();
195}
196/*!
197 \property QDeclarativeCameraExposure::manualIso
198
199 This property holds the ISO settings for capturing photos.
200
201 If the value is negative, the camera will
202 automatically determine an appropriate value.
203
204 \sa iso, setAutoIsoSensitivity()
205*/
206/*!
207 \qmlproperty real QtMultimedia::CameraExposure::manualIso
208
209 This property holds the ISO settings for capturing photos.
210
211 If a negative value is specified, the camera will
212 automatically determine an appropriate value.
213
214 \sa iso, setAutoIsoSensitivity()
215*/
216
217int QDeclarativeCameraExposure::manualIsoSensitivity() const
218{
219 return m_manualIso;
220}
221
222void QDeclarativeCameraExposure::setManualIsoSensitivity(int iso)
223{
224 m_manualIso = iso;
225 if (iso > 0)
226 m_exposure->setManualIsoSensitivity(iso);
227 else
228 m_exposure->setAutoIsoSensitivity();
229
230 emit manualIsoSensitivityChanged(iso);
231}
232/*!
233 \property QDeclarativeCameraExposure::manualShutterSpeed
234
235 This property holds the shutter speed value (in seconds).
236 If the value is less than zero, the camera automatically
237 determines an appropriate shutter speed.
238
239 \l shutterSpeed, setAutoShutterSpeed()
240*/
241/*!
242 \qmlproperty real QtMultimedia::CameraExposure::manualShutterSpeed
243
244 This property holds the shutter speed value (in seconds).
245 If the value is less than zero, the camera automatically
246 determines an appropriate shutter speed.
247
248 \l shutterSpeed, setAutoShutterSpeed()
249*/
250qreal QDeclarativeCameraExposure::manualShutterSpeed() const
251{
252 return m_manualShutterSpeed;
253}
254
255void QDeclarativeCameraExposure::setManualShutterSpeed(qreal speed)
256{
257 m_manualShutterSpeed = speed;
258 if (speed > 0)
259 m_exposure->setManualShutterSpeed(speed);
260 else
261 m_exposure->setAutoShutterSpeed();
262
263 emit manualShutterSpeedChanged(speed);
264}
265/*!
266 \property QDeclarativeCameraExposure::manualAperture
267
268 This property holds aperture (F number) value
269 for capturing photos.
270
271 If the value is less than zero,
272 the camera automatically determines an appropriate aperture value.
273
274 \l aperture, setAutoAperture()
275*/
276/*!
277 \qmlproperty real QtMultimedia::CameraExposure::manualAperture
278
279 This property holds the aperture (F number) value
280 for capturing photos.
281
282 If the value is less than zero, the camera automatically
283 determines an appropriate aperture value.
284
285 \l aperture, setAutoAperture()
286*/
287qreal QDeclarativeCameraExposure::manualAperture() const
288{
289 return m_manualAperture;
290}
291
292void QDeclarativeCameraExposure::setManualAperture(qreal aperture)
293{
294 m_manualAperture = aperture;
295 if (aperture > 0)
296 m_exposure->setManualAperture(aperture);
297 else
298 m_exposure->setAutoAperture();
299
300 emit manualApertureChanged(aperture);
301}
302
303/*!
304 \qmlmethod QtMultimedia::CameraExposure::setAutoAperture()
305 Turn on auto aperture selection. The manual aperture value is reset to -1.0
306 */
307void QDeclarativeCameraExposure::setAutoAperture()
308{
309 setManualAperture(-1.0);
310}
311
312/*!
313 \qmlmethod QtMultimedia::CameraExposure::setAutoShutterSpeed()
314 Turn on auto shutter speed selection. The manual shutter speed value is reset to -1.0
315 */
316void QDeclarativeCameraExposure::setAutoShutterSpeed()
317{
318 setManualShutterSpeed(-1.0);
319}
320
321/*!
322 \qmlmethod QtMultimedia::CameraExposure::setAutoIsoSensitivity()
323 Turn on auto ISO sensitivity selection. The manual ISO value is reset to -1.
324 */
325void QDeclarativeCameraExposure::setAutoIsoSensitivity()
326{
327 setManualIsoSensitivity(-1);
328}
329/*!
330 \property QDeclarativeCameraExposure::exposureMode
331
332 This property holds the camera exposure mode. The mode can one of the values in \l QCameraExposure::ExposureMode.
333*/
334/*!
335 \qmlproperty enumeration QtMultimedia::CameraExposure::exposureMode
336
337 This property holds the camera exposure mode.
338
339 The mode can be one of the following:
340
341 \table
342 \header \li Value \li Description
343 \row \li Camera.ExposureManual \li Manual mode.
344 \row \li Camera.ExposureAuto \li Automatic mode.
345 \row \li Camera.ExposureNight \li Night mode.
346 \row \li Camera.ExposureBacklight \li Backlight exposure mode.
347 \row \li Camera.ExposureSpotlight \li Spotlight exposure mode.
348 \row \li Camera.ExposureSports \li Spots exposure mode.
349 \row \li Camera.ExposureSnow \li Snow exposure mode.
350 \row \li Camera.ExposureBeach \li Beach exposure mode.
351 \row \li Camera.ExposureLargeAperture \li Use larger aperture with small depth of field.
352 \row \li Camera.ExposureSmallAperture \li Use smaller aperture.
353 \row \li Camera.ExposurePortrait \li Portrait exposure mode.
354 \row \li Camera.ExposureAction \li Action exposure mode. Since 5.5
355 \row \li Camera.ExposureLandscape \li Landscape exposure mode. Since 5.5
356 \row \li Camera.ExposureNightPortrait \li Night portrait exposure mode. Since 5.5
357 \row \li Camera.ExposureTheatre \li Theatre exposure mode. Since 5.5
358 \row \li Camera.ExposureSunset \li Sunset exposure mode. Since 5.5
359 \row \li Camera.ExposureSteadyPhoto \li Steady photo exposure mode. Since 5.5
360 \row \li Camera.ExposureFireworks \li Fireworks exposure mode. Since 5.5
361 \row \li Camera.ExposureParty \li Party exposure mode. Since 5.5
362 \row \li Camera.ExposureCandlelight \li Candlelight exposure mode. Since 5.5
363 \row \li Camera.ExposureBarcode \li Barcode exposure mode. Since 5.5
364 \row \li Camera.ExposureModeVendor \li The base value for device specific exposure modes.
365 \endtable
366*/
367
368QDeclarativeCameraExposure::ExposureMode QDeclarativeCameraExposure::exposureMode() const
369{
370 return QDeclarativeCameraExposure::ExposureMode(m_exposure->exposureMode());
371}
372
373void QDeclarativeCameraExposure::setExposureMode(QDeclarativeCameraExposure::ExposureMode mode)
374{
375 if (exposureMode() != mode) {
376 m_exposure->setExposureMode(QCameraExposure::ExposureMode(mode));
377 emit exposureModeChanged(exposureMode());
378 }
379}
380
381/*!
382 \qmlproperty list<ExposureMode> QtMultimedia::CameraExposure::supportedExposureModes
383
384 This property holds the supported exposure modes of the camera.
385
386 \since 5.11
387 \sa exposureMode
388 */
389QVariantList QDeclarativeCameraExposure::supportedExposureModes() const
390{
391 QVariantList supportedModes;
392
393 for (int i = int(ExposureAuto); i <= int(QCameraExposure::ExposureBarcode); ++i) {
394 if (m_exposure->isExposureModeSupported(mode: (QCameraExposure::ExposureMode) i))
395 supportedModes.append(t: QVariant(i));
396 }
397
398 return supportedModes;
399}
400
401/*!
402 \property QDeclarativeCameraExposure::spotMeteringPoint
403
404 This property holds the relative frame coordinates of the point to use
405 for exposure metering. This point is only used in spot metering mode, and it
406 typically defaults to the center \c (0.5, 0.5).
407 */
408/*!
409 \qmlproperty QPointF QtMultimedia::CameraExposure::spotMeteringPoint
410
411 The property holds the frame coordinates of the point to use for exposure metering.
412 This point is only used in spot metering mode, and it typically defaults
413 to the center \c (0.5, 0.5).
414 */
415
416QPointF QDeclarativeCameraExposure::spotMeteringPoint() const
417{
418 return m_exposure->spotMeteringPoint();
419}
420
421void QDeclarativeCameraExposure::setSpotMeteringPoint(const QPointF &point)
422{
423 QPointF oldPoint(spotMeteringPoint());
424 m_exposure->setSpotMeteringPoint(point);
425
426 if (oldPoint != spotMeteringPoint())
427 emit spotMeteringPointChanged(spotMeteringPoint());
428}
429/*!
430 \property QDeclarativeCameraExposure::meteringMode
431
432 This property holds the camera metering mode (how exposure is balanced).
433 The mode can be one of the constants in \l QCameraExposure::MeteringMode.
434*/
435/*!
436 \qmlproperty enumeration QtMultimedia::CameraExposure::meteringMode
437
438 This property holds the camera metering mode (how exposure is balanced).
439
440 The mode can be one of the following:
441
442 \table
443 \header \li Value \li Description
444 \row \li Camera.MeteringMatrix \li A matrix of sample points is used to measure exposure.
445 \row \li Camera.MeteringAverage \li An average is used to measure exposure.
446 \row \li Camera.MeteringSpot \li A specific location (\l spotMeteringPoint) is used to measure exposure.
447 \endtable
448*/
449QDeclarativeCameraExposure::MeteringMode QDeclarativeCameraExposure::meteringMode() const
450{
451 return QDeclarativeCameraExposure::MeteringMode(m_exposure->meteringMode());
452}
453
454void QDeclarativeCameraExposure::setMeteringMode(QDeclarativeCameraExposure::MeteringMode mode)
455{
456 QDeclarativeCameraExposure::MeteringMode oldMode = meteringMode();
457 m_exposure->setMeteringMode(QCameraExposure::MeteringMode(mode));
458 if (oldMode != meteringMode())
459 emit meteringModeChanged(meteringMode());
460}
461
462QT_END_NAMESPACE
463
464#include "moc_qdeclarativecameraexposure_p.cpp"
465

source code of qtmultimedia/src/imports/multimedia/qdeclarativecameraexposure.cpp