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