Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcamera.cpp
Go to the documentation of this file.
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
5#include "qcamera_p.h"
6
7#include <qcameradevice.h>
8#include <private/qplatformcamera_p.h>
9#include <private/qplatformimagecapture_p.h>
10#include <private/qplatformmediaintegration_p.h>
11#include <private/qplatformmediacapture_p.h>
12#include <qmediadevices.h>
13#include <qmediacapturesession.h>
14
15#include <QDebug>
16
18
19/*!
20 \class QCamera
21
22
23 \brief The QCamera class provides interface for system camera devices.
24
25 \inmodule QtMultimedia
26 \ingroup multimedia
27 \ingroup multimedia_camera
28
29 QCamera can be used within a QMediaCaptureSession for video recording and image taking.
30
31 You can use QCameraDevice to list available cameras and choose which one to use.
32
33 \snippet multimedia-snippets/camerasnippets.cpp Camera selection
34
35 \include qcamera-common.qdocinc {zoom} {Q}
36
37 \snippet multimedia-snippets/camerasnippets.cpp Camera zoom
38
39 \include qcamera-common.qdocinc {image-processing} {Q}
40
41 \snippet multimedia-snippets/camerasnippets.cpp Camera image whitebalance
42
43 For more information on image processing of camera frames, see
44 \l {camera_image_processing}{Camera Image Processing}.
45
46 \include qcamera-common.qdocinc {permission} {Q} {class}
47
48 \snippet multimedia-snippets/camerasnippets.cpp Camera permission
49
50 See the \l{Camera Overview}{camera overview} for more information.
51
52 \note On WebAssembly platform, due to its asynchronous nature,
53 QMediaDevices::videoInputsChanged() signal is emitted when the list of
54 video inputs is ready. User permissions are required. Works only on secure https contexts.
55*/
56
57/*!
58 \qmltype Camera
59 \nativetype QCamera
60 \inqmlmodule QtMultimedia
61 \brief An interface for camera settings related to focus and zoom.
62 \ingroup multimedia_qml
63 \ingroup camera_qml
64
65 The Camera element can be used within a \l CaptureSession for video recording
66 and image taking.
67
68 You can use \l MediaDevices to list available cameras and choose which one to use.
69
70 \snippet multimedia-snippets/camerasnippets.qml Camera selection
71
72 \include qcamera-common.qdocinc {zoom} {}
73
74 \snippet multimedia-snippets/camerasnippets.qml Camera zoom
75
76 \include qcamera-common.qdocinc {image-processing} {}
77
78 \snippet multimedia-snippets/camerasnippets.qml Camera image whitebalance
79
80 For more information on image processing of camera frames, see
81 \l {camera_image_processing}{Camera Image Processing}.
82
83 \include qcamera-common.qdocinc {permission} {} {component}
84
85 \snippet multimedia-snippets/camerasnippets.qml Camera permission
86
87 See the \l{Camera Overview}{camera overview} for more information.
88*/
89
90void QCameraPrivate::init(const QCameraDevice &device)
91{
92 Q_Q(QCamera);
93
94 auto maybeControl = QPlatformMediaIntegration::instance()->createCamera(q);
95 if (!maybeControl) {
96 qWarning() << "Failed to initialize QCamera" << maybeControl.error();
97 return;
98 }
99 control = maybeControl.value();
100 cameraDevice = !device.isNull() ? device : QMediaDevices::defaultVideoInput();
101 if (cameraDevice.isNull())
102 control->updateError(QCamera::CameraError, QStringLiteral("No camera detected"));
103 control->setCamera(cameraDevice);
104 q->connect(control, &QPlatformVideoSource::activeChanged, q, &QCamera::activeChanged);
105 q->connect(control, &QPlatformCamera::errorChanged, q, &QCamera::errorChanged);
106 q->connect(control, &QPlatformCamera::errorOccurred, q, &QCamera::errorOccurred);
107}
108
109/*!
110 Construct a QCamera with a \a parent.
111
112 Selects the default camera on the system if more than one camera is available.
113*/
114
115QCamera::QCamera(QObject *parent)
116 : QCamera(QMediaDevices::defaultVideoInput(), parent)
117{
118}
119
120/*!
121 \since 5.3
122
123 Construct a QCamera from a camera description \a cameraDevice and \a parent.
124*/
125
126QCamera::QCamera(const QCameraDevice &cameraDevice, QObject *parent)
127 : QObject(*new QCameraPrivate, parent)
128{
129 Q_D(QCamera);
130 d->init(cameraDevice);
131}
132
133/*!
134 \since 5.3
135
136 Construct a QCamera which uses a hardware camera located a the specified \a position.
137
138 For example on a mobile phone it can be used to easily choose between front-facing and
139 back-facing cameras.
140
141 If no camera is available at the specified \a position or if \a position is
142 QCameraDevice::UnspecifiedPosition, the default camera is used.
143*/
144
145QCamera::QCamera(QCameraDevice::Position position, QObject *parent)
146 : QObject(*new QCameraPrivate, parent)
147{
148 Q_D(QCamera);
149
150 QCameraDevice device;
151 auto cameras = QMediaDevices::videoInputs();
152 for (const auto &c : std::as_const(cameras)) {
153 if (c.position() == position) {
154 device = c;
155 break;
156 }
157 }
158 d->init(device);
159}
160
161/*!
162 Destroys the camera object.
163*/
164
165QCamera::~QCamera()
166{
167 Q_D(QCamera);
168 if (d->captureSession)
169 d->captureSession->setCamera(nullptr);
170}
171
172/*!
173 Returns true if the camera can be used.
174*/
175bool QCamera::isAvailable() const
176{
177 Q_D(const QCamera);
178 return d->control && !d->cameraDevice.isNull();
179}
180
181/*! \qmlproperty bool QtMultimedia::Camera::active
182
183 Describes whether the camera is currently active.
184*/
185
186/*! \property QCamera::active
187
188 Describes whether the camera is currently active.
189*/
190
191/*!
192 Returns true if the camera is currently active.
193*/
194bool QCamera::isActive() const
195{
196 Q_D(const QCamera);
197 return d->control && d->control->isActive();
198}
199
200/*!
201 Turns the camera on if \a active is \c{true}, or off if it's \c{false}.
202*/
203void QCamera::setActive(bool active)
204{
205 Q_D(const QCamera);
206 if (d->control)
207 d->control->setActive(active);
208}
209
210/*!
211 \qmlproperty enumeration QtMultimedia::Camera::error
212
213 Returns the error state of the camera.
214
215 \qmlenumeratorsfrom QCamera::Error
216*/
217
218/*!
219 \property QCamera::error
220
221 Returns the error state of the camera.
222
223 \sa QCamera::Error
224*/
225
226QCamera::Error QCamera::error() const
227{
228 Q_D(const QCamera);
229
230 return d->control ? d->control->error() : QCamera::CameraError;
231}
232
233/*!
234 \qmlproperty string QtMultimedia::Camera::errorString
235
236 Returns a human readable string describing a camera's error state.
237*/
238
239/*!
240 \property QCamera::errorString
241
242 Returns a human readable string describing a camera's error state.
243*/
244QString QCamera::errorString() const
245{
246 Q_D(const QCamera);
247
248 return d->control ? d->control->errorString()
249 : QStringLiteral("Camera is not supported on the platform");
250}
251
252/*! \enum QCamera::Feature
253
254 Describes a set of features supported by the camera. The returned value can be a
255 combination of:
256
257 \value ColorTemperature
258 The Camera supports setting a custom \l{colorTemperature}.
259 \value ExposureCompensation
260 The Camera supports setting a custom \l{exposureCompensation}.
261 \value IsoSensitivity
262 The Camera supports setting a custom \l{isoSensitivity}.
263 \value ManualExposureTime
264 The Camera supports setting a \l{QCamera::manualExposureTime}{manual exposure Time}.
265 \value CustomFocusPoint
266 The Camera supports setting a \l{QCamera::customFocusPoint}{custom focus point}.
267 \value FocusDistance
268 The Camera supports setting the \l{focusDistance} property.
269*/
270
271/*!
272 \qmlproperty enumeration QtMultimedia::Camera::supportedFeatures
273
274 Returns the features supported by this camera. The value is bitmask
275 that may contain any of the following flags. It stores an OR
276 combination of Feature values.
277
278 \qmlenumeratorsfrom QCamera::Feature
279*/
280
281/*!
282 \property QCamera::supportedFeatures
283
284 Returns the features supported by this camera.
285
286 \sa QCamera::Feature
287*/
288QCamera::Features QCamera::supportedFeatures() const
289{
290 Q_D(const QCamera);
291 return d->control ? d->control->supportedFeatures() : QCamera::Features{};
292}
293
294/*! \qmlmethod void Camera::start()
295
296 Starts the camera.
297
298 Same as setting the active property to true.
299
300 If the camera can't be started for some reason, the errorOccurred() signal is emitted.
301*/
302
303/*! \fn void QCamera::start()
304
305 Starts the camera.
306
307 Same as setActive(true).
308
309 If the camera can't be started for some reason, the errorOccurred() signal is emitted.
310*/
311
312/*! \qmlmethod void Camera::stop()
313
314 Stops the camera.
315 Same as setting the active property to false.
316*/
317
318/*! \fn void QCamera::stop()
319
320 Stops the camera.
321 Same as setActive(false).
322*/
323
324/*!
325 Returns the capture session this camera is connected to, or
326 a nullptr if the camera is not connected to a capture session.
327
328 use QMediaCaptureSession::setCamera() to connect the camera to
329 a session.
330*/
331QMediaCaptureSession *QCamera::captureSession() const
332{
333 Q_D(const QCamera);
334 return d->captureSession;
335}
336
337/*!
338 \internal
339*/
340void QCamera::setCaptureSession(QMediaCaptureSession *session)
341{
342 Q_D(QCamera);
343 d->captureSession = session;
344}
345
346/*!
347 \internal
348*/
349QPlatformCamera *QCamera::platformCamera()
350{
351 Q_D(const QCamera);
352 return d->control;
353}
354
355/*! \qmlproperty cameraDevice QtMultimedia::Camera::cameraDevice
356
357 Gets or sets the currently active camera device.
358
359 When switching camera devices, the \l Camera's capabilities are updated.
360 Additionally, the \l Camera's control properties (such as \l focusMode,
361 \l flashMode, \l focusDistance, \l zoomFactor) are updated as follows:
362
363 \list
364 \li If a property is supported on the new device, the property value is applied to the
365 camera device.
366 \li If a property is supported but its range of valid values was changed, the property
367 is clamped to the new range and applied to the camera device.
368 \li If the new camera device does not support a property, the property value is reset
369 to default, and no changes are made to the camera device.
370 \endlist
371*/
372
373/*!
374 \property QCamera::cameraDevice
375
376 Returns the QCameraDevice object associated with this camera.
377
378 When switching camera devices, the \l QCamera's capabilities are updated.
379 Additionally, the \l QCamera's control properties (such as \l focusMode,
380 \l flashMode, \l focusDistance, \l zoomFactor) are updated as follows:
381
382 \list
383 \li If a property is supported on the new device, the property value is applied to the
384 camera device.
385 \li If a property is supported but its range of valid values was changed, the property
386 is clamped to the new range and applied to the camera device.
387 \li If the new camera device does not support a property, the property value is reset
388 to default, and no changes are made to the camera device.
389 \endlist
390 */
391QCameraDevice QCamera::cameraDevice() const
392{
393 Q_D(const QCamera);
394 return d->cameraDevice;
395}
396
397/*!
398 Connects the camera object to the physical camera device described by
399 \a cameraDevice. Using a default constructed QCameraDevice object as
400 \a cameraDevice will connect the camera to the system default camera device.
401
402 When switching camera devices, the QCamera's capabilities are updated.
403 Additionally, the QCamera's control properties (such as \l focusMode,
404 \l flashMode, \l focusDistance, \l zoomFactor) are updated as follows:
405
406 \list
407 \li If a property is supported on the new device, the property value is applied to the
408 camera device.
409 \li If a property is supported but its range of valid values was changed, the property
410 is clamped to the new range and applied to the camera device.
411 \li If the new camera device does not support a property, the property value is reset
412 to default, and no changes are made to the camera device.
413 \endlist
414*/
415void QCamera::setCameraDevice(const QCameraDevice &cameraDevice)
416{
417 Q_D(QCamera);
418
419 if (!QPlatformMediaIntegration::instance()->isCameraSwitchingDuringRecordingSupported()
420 && d->captureSession && d->captureSession->recorder()
421 && d->captureSession->recorder()->recorderState() == QMediaRecorder::RecordingState) {
422 qWarning("This media backend does not support camera device switching during recording");
423 return;
424 }
425
426 auto dev = cameraDevice;
427 if (dev.isNull())
428 dev = QMediaDevices::defaultVideoInput();
429 if (d->cameraDevice == dev)
430 return;
431 d->cameraDevice = dev;
432 if (d->control)
433 d->control->setCamera(d->cameraDevice);
434 emit cameraDeviceChanged();
435 setCameraFormat({});
436}
437
438/*! \qmlproperty cameraFormat QtMultimedia::Camera::cameraFormat
439
440 Gets or sets the currently active camera format.
441
442 \note When using the FFMPEG backend on an Android target device if you request
443 \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
444 semi-planar NV12/NV21. This depends on the codec implemented by the device
445 OEM.
446
447 \note On macOS, camera-devices are shared across multiple
448 applications on the operating system. This means that another
449 application may override the format set by this property.
450 Application developers should account for receiving video frames
451 that have a different resolution, pixel format and framerate than
452 what is described by this property. This property does not change
453 when the device's format is modified by another application. The
454 format described by this property can be re-applied to the device
455 by re-activating the \l Camera.
456
457 \sa cameraDevice::videoFormats
458*/
459
460/*!
461 \property QCamera::cameraFormat
462
463 Returns the camera format currently used by the camera.
464
465 \note When using the FFMPEG backend on an Android target device if you request
466 \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
467 semi-planar NV12/NV21. This depends on the codec implemented by the device
468 OEM.
469
470 \note On macOS, camera-devices are shared across multiple
471 applications on the operating system. This means that another
472 application may override the format set by this property.
473 Application developers should account for receiving video frames
474 that have a different resolution, pixel format and framerate than
475 what is described by this property. This property does not change
476 when the device's format is modified by another application. The
477 format described by this property can be re-applied to the device
478 by re-activating the \l QCamera.
479
480 \sa QCameraDevice::videoFormats
481*/
482QCameraFormat QCamera::cameraFormat() const
483{
484 Q_D(const QCamera);
485 return d->cameraFormat;
486}
487
488/*!
489 Tells the camera to use the format described by \a format. This can be used to define
490 a specific resolution and frame rate to be used for recording and image capture.
491
492 \note When using the FFMPEG backend on an Android target device if you request
493 \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
494 semi-planar NV12/NV21. This depends on the codec implemented by the device
495 OEM.
496*/
497void QCamera::setCameraFormat(const QCameraFormat &format)
498{
499 Q_D(QCamera);
500 if (!d->control || !d->control->setCameraFormat(format))
501 return;
502
503 d->cameraFormat = format;
504 emit cameraFormatChanged();
505}
506
507/*!
508 \enum QCamera::Error
509
510 This enum holds the last error code.
511
512 \value NoError No errors have occurred.
513 \value CameraError An error has occurred.
514*/
515
516/*!
517 \qmlsignal void Camera::errorOccurred(Camera::Error error, string errorString)
518
519 This signal is emitted when error state changes to \a error. A description
520 of the error is provided as \a errorString.
521*/
522
523/*!
524 \fn void QCamera::errorOccurred(QCamera::Error error, const QString &errorString)
525
526 This signal is emitted when error state changes to \a error. A description
527 of the error is provided as \a errorString.
528*/
529
530/*!
531 \qmlproperty enumeration Camera::focusMode
532
533 This property holds the value that controls focus mode for the camera device.
534 In all autofocus modes, the camera device keeps focusing continuously.
535
536 \note In automatic focusing modes and where supported, the \l focusPoint property provides
537 information and control over the area of the image that is being focused.
538
539 \value Camera.FocusModeAuto Continuous auto focus mode.
540 \value Camera.FocusModeAutoNear Continuous auto focus, preferring objects near to
541 the camera.
542 \value Camera.FocusModeAutoFar Continuous auto focus, preferring objects far away
543 from the camera.
544 \value Camera.FocusModeHyperfocal Focus to hyperfocal distance, with the maximum
545 depth of field achieved. All objects at distances from half of this
546 distance out to infinity will be acceptably sharp.
547 \value Camera.FocusModeInfinity Focus strictly to infinity.
548 \value Camera.FocusModeManual The lens focus distance is set to a value specified by \l focusDistance.
549
550 To check whether the camera device supports a particular focus mode, pass the corresponding
551 \c focusMode value to the \l isFocusModeSupported() function as a parameter. The function
552 returns \c false if the focus mode value is not supported. Assigning an unsupported mode to
553 this property has no effect.
554
555 If you set the focusMode property to \c Camera.FocusModeManual, the lens
556 locks to the focus according to \l focusDistance.
557
558 \sa isFocusModeSupported()
559*/
560
561/*!
562 \property QCamera::focusMode
563 \brief the current camera focus mode.
564
565 This property holds the value that controls focus mode for the camera device.
566 In all autofocus modes, the camera device keeps focusing continuously.
567
568 To check whether the camera device supports a particular focus mode, pass the corresponding
569 \l FocusMode value to the \l isFocusModeSupported function as a parameter. The function
570 returns false if the focus mode value is not supported. Assigning an unsupported mode to
571 this property has no effect.
572
573 If you set the focusMode property to \l QCamera::FocusModeManual, the lens
574 locks to the focus according to \l focusDistance.
575
576 \sa isFocusModeSupported()
577*/
578QCamera::FocusMode QCamera::focusMode() const
579{
580 Q_D(const QCamera);
581 return d->control ? d->control->focusMode() : QCamera::FocusModeAuto;
582}
583
584/*!
585 \fn void QCamera::focusModeChanged()
586
587 Signals when the focusMode changes.
588*/
589void QCamera::setFocusMode(QCamera::FocusMode mode)
590{
591 Q_D(QCamera);
592 if (!d->control || d->control->focusMode() == mode)
593 return;
594 d->control->setFocusMode(mode);
595}
596
597/*!
598 \qmlmethod bool Camera::isFocusModeSupported(FocusMode mode)
599
600 Returns \c true if the focus \a mode is supported by the camera.
601
602 If \l {focusMode}{Camera.FocusModeManual} is reported as supported,
603 the feature \l {supportedFeatures}{Camera.FocusDistance} is implied
604 to be supported as well.
605*/
606
607/*!
608 Returns \c true if the focus \a mode is supported by the camera.
609
610 If \l FocusModeManual is reported as supported, the feature
611 \l Feature::FocusDistance is implied to be supported as well.
612*/
613bool QCamera::isFocusModeSupported(FocusMode mode) const
614{
615 Q_D(const QCamera);
616 return d->control ? d->control->isFocusModeSupported(mode) : false;
617}
618
619/*!
620 \qmlproperty point QtMultimedia::Camera::focusPoint
621 Returns the point currently used by the auto focus system to focus onto.
622*/
623
624/*!
625 \property QCamera::focusPoint
626
627 Returns the point currently used by the auto focus system to focus onto.
628 */
629QPointF QCamera::focusPoint() const
630{
631 Q_D(const QCamera);
632 return d->control ? d->control->focusPoint() : QPointF(-1., -1.);
633
634}
635
636/*!
637 \qmlproperty point QtMultimedia::Camera::customFocusPoint
638
639 This property holds the position of custom focus point, in relative frame
640 coordinates. This means that QPointF(0,0) points to the top-left corner
641 of the frame, and QPointF(0.5,0.5) points to the center of the frame.
642
643 You can check whether custom focus points are supported by querying
644 supportedFeatures() with the Feature.CustomFocusPoint flag.
645*/
646
647/*!
648 \property QCamera::customFocusPoint
649
650 This property represents the position of the custom focus point, in relative frame coordinates:
651 QPointF(0,0) points to the left top frame point, QPointF(0.5,0.5) points to the frame center.
652
653 You can check whether custom focus points are supported by querying
654 supportedFeatures() with the Feature.CustomFocusPoint flag.
655*/
656QPointF QCamera::customFocusPoint() const
657{
658 Q_D(const QCamera);
659 return d->control ? d->control->customFocusPoint() : QPointF{-1., -1.};
660}
661
662void QCamera::setCustomFocusPoint(const QPointF &point)
663{
664 Q_D(QCamera);
665 if (d->control)
666 d->control->setCustomFocusPoint(point);
667}
668
669/*!
670 \qmlproperty real QtMultimedia::Camera::focusDistance
671
672 This property defines the lens focus distance when the camera device works in
673 manual focus mode. Valid values range from 0 to 1, where 0 is the closest
674 possible focus distance, and 1 is the farthest. The farthest point is
675 typically at infinity, but this may not be the case for all devices.
676
677 This property is applied to the device only when \l focusMode is set to
678 \l {focusMode}{Camera.FocusModeManual}, and \l supportedFeatures includes the
679 \c Camera.FocusDistance flag.
680
681 If you assign a value to this property while \l focusMode is not
682 set to \c Camera.FocusModeManual, the property stores the value but does
683 not affect the device until \c Camera.FocusModeManual is active.
684
685 Assigning a value outside the valid range [0, 1] has no effect on this property.
686
687 If \l supportedFeatures does not include the \c Camera.FocusDistance flag,
688 any attempt to set this property is ignored.
689
690 This property will not be updated by the camera when it is in an automatic focus mode.
691
692 The default value is 1.
693*/
694
695/*!
696 \property QCamera::focusDistance
697
698 This property defines the lens focus distance when the camera device works in
699 manual focus mode. Valid values range from 0 to 1, where 0 is the closest
700 possible focus distance, and 1 is the farthest. The farthest point is
701 typically at infinity, but this may not be the case for all devices.
702
703 This property is applied to the device only when \l focusMode is set to
704 \l FocusModeManual, and \l supportedFeatures includes the
705 \l Feature::FocusDistance flag.
706
707 If you assign a value to this property while \l focusMode is not
708 set to \c QCamera::FocusModeManual, the property stores the value but does
709 not affect the device until \c QCamera::FocusModeManual is active.
710
711 Assigning a value outside the valid range [0, 1] has no effect on this property.
712
713 If \l supportedFeatures does not include the \l FocusDistance flag,
714 any attempt to set this property is ignored.
715
716 This property will not be updated by the camera when it is in an automatic focus mode.
717
718 The default value is 1.
719*/
720void QCamera::setFocusDistance(float distance)
721{
722 if (!d_func()->control)
723 return;
724 d_func()->control->setFocusDistance(distance);
725}
726
727float QCamera::focusDistance() const
728{
729 if (d_func()->control)
730 return d_func()->control->focusDistance();
731 return 0.f;
732}
733
734/*!
735 \qmlproperty real QtMultimedia::Camera::maximumZoomFactor
736
737 This property holds the maximum zoom factor supported.
738
739 This will be \c 1.0 on cameras that do not support zooming.
740*/
741
742
743/*!
744 \property QCamera::maximumZoomFactor
745
746 Returns the maximum zoom factor.
747
748 This will be \c 1.0 on cameras that do not support zooming.
749*/
750
751float QCamera::maximumZoomFactor() const
752{
753 Q_D(const QCamera);
754 return d->control ? d->control->maxZoomFactor() : 1.f;
755}
756
757/*!
758 \qmlproperty real QtMultimedia::Camera::minimumZoomFactor
759
760 This property holds the minimum zoom factor supported.
761
762 This will be \c 1.0 on cameras that do not support zooming.
763*/
764
765/*!
766 \property QCamera::minimumZoomFactor
767
768 Returns the minimum zoom factor.
769
770 This will be \c 1.0 on cameras that do not support zooming.
771*/
772
773float QCamera::minimumZoomFactor() const
774{
775 Q_D(const QCamera);
776 return d->control ? d->control->minZoomFactor() : 1.f;
777}
778
779/*!
780 \qmlproperty real QtMultimedia::Camera::zoomFactor
781
782 Gets or sets the current zoom factor. Values will be clamped between
783 \l minimumZoomFactor and \l maximumZoomFactor.
784*/
785
786/*!
787 \property QCamera::zoomFactor
788 \brief The current zoom factor.
789
790 Gets or sets the current zoom factor. Values will be clamped between
791 \l minimumZoomFactor and \l maximumZoomFactor.
792*/
793float QCamera::zoomFactor() const
794{
795 Q_D(const QCamera);
796 return d->control ? d->control->zoomFactor() : 1.f;
797}
798/*!
799 Zooms to a zoom factor \a factor at a rate of 1 factor per second.
800 */
801void QCamera::setZoomFactor(float factor)
802{
803 zoomTo(factor, 0.f);
804}
805
806/*!
807 \qmlmethod void QtMultimedia::Camera::zoomTo(factor, rate)
808
809 Zooms to a zoom factor \a factor using \a rate.
810
811 The \a rate is specified in powers of two per second. At a rate of 1
812 it would take 2 seconds to go from a zoom factor of 1 to 4.
813
814 \note Using a specific rate is not supported on all cameras. If not supported,
815 zooming will happen as fast as possible.
816*/
817
818/*!
819 Zooms to a zoom factor \a factor using \a rate.
820
821 The \a rate is specified in powers of two per second. At a rate of 1
822 it would take 2 seconds to go from a zoom factor of 1 to 4.
823
824 \note Using a specific rate is not supported on all cameras. If not supported,
825 zooming will happen as fast as possible.
826*/
827void QCamera::zoomTo(float factor, float rate)
828{
829 Q_ASSERT(rate >= 0.f);
830 if (rate < 0.f)
831 rate = 0.f;
832
833 Q_D(QCamera);
834 if (!d->control)
835 return;
836 factor = qBound(d->control->minZoomFactor(), factor, d->control->maxZoomFactor());
837 d->control->zoomTo(factor, rate);
838}
839
840/*!
841 \enum QCamera::FocusMode
842
843 \value FocusModeAuto Continuous auto focus mode.
844 \value FocusModeAutoNear Continuous auto focus mode on near objects.
845 \value FocusModeAutoFar Continuous auto focus mode on objects far away.
846 \value FocusModeHyperfocal Focus to hyperfocal distance, with the maximum depth of field achieved.
847 All objects at distances from half of this
848 distance out to infinity will be acceptably sharp.
849 \value FocusModeInfinity Focus strictly to infinity.
850 \value FocusModeManual Camera lens focus distance is locked according to \l focusDistance.
851*/
852
853/*!
854 \qmlproperty enumeration QtMultimedia::Camera::flashMode
855
856 Gets or sets a certain flash mode if the camera has a flash.
857
858 Assigning an unsupported mode to this property has no effect.
859
860 This property only has an effect when capturing images using
861 \l ImageCapture
862
863 \qmlenumeratorsfrom QCamera::FlashMode
864
865 \sa isFlashModeSupported(), isFlashReady(), flashReady
866*/
867
868/*!
869 \property QCamera::flashMode
870 \brief The flash mode being used.
871
872 Enables a certain flash mode if the camera has a flash.
873
874 Assigning an unsupported mode to this property has no effect.
875
876 This property only has an effect when capturing images using
877 \l QImageCapture
878
879 \sa QCamera::FlashMode, QCamera::isFlashModeSupported, QCamera::isFlashReady
880*/
881QCamera::FlashMode QCamera::flashMode() const
882{
883 Q_D(const QCamera);
884 return d->control ? d->control->flashMode() : QCamera::FlashOff;
885}
886
887void QCamera::setFlashMode(QCamera::FlashMode mode)
888{
889 Q_D(QCamera);
890 if (d->control)
891 d->control->setFlashMode(mode);
892}
893
894/*!
895 \qmlmethod bool QtMultimedia::Camera::isFlashModeSupported(FlashMode mode)
896
897 Returns true if the flash \a mode is supported.
898*/
899
900/*!
901 Returns true if the flash \a mode is supported.
902*/
903bool QCamera::isFlashModeSupported(QCamera::FlashMode mode) const
904{
905 Q_D(const QCamera);
906 return d->control ? d->control->isFlashModeSupported(mode) : (mode == FlashOff);
907}
908
909/*!
910 \qmlmethod bool QtMultimedia::Camera::isFlashReady()
911
912 Returns true if flash is charged.
913*/
914
915/*!
916 Returns true if flash is charged.
917*/
918bool QCamera::isFlashReady() const
919{
920 Q_D(const QCamera);
921 return d->control ? d->control->isFlashReady() : false;
922}
923
924/*!
925 \qmlproperty enumeration Camera::torchMode
926
927 Gets or sets the torch mode being used.
928
929 A torch is a continuous source of light. It can be used during video recording in
930 low light conditions. Enabling torch mode will usually override any currently set
931 flash mode.
932
933 \qmlenumeratorsfrom QCamera::TorchMode
934
935 \sa isTorchModeSupported(), flashMode
936*/
937
938/*!
939 \property QCamera::torchMode
940 \brief The torch mode being used.
941
942 A torch is a continuous source of light. It can be used during video recording in
943 low light conditions. Enabling torch mode will usually override any currently set
944 flash mode.
945
946 \sa QCamera::TorchMode, QCamera::isTorchModeSupported, QCamera::flashMode
947*/
948QCamera::TorchMode QCamera::torchMode() const
949{
950 Q_D(const QCamera);
951 return d->control ? d->control->torchMode() : TorchOff;
952}
953
954void QCamera::setTorchMode(QCamera::TorchMode mode)
955{
956 Q_D(QCamera);
957 if (d->control)
958 d->control->setTorchMode(mode);
959}
960
961/*!
962 \qmlmethod bool QtMultimedia::Camera::isTorchModeSupported(TorchMode mode)
963
964 Returns true if the torch \a mode is supported.
965*/
966
967/*!
968 Returns true if the torch \a mode is supported.
969*/
970bool QCamera::isTorchModeSupported(QCamera::TorchMode mode) const
971{
972 Q_D(const QCamera);
973 return d->control ? d->control->isTorchModeSupported(mode) : (mode == TorchOff);
974}
975
976/*!
977 \qmlproperty enumeration QtMultimedia::Camera::exposureMode
978 \brief The exposure mode being used.
979
980 \qmlenumeratorsfrom QCamera::ExposureMode
981
982 \sa isExposureModeSupported()
983*/
984
985/*!
986 \property QCamera::exposureMode
987 \brief The exposure mode being used.
988
989 \sa QCamera::isExposureModeSupported
990*/
991QCamera::ExposureMode QCamera::exposureMode() const
992{
993 Q_D(const QCamera);
994 return d->control ? d->control->exposureMode() : QCamera::ExposureAuto;
995}
996
997void QCamera::setExposureMode(QCamera::ExposureMode mode)
998{
999 Q_D(QCamera);
1000 if (d->control)
1001 d->control->setExposureMode(mode);
1002}
1003
1004/*!
1005 \qmlmethod bool QtMultimedia::Camera::isExposureModeSupported(ExposureMode mode)
1006
1007 Returns true if the exposure \a mode is supported.
1008*/
1009
1010/*!
1011 Returns true if the exposure \a mode is supported.
1012*/
1013bool QCamera::isExposureModeSupported(QCamera::ExposureMode mode) const
1014{
1015 Q_D(const QCamera);
1016 return d->control && d->control->isExposureModeSupported(mode);
1017}
1018
1019/*!
1020 \qmlproperty real QtMultimedia::Camera::exposureCompensation
1021
1022 Gets or sets the exposure compensation in EV units.
1023
1024 Exposure compensation property allows to adjust the automatically calculated
1025 exposure.
1026*/
1027
1028/*!
1029 \property QCamera::exposureCompensation
1030 \brief Exposure compensation in EV units.
1031
1032 Exposure compensation property allows to adjust the automatically calculated
1033 exposure.
1034*/
1035float QCamera::exposureCompensation() const
1036{
1037 Q_D(const QCamera);
1038 return d->control ? d->control->exposureCompensation() : 0.f;
1039}
1040
1041void QCamera::setExposureCompensation(float ev)
1042{
1043 Q_D(QCamera);
1044 if (d->control)
1045 d->control->setExposureCompensation(ev);
1046}
1047
1048/*!
1049 \qmlproperty int QtMultimedia::Camera::isoSensitivity
1050
1051 Describes the ISO sensitivity currently used by the camera.
1052
1053*/
1054
1055/*!
1056 \property QCamera::isoSensitivity
1057 \brief The sensor ISO sensitivity.
1058
1059 Describes the ISO sensitivity currently used by the camera.
1060
1061 \sa setAutoIsoSensitivity(), setManualIsoSensitivity()
1062*/
1063int QCamera::isoSensitivity() const
1064{
1065 Q_D(const QCamera);
1066 return d->control ? d->control->isoSensitivity() : -1;
1067}
1068
1069/*!
1070 \qmlproperty int QtMultimedia::Camera::manualIsoSensitivity
1071
1072 Describes a manually set ISO sensitivity
1073
1074 Setting this property to -1 (the default), implies that the camera
1075 automatically adjusts the ISO sensitivity.
1076*/
1077
1078/*!
1079 \property QCamera::manualIsoSensitivity
1080 \brief Describes a manually set ISO sensitivity
1081
1082 Setting this property to -1 (the default), implies that the camera
1083 automatically adjusts the ISO sensitivity.
1084*/
1085void QCamera::setManualIsoSensitivity(int iso)
1086{
1087 Q_D(QCamera);
1088 if (iso <= 0)
1089 iso = -1;
1090 if (d->control)
1091 d->control->setManualIsoSensitivity(iso);
1092}
1093
1094int QCamera::manualIsoSensitivity() const
1095{
1096 Q_D(const QCamera);
1097 return d->control ? d->control->manualIsoSensitivity() : 100;
1098}
1099
1100/*!
1101 \fn QCamera::setAutoIsoSensitivity()
1102 Turn on auto sensitivity
1103*/
1104
1105void QCamera::setAutoIsoSensitivity()
1106{
1107 Q_D(QCamera);
1108 if (d->control)
1109 d->control->setManualIsoSensitivity(-1);
1110}
1111
1112/*!
1113 Returns the minimum ISO sensitivity supported by the camera.
1114*/
1115int QCamera::minimumIsoSensitivity() const
1116{
1117 Q_D(const QCamera);
1118 return d->control ? d->control->minIso() : -1;
1119}
1120
1121/*!
1122 Returns the maximum ISO sensitivity supported by the camera.
1123*/
1124int QCamera::maximumIsoSensitivity() const
1125{
1126 Q_D(const QCamera);
1127 return d->control ? d->control->maxIso() : -1;
1128}
1129
1130/*!
1131 The minimal exposure time in seconds.
1132*/
1133float QCamera::minimumExposureTime() const
1134{
1135 Q_D(const QCamera);
1136 return d->control ? d->control->minExposureTime() : -1.f;
1137}
1138
1139/*!
1140 The maximal exposure time in seconds.
1141*/
1142float QCamera::maximumExposureTime() const
1143{
1144 Q_D(const QCamera);
1145 return d->control ? d->control->maxExposureTime() : -1.f;
1146}
1147
1148/*!
1149 \qmlproperty real QtMultimedia::Camera::exposureTime
1150 Returns the Camera's exposure time in seconds.
1151
1152 \sa manualExposureTime
1153*/
1154
1155/*!
1156 \property QCamera::exposureTime
1157 \brief Camera's exposure time in seconds.
1158
1159 \sa minimumExposureTime(), maximumExposureTime(), setManualExposureTime()
1160*/
1161
1162/*!
1163 \fn QCamera::exposureTimeChanged(float speed)
1164
1165 Signals that a camera's exposure \a speed has changed.
1166*/
1167
1168/*!
1169 Returns the current exposure time in seconds.
1170*/
1171
1172float QCamera::exposureTime() const
1173{
1174 Q_D(const QCamera);
1175 return d->control ? d->control->exposureTime() : -1;
1176}
1177
1178/*!
1179 \qmlproperty real QtMultimedia::Camera::manualExposureTime
1180
1181 Gets or sets a manual exposure time.
1182
1183 Setting this property to -1 (the default) means that the camera
1184 automatically determines the exposure time.
1185*/
1186
1187/*!
1188 \property QCamera::manualExposureTime
1189
1190 Set the manual exposure time to \a seconds
1191*/
1192
1193void QCamera::setManualExposureTime(float seconds)
1194{
1195 Q_D(QCamera);
1196 if (d->control)
1197 d->control->setManualExposureTime(seconds);
1198}
1199
1200/*!
1201 Returns the manual exposure time in seconds, or -1
1202 if the camera is using automatic exposure times.
1203*/
1204float QCamera::manualExposureTime() const
1205{
1206 Q_D(const QCamera);
1207 return d->control ? d->control->manualExposureTime() : -1;
1208}
1209
1210/*!
1211 Use automatically calculated exposure time
1212*/
1213void QCamera::setAutoExposureTime()
1214{
1215 Q_D(QCamera);
1216 if (d->control)
1217 d->control->setManualExposureTime(-1);
1218}
1219
1220
1221/*!
1222 \enum QCamera::FlashMode
1223
1224 \value FlashOff Flash is Off.
1225 \value FlashOn Flash is On.
1226 \value FlashAuto Automatic flash.
1227*/
1228
1229/*!
1230 \enum QCamera::TorchMode
1231
1232 \value TorchOff Torch is Off.
1233 \value TorchOn Torch is On.
1234 \value TorchAuto Automatic torch.
1235*/
1236
1237/*!
1238 \enum QCamera::ExposureMode
1239
1240 \value ExposureAuto Automatic mode.
1241 \value ExposureManual Manual mode.
1242 \value ExposurePortrait Portrait exposure mode.
1243 \value ExposureNight Night mode.
1244 \value ExposureSports Spots exposure mode.
1245 \value ExposureSnow Snow exposure mode.
1246 \value ExposureBeach Beach exposure mode.
1247 \value ExposureAction Action mode. Since 5.5
1248 \value ExposureLandscape Landscape mode. Since 5.5
1249 \value ExposureNightPortrait Night portrait mode. Since 5.5
1250 \value ExposureTheatre Theatre mode. Since 5.5
1251 \value ExposureSunset Sunset mode. Since 5.5
1252 \value ExposureSteadyPhoto Steady photo mode. Since 5.5
1253 \value ExposureFireworks Fireworks mode. Since 5.5
1254 \value ExposureParty Party mode. Since 5.5
1255 \value ExposureCandlelight Candlelight mode. Since 5.5
1256 \value ExposureBarcode Barcode mode. Since 5.5
1257*/
1258
1259/*!
1260 \qmlproperty bool QtMultimedia::Camera::flashReady
1261
1262 Indicates if the flash is charged and ready to use.
1263*/
1264
1265/*!
1266 \property QCamera::flashReady
1267 \brief Indicates if the flash is charged and ready to use.
1268*/
1269
1270/*!
1271 \fn void QCamera::flashReady(bool ready)
1272
1273 Signal the flash \a ready status has changed.
1274*/
1275
1276/*!
1277 \fn void QCamera::isoSensitivityChanged(int value)
1278
1279 Signal emitted when sensitivity changes to \a value.
1280*/
1281
1282/*!
1283 \fn void QCamera::exposureCompensationChanged(float value)
1284
1285 Signal emitted when the exposure compensation changes to \a value.
1286*/
1287
1288
1289/*!
1290 \qmlproperty enumeration QtMultimedia::Camera::whiteBalanceMode
1291
1292 Gets or sets the white balance mode being used.
1293
1294 \qmlenumeratorsfrom QCamera::WhiteBalanceMode
1295
1296 \sa isWhiteBalanceModeSupported()
1297*/
1298
1299/*!
1300 \property QCamera::whiteBalanceMode
1301
1302 Returns the white balance mode being used.
1303*/
1304QCamera::WhiteBalanceMode QCamera::whiteBalanceMode() const
1305{
1306 Q_D(const QCamera);
1307 return d->control ? d->control->whiteBalanceMode() : QCamera::WhiteBalanceAuto;
1308}
1309
1310/*!
1311 Sets the white balance to \a mode.
1312*/
1313void QCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode)
1314{
1315 Q_D(QCamera);
1316 if (!d->control)
1317 return;
1318 if (!d->control->isWhiteBalanceModeSupported(mode))
1319 return;
1320 d->control->setWhiteBalanceMode(mode);
1321 if (mode == QCamera::WhiteBalanceManual)
1322 d->control->setColorTemperature(5600);
1323}
1324
1325/*!
1326 \qmlmethod bool QtMultimedia::Camera::isWhiteBalanceModeSupported(WhiteBalanceMode mode)
1327
1328 Returns true if the white balance \a mode is supported.
1329*/
1330
1331/*!
1332 Returns true if the white balance \a mode is supported.
1333*/
1334bool QCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const
1335{
1336 Q_D(const QCamera);
1337 return d->control && d->control->isWhiteBalanceModeSupported(mode);
1338}
1339
1340/*!
1341 \qmlproperty int QtMultimedia::Camera::colorTemperature
1342
1343 Gets or sets the current color temperature.
1344
1345 Setting a color temperature will only have an effect if WhiteBalanceManual is
1346 supported. In this case, setting a temperature greater 0 will automatically set the
1347 white balance mode to WhiteBalanceManual. Setting the temperature to 0 will reset
1348 the white balance mode to WhiteBalanceAuto.
1349*/
1350
1351/*!
1352 \property QCamera::colorTemperature
1353
1354 Returns the current color temperature if the
1355 current white balance mode is \c WhiteBalanceManual. For other modes the
1356 return value is undefined.
1357*/
1358int QCamera::colorTemperature() const
1359{
1360 Q_D(const QCamera);
1361 return d->control ? d->control->colorTemperature() : 0;
1362}
1363
1364/*!
1365 Sets manual white balance to \a colorTemperature. This is used
1366 when whiteBalanceMode() is set to \c WhiteBalanceManual. The units are Kelvin.
1367
1368 Setting a color temperature will only have an effect if WhiteBalanceManual is
1369 supported. In this case, setting a temperature greater 0 will automatically set the
1370 white balance mode to WhiteBalanceManual. Setting the temperature to 0 will reset
1371 the white balance mode to WhiteBalanceAuto.
1372*/
1373
1374void QCamera::setColorTemperature(int colorTemperature)
1375{
1376 Q_D(QCamera);
1377 if (!d->control)
1378 return;
1379 if (colorTemperature < 0)
1380 colorTemperature = 0;
1381 if (colorTemperature == 0) {
1382 d->control->setWhiteBalanceMode(WhiteBalanceAuto);
1383 } else if (!isWhiteBalanceModeSupported(WhiteBalanceManual)) {
1384 return;
1385 } else {
1386 d->control->setWhiteBalanceMode(WhiteBalanceManual);
1387 }
1388 d->control->setColorTemperature(colorTemperature);
1389}
1390
1391/*!
1392 \enum QCamera::WhiteBalanceMode
1393
1394 \value WhiteBalanceAuto Auto white balance mode.
1395 \value WhiteBalanceManual Manual white balance. In this mode the white
1396 balance should be set with setColorTemperature()
1397 \value WhiteBalanceSunlight Sunlight white balance mode.
1398 \value WhiteBalanceCloudy Cloudy white balance mode.
1399 \value WhiteBalanceShade Shade white balance mode.
1400 \value WhiteBalanceTungsten Tungsten (incandescent) white balance mode.
1401 \value WhiteBalanceFluorescent Fluorescent white balance mode.
1402 \value WhiteBalanceFlash Flash white balance mode.
1403 \value WhiteBalanceSunset Sunset white balance mode.
1404*/
1405
1406/*!
1407 \fn void QCamera::brightnessChanged()
1408 \internal
1409*/
1410/*!
1411 \fn void QCamera::contrastChanged()
1412 \internal
1413*/
1414/*!
1415 \fn void QCamera::hueChanged()
1416 \internal
1417*/
1418/*!
1419 \fn void QCamera::saturationChanged()
1420 \internal
1421*/
1422QT_END_NAMESPACE
1423
1424#include "moc_qcamera.cpp"
QPlatformCamera * control
Definition qcamera_p.h:34
Combined button and popup list for selecting options.