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 auto dev = cameraDevice;
478 if (dev.isNull())
479 dev = QMediaDevices::defaultVideoInput();
480 if (d->cameraDevice == dev)
481 return;
482 d->cameraDevice = dev;
483 if (d->control)
484 d->control->setCamera(d->cameraDevice);
485 emit cameraDeviceChanged();
486 setCameraFormat({});
487}
488
489/*! \qmlproperty cameraFormat QtMultimedia::Camera::cameraFormat
490
491 Gets or sets the currently active camera format.
492
493 \note When using the FFMPEG backend on an Android target device if you request
494 \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
495 semi-planar NV12/NV21. This depends on the codec implemented by the device
496 OEM.
497
498 \note On macOS, camera-devices are shared across multiple
499 applications on the operating system. This means that another
500 application may override the format set by this property.
501 Application developers should account for receiving video frames
502 that have a different resolution, pixel format and framerate than
503 what is described by this property. This property does not change
504 when the device's format is modified by another application. The
505 format described by this property can be re-applied to the device
506 by re-activating the \l Camera.
507
508 \sa cameraDevice::videoFormats
509*/
510
511/*!
512 \property QCamera::cameraFormat
513
514 Returns the camera format currently used by the camera.
515
516 \note When using the FFMPEG backend on an Android target device if you request
517 \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
518 semi-planar NV12/NV21. This depends on the codec implemented by the device
519 OEM.
520
521 \note On macOS, camera-devices are shared across multiple
522 applications on the operating system. This means that another
523 application may override the format set by this property.
524 Application developers should account for receiving video frames
525 that have a different resolution, pixel format and framerate than
526 what is described by this property. This property does not change
527 when the device's format is modified by another application. The
528 format described by this property can be re-applied to the device
529 by re-activating the \l QCamera.
530
531 \sa QCameraDevice::videoFormats
532*/
533QCameraFormat QCamera::cameraFormat() const
534{
535 Q_D(const QCamera);
536 return d->cameraFormat;
537}
538
539/*!
540 Tells the camera to use the format described by \a format. This can be used to define
541 a specific resolution and frame rate to be used for recording and image capture.
542
543 \note When using the FFMPEG backend on an Android target device if you request
544 \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
545 semi-planar NV12/NV21. This depends on the codec implemented by the device
546 OEM.
547*/
548void QCamera::setCameraFormat(const QCameraFormat &format)
549{
550 Q_D(QCamera);
551 if (!d->control || !d->control->setCameraFormat(format))
552 return;
553
554 d->cameraFormat = format;
555 emit cameraFormatChanged();
556}
557
558/*!
559 \enum QCamera::Error
560
561 This enum holds the last error code.
562
563 \value NoError No errors have occurred.
564 \value CameraError An error has occurred.
565*/
566
567/*!
568 \qmlsignal void Camera::errorOccurred(Camera::Error error, string errorString)
569
570 This signal is emitted when error state changes to \a error. A description
571 of the error is provided as \a errorString.
572*/
573
574/*!
575 \fn void QCamera::errorOccurred(QCamera::Error error, const QString &errorString)
576
577 This signal is emitted when error state changes to \a error. A description
578 of the error is provided as \a errorString.
579*/
580
581/*!
582 \qmlproperty enumeration Camera::focusMode
583
584 This property holds the value that controls focus mode for the camera device.
585 In all autofocus modes, the camera device keeps focusing continuously.
586
587 \note In automatic focusing modes and where supported, the \l focusPoint property provides
588 information and control over the area of the image that is being focused.
589
590 \value Camera.FocusModeAuto Continuous auto focus mode.
591 \value Camera.FocusModeAutoNear Continuous auto focus, preferring objects near to
592 the camera.
593 \value Camera.FocusModeAutoFar Continuous auto focus, preferring objects far away
594 from the camera.
595 \value Camera.FocusModeHyperfocal Focus to hyperfocal distance, with the maximum
596 depth of field achieved. All objects at distances from half of this
597 distance out to infinity will be acceptably sharp.
598 \value Camera.FocusModeInfinity Focus strictly to infinity.
599 \value Camera.FocusModeManual The lens focus distance is set to a value specified by \l focusDistance.
600
601 To check whether the camera device supports a particular focus mode, pass the corresponding
602 \c focusMode value to the \l isFocusModeSupported() function as a parameter. The function
603 returns \c false if the focus mode value is not supported. Assigning an unsupported mode to
604 this property has no effect.
605
606 If you set the focusMode property to \c Camera.FocusModeManual, the lens
607 locks to the focus according to \l focusDistance.
608
609 \sa isFocusModeSupported()
610*/
611
612/*!
613 \property QCamera::focusMode
614 \brief the current camera focus mode.
615
616 This property holds the value that controls focus mode for the camera device.
617 In all autofocus modes, the camera device keeps focusing continuously.
618
619 To check whether the camera device supports a particular focus mode, pass the corresponding
620 \l FocusMode value to the \l isFocusModeSupported function as a parameter. The function
621 returns false if the focus mode value is not supported. Assigning an unsupported mode to
622 this property has no effect.
623
624 If you set the focusMode property to \l QCamera::FocusModeManual, the lens
625 locks to the focus according to \l focusDistance.
626
627 \sa isFocusModeSupported()
628*/
629QCamera::FocusMode QCamera::focusMode() const
630{
631 Q_D(const QCamera);
632 return d->control ? d->control->focusMode() : QCamera::FocusModeAuto;
633}
634
635/*!
636 \fn void QCamera::focusModeChanged()
637
638 Signals when the focusMode changes.
639*/
640void QCamera::setFocusMode(QCamera::FocusMode mode)
641{
642 Q_D(QCamera);
643 if (!d->control || d->control->focusMode() == mode)
644 return;
645 d->control->setFocusMode(mode);
646}
647
648/*!
649 \qmlmethod bool Camera::isFocusModeSupported(FocusMode mode)
650
651 Returns \c true if the focus \a mode is supported by the camera.
652
653 If \l {focusMode}{Camera.FocusModeManual} is reported as supported,
654 the feature \l {supportedFeatures}{Camera.FocusDistance} is implied
655 to be supported as well.
656*/
657
658/*!
659 Returns \c true if the focus \a mode is supported by the camera.
660
661 If \l FocusModeManual is reported as supported, the feature
662 \l Feature::FocusDistance is implied to be supported as well.
663*/
664bool QCamera::isFocusModeSupported(FocusMode mode) const
665{
666 Q_D(const QCamera);
667 return d->control ? d->control->isFocusModeSupported(mode) : false;
668}
669
670/*!
671 \qmlproperty point QtMultimedia::Camera::focusPoint
672 Returns the point currently used by the auto focus system to focus onto.
673*/
674
675/*!
676 \property QCamera::focusPoint
677
678 Returns the point currently used by the auto focus system to focus onto.
679 */
680QPointF QCamera::focusPoint() const
681{
682 Q_D(const QCamera);
683 return d->control ? d->control->focusPoint() : QPointF(-1., -1.);
684
685}
686
687/*!
688 \qmlproperty point QtMultimedia::Camera::customFocusPoint
689
690 This property holds the position of custom focus point, in relative frame
691 coordinates. This means that QPointF(0,0) points to the top-left corner
692 of the frame, and QPointF(0.5,0.5) points to the center of the frame.
693
694 You can check whether custom focus points are supported by querying
695 supportedFeatures() with the Feature.CustomFocusPoint flag.
696*/
697
698/*!
699 \property QCamera::customFocusPoint
700
701 This property represents the position of the custom focus point, in relative frame coordinates:
702 QPointF(0,0) points to the left top frame point, QPointF(0.5,0.5) points to the frame center.
703
704 You can check whether custom focus points are supported by querying
705 supportedFeatures() with the Feature.CustomFocusPoint flag.
706*/
707QPointF QCamera::customFocusPoint() const
708{
709 Q_D(const QCamera);
710 return d->control ? d->control->customFocusPoint() : QPointF{-1., -1.};
711}
712
713void QCamera::setCustomFocusPoint(const QPointF &point)
714{
715 Q_D(QCamera);
716 if (d->control)
717 d->control->setCustomFocusPoint(point);
718}
719
720/*!
721 \qmlproperty real QtMultimedia::Camera::focusDistance
722
723 This property defines the lens focus distance when the camera device works in
724 manual focus mode. Valid values range from 0 to 1, where 0 is the closest
725 possible focus distance, and 1 is the farthest. The farthest point is
726 typically at infinity, but this may not be the case for all devices.
727
728 This property is applied to the device only when \l focusMode is set to
729 \l {focusMode}{Camera.FocusModeManual}, and \l supportedFeatures includes the
730 \c Camera.FocusDistance flag.
731
732 If you assign a value to this property while \l focusMode is not
733 set to \c Camera.FocusModeManual, the property stores the value but does
734 not affect the device until \c Camera.FocusModeManual is active.
735
736 Assigning a value outside the valid range [0, 1] has no effect on this property.
737
738 If \l supportedFeatures does not include the \c Camera.FocusDistance flag,
739 any attempt to set this property is ignored.
740
741 This property will not be updated by the camera when it is in an automatic focus mode.
742
743 The default value is 1.
744*/
745
746/*!
747 \property QCamera::focusDistance
748
749 This property defines the lens focus distance when the camera device works in
750 manual focus mode. Valid values range from 0 to 1, where 0 is the closest
751 possible focus distance, and 1 is the farthest. The farthest point is
752 typically at infinity, but this may not be the case for all devices.
753
754 This property is applied to the device only when \l focusMode is set to
755 \l FocusModeManual, and \l supportedFeatures includes the
756 \l Feature::FocusDistance flag.
757
758 If you assign a value to this property while \l focusMode is not
759 set to \c QCamera::FocusModeManual, the property stores the value but does
760 not affect the device until \c QCamera::FocusModeManual is active.
761
762 Assigning a value outside the valid range [0, 1] has no effect on this property.
763
764 If \l supportedFeatures does not include the \l FocusDistance flag,
765 any attempt to set this property is ignored.
766
767 This property will not be updated by the camera when it is in an automatic focus mode.
768
769 The default value is 1.
770*/
771void QCamera::setFocusDistance(float distance)
772{
773 if (!d_func()->control)
774 return;
775 d_func()->control->setFocusDistance(distance);
776}
777
778float QCamera::focusDistance() const
779{
780 if (d_func()->control)
781 return d_func()->control->focusDistance();
782 return 0.f;
783}
784
785/*!
786 \qmlproperty real QtMultimedia::Camera::maximumZoomFactor
787
788 This property holds the maximum zoom factor supported.
789
790 This will be \c 1.0 on cameras that do not support zooming.
791*/
792
793
794/*!
795 \property QCamera::maximumZoomFactor
796
797 Returns the maximum zoom factor.
798
799 This will be \c 1.0 on cameras that do not support zooming.
800*/
801
802float QCamera::maximumZoomFactor() const
803{
804 Q_D(const QCamera);
805 return d->control ? d->control->maxZoomFactor() : 1.f;
806}
807
808/*!
809 \qmlproperty real QtMultimedia::Camera::minimumZoomFactor
810
811 This property holds the minimum zoom factor supported.
812
813 This will be \c 1.0 on cameras that do not support zooming.
814*/
815
816/*!
817 \property QCamera::minimumZoomFactor
818
819 Returns the minimum zoom factor.
820
821 This will be \c 1.0 on cameras that do not support zooming.
822*/
823
824float QCamera::minimumZoomFactor() const
825{
826 Q_D(const QCamera);
827 return d->control ? d->control->minZoomFactor() : 1.f;
828}
829
830/*!
831 \qmlproperty real QtMultimedia::Camera::zoomFactor
832
833 Gets or sets the current zoom factor. Values will be clamped between
834 \l minimumZoomFactor and \l maximumZoomFactor.
835*/
836
837/*!
838 \property QCamera::zoomFactor
839 \brief The current zoom factor.
840
841 Gets or sets the current zoom factor. Values will be clamped between
842 \l minimumZoomFactor and \l maximumZoomFactor.
843*/
844float QCamera::zoomFactor() const
845{
846 Q_D(const QCamera);
847 return d->control ? d->control->zoomFactor() : 1.f;
848}
849/*!
850 Zooms to a zoom factor \a factor at a rate of 1 factor per second.
851 */
852void QCamera::setZoomFactor(float factor)
853{
854 zoomTo(factor, 0.f);
855}
856
857/*!
858 \qmlmethod void QtMultimedia::Camera::zoomTo(factor, rate)
859
860 Zooms to a zoom factor \a factor using \a rate.
861
862 The \a rate is specified in powers of two per second. At a rate of 1
863 it would take 2 seconds to go from a zoom factor of 1 to 4.
864
865 \note Using a specific rate is not supported on all cameras. If not supported,
866 zooming will happen as fast as possible.
867*/
868
869/*!
870 Zooms to a zoom factor \a factor using \a rate.
871
872 The \a rate is specified in powers of two per second. At a rate of 1
873 it would take 2 seconds to go from a zoom factor of 1 to 4.
874
875 \note Using a specific rate is not supported on all cameras. If not supported,
876 zooming will happen as fast as possible.
877*/
878void QCamera::zoomTo(float factor, float rate)
879{
880 Q_ASSERT(rate >= 0.f);
881 if (rate < 0.f)
882 rate = 0.f;
883
884 Q_D(QCamera);
885 if (!d->control)
886 return;
887 factor = qBound(d->control->minZoomFactor(), factor, d->control->maxZoomFactor());
888 d->control->zoomTo(factor, rate);
889}
890
891/*!
892 \enum QCamera::FocusMode
893
894 \value FocusModeAuto Continuous auto focus mode.
895 \value FocusModeAutoNear Continuous auto focus mode on near objects.
896 \value FocusModeAutoFar Continuous auto focus mode on objects far away.
897 \value FocusModeHyperfocal Focus to hyperfocal distance, with the maximum depth of field achieved.
898 All objects at distances from half of this
899 distance out to infinity will be acceptably sharp.
900 \value FocusModeInfinity Focus strictly to infinity.
901 \value FocusModeManual Camera lens focus distance is locked according to \l focusDistance.
902*/
903
904/*!
905 \qmlproperty enumeration QtMultimedia::Camera::flashMode
906
907 Gets or sets a certain flash mode if the camera has a flash.
908
909 Assigning an unsupported mode to this property has no effect.
910
911 This property only has an effect when capturing images using
912 \l ImageCapture
913
914 \qmlenumeratorsfrom QCamera::FlashMode
915
916 \sa isFlashModeSupported(), isFlashReady(), flashReady
917*/
918
919/*!
920 \property QCamera::flashMode
921 \brief The flash mode being used.
922
923 Enables a certain flash mode if the camera has a flash.
924
925 Assigning an unsupported mode to this property has no effect.
926
927 This property only has an effect when capturing images using
928 \l QImageCapture
929
930 \sa QCamera::FlashMode, QCamera::isFlashModeSupported, QCamera::isFlashReady
931*/
932QCamera::FlashMode QCamera::flashMode() const
933{
934 Q_D(const QCamera);
935 return d->control ? d->control->flashMode() : QCamera::FlashOff;
936}
937
938void QCamera::setFlashMode(QCamera::FlashMode mode)
939{
940 Q_D(QCamera);
941 if (d->control)
942 d->control->setFlashMode(mode);
943}
944
945/*!
946 \qmlmethod bool QtMultimedia::Camera::isFlashModeSupported(FlashMode mode)
947
948 Returns true if the flash \a mode is supported.
949*/
950
951/*!
952 Returns true if the flash \a mode is supported.
953*/
954bool QCamera::isFlashModeSupported(QCamera::FlashMode mode) const
955{
956 Q_D(const QCamera);
957 return d->control ? d->control->isFlashModeSupported(mode) : (mode == FlashOff);
958}
959
960/*!
961 \qmlmethod bool QtMultimedia::Camera::isFlashReady()
962
963 Returns true if flash is charged.
964*/
965
966/*!
967 Returns true if flash is charged.
968*/
969bool QCamera::isFlashReady() const
970{
971 Q_D(const QCamera);
972 return d->control ? d->control->isFlashReady() : false;
973}
974
975/*!
976 \qmlproperty enumeration Camera::torchMode
977
978 Gets or sets the torch mode being used.
979
980 A torch is a continuous source of light. It can be used during video recording in
981 low light conditions. Enabling torch mode will usually override any currently set
982 flash mode.
983
984 \qmlenumeratorsfrom QCamera::TorchMode
985
986 \sa isTorchModeSupported(), flashMode
987*/
988
989/*!
990 \property QCamera::torchMode
991 \brief The torch mode being used.
992
993 A torch is a continuous source of light. It can be used during video recording in
994 low light conditions. Enabling torch mode will usually override any currently set
995 flash mode.
996
997 \sa QCamera::TorchMode, QCamera::isTorchModeSupported, QCamera::flashMode
998*/
999QCamera::TorchMode QCamera::torchMode() const
1000{
1001 Q_D(const QCamera);
1002 return d->control ? d->control->torchMode() : TorchOff;
1003}
1004
1005void QCamera::setTorchMode(QCamera::TorchMode mode)
1006{
1007 Q_D(QCamera);
1008 if (d->control)
1009 d->control->setTorchMode(mode);
1010}
1011
1012/*!
1013 \qmlmethod bool QtMultimedia::Camera::isTorchModeSupported(TorchMode mode)
1014
1015 Returns true if the torch \a mode is supported.
1016*/
1017
1018/*!
1019 Returns true if the torch \a mode is supported.
1020*/
1021bool QCamera::isTorchModeSupported(QCamera::TorchMode mode) const
1022{
1023 Q_D(const QCamera);
1024 return d->control ? d->control->isTorchModeSupported(mode) : (mode == TorchOff);
1025}
1026
1027/*!
1028 \qmlproperty enumeration QtMultimedia::Camera::exposureMode
1029 \brief The exposure mode being used.
1030
1031 \qmlenumeratorsfrom QCamera::ExposureMode
1032
1033 \sa isExposureModeSupported()
1034*/
1035
1036/*!
1037 \property QCamera::exposureMode
1038 \brief The exposure mode being used.
1039
1040 \sa QCamera::isExposureModeSupported
1041*/
1042QCamera::ExposureMode QCamera::exposureMode() const
1043{
1044 Q_D(const QCamera);
1045 return d->control ? d->control->exposureMode() : QCamera::ExposureAuto;
1046}
1047
1048void QCamera::setExposureMode(QCamera::ExposureMode mode)
1049{
1050 Q_D(QCamera);
1051 if (d->control)
1052 d->control->setExposureMode(mode);
1053}
1054
1055/*!
1056 \qmlmethod bool QtMultimedia::Camera::isExposureModeSupported(ExposureMode mode)
1057
1058 Returns true if the exposure \a mode is supported.
1059*/
1060
1061/*!
1062 Returns true if the exposure \a mode is supported.
1063*/
1064bool QCamera::isExposureModeSupported(QCamera::ExposureMode mode) const
1065{
1066 Q_D(const QCamera);
1067 return d->control && d->control->isExposureModeSupported(mode);
1068}
1069
1070/*!
1071 \qmlproperty real QtMultimedia::Camera::exposureCompensation
1072
1073 Gets or sets the exposure compensation in EV units.
1074
1075 Exposure compensation property allows to adjust the automatically calculated
1076 exposure.
1077*/
1078
1079/*!
1080 \property QCamera::exposureCompensation
1081 \brief Exposure compensation in EV units.
1082
1083 Exposure compensation property allows to adjust the automatically calculated
1084 exposure.
1085*/
1086float QCamera::exposureCompensation() const
1087{
1088 Q_D(const QCamera);
1089 return d->control ? d->control->exposureCompensation() : 0.f;
1090}
1091
1092void QCamera::setExposureCompensation(float ev)
1093{
1094 Q_D(QCamera);
1095 if (d->control)
1096 d->control->setExposureCompensation(ev);
1097}
1098
1099/*!
1100 \qmlproperty int QtMultimedia::Camera::isoSensitivity
1101
1102 Describes the ISO sensitivity currently used by the camera.
1103
1104*/
1105
1106/*!
1107 \property QCamera::isoSensitivity
1108 \brief The sensor ISO sensitivity.
1109
1110 Describes the ISO sensitivity currently used by the camera.
1111
1112 \sa setAutoIsoSensitivity(), setManualIsoSensitivity()
1113*/
1114int QCamera::isoSensitivity() const
1115{
1116 Q_D(const QCamera);
1117 return d->control ? d->control->isoSensitivity() : -1;
1118}
1119
1120/*!
1121 \qmlproperty int QtMultimedia::Camera::manualIsoSensitivity
1122
1123 Describes a manually set ISO sensitivity
1124
1125 Setting this property to -1 (the default), implies that the camera
1126 automatically adjusts the ISO sensitivity.
1127*/
1128
1129/*!
1130 \property QCamera::manualIsoSensitivity
1131 \brief 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*/
1136void QCamera::setManualIsoSensitivity(int iso)
1137{
1138 Q_D(QCamera);
1139 if (iso <= 0)
1140 iso = -1;
1141 if (d->control)
1142 d->control->setManualIsoSensitivity(iso);
1143}
1144
1145int QCamera::manualIsoSensitivity() const
1146{
1147 Q_D(const QCamera);
1148 return d->control ? d->control->manualIsoSensitivity() : 100;
1149}
1150
1151/*!
1152 \fn QCamera::setAutoIsoSensitivity()
1153 Turn on auto sensitivity
1154*/
1155
1156void QCamera::setAutoIsoSensitivity()
1157{
1158 Q_D(QCamera);
1159 if (d->control)
1160 d->control->setManualIsoSensitivity(-1);
1161}
1162
1163/*!
1164 Returns the minimum ISO sensitivity supported by the camera.
1165*/
1166int QCamera::minimumIsoSensitivity() const
1167{
1168 Q_D(const QCamera);
1169 return d->control ? d->control->minIso() : -1;
1170}
1171
1172/*!
1173 Returns the maximum ISO sensitivity supported by the camera.
1174*/
1175int QCamera::maximumIsoSensitivity() const
1176{
1177 Q_D(const QCamera);
1178 return d->control ? d->control->maxIso() : -1;
1179}
1180
1181/*!
1182 The minimal exposure time in seconds.
1183*/
1184float QCamera::minimumExposureTime() const
1185{
1186 Q_D(const QCamera);
1187 return d->control ? d->control->minExposureTime() : -1.f;
1188}
1189
1190/*!
1191 The maximal exposure time in seconds.
1192*/
1193float QCamera::maximumExposureTime() const
1194{
1195 Q_D(const QCamera);
1196 return d->control ? d->control->maxExposureTime() : -1.f;
1197}
1198
1199/*!
1200 \qmlproperty real QtMultimedia::Camera::exposureTime
1201 Returns the Camera's exposure time in seconds.
1202
1203 \sa manualExposureTime
1204*/
1205
1206/*!
1207 \property QCamera::exposureTime
1208 \brief Camera's exposure time in seconds.
1209
1210 \sa minimumExposureTime(), maximumExposureTime(), setManualExposureTime()
1211*/
1212
1213/*!
1214 \fn QCamera::exposureTimeChanged(float speed)
1215
1216 Signals that a camera's exposure \a speed has changed.
1217*/
1218
1219/*!
1220 Returns the current exposure time in seconds.
1221*/
1222
1223float QCamera::exposureTime() const
1224{
1225 Q_D(const QCamera);
1226 return d->control ? d->control->exposureTime() : -1;
1227}
1228
1229/*!
1230 \qmlproperty real QtMultimedia::Camera::manualExposureTime
1231
1232 Gets or sets a manual exposure time.
1233
1234 Setting this property to -1 (the default) means that the camera
1235 automatically determines the exposure time.
1236*/
1237
1238/*!
1239 \property QCamera::manualExposureTime
1240
1241 Set the manual exposure time to \a seconds
1242*/
1243
1244void QCamera::setManualExposureTime(float seconds)
1245{
1246 Q_D(QCamera);
1247 if (d->control)
1248 d->control->setManualExposureTime(seconds);
1249}
1250
1251/*!
1252 Returns the manual exposure time in seconds, or -1
1253 if the camera is using automatic exposure times.
1254*/
1255float QCamera::manualExposureTime() const
1256{
1257 Q_D(const QCamera);
1258 return d->control ? d->control->manualExposureTime() : -1;
1259}
1260
1261/*!
1262 Use automatically calculated exposure time
1263*/
1264void QCamera::setAutoExposureTime()
1265{
1266 Q_D(QCamera);
1267 if (d->control)
1268 d->control->setManualExposureTime(-1);
1269}
1270
1271
1272/*!
1273 \enum QCamera::FlashMode
1274
1275 \value FlashOff Flash is Off.
1276 \value FlashOn Flash is On.
1277 \value FlashAuto Automatic flash.
1278*/
1279
1280/*!
1281 \enum QCamera::TorchMode
1282
1283 \value TorchOff Torch is Off.
1284 \value TorchOn Torch is On.
1285 \value TorchAuto Automatic torch.
1286*/
1287
1288/*!
1289 \enum QCamera::ExposureMode
1290
1291 \value ExposureAuto Automatic mode.
1292 \value ExposureManual Manual mode.
1293 \value ExposurePortrait Portrait exposure mode.
1294 \value ExposureNight Night mode.
1295 \value ExposureSports Spots exposure mode.
1296 \value ExposureSnow Snow exposure mode.
1297 \value ExposureBeach Beach exposure mode.
1298 \value ExposureAction Action mode. Since 5.5
1299 \value ExposureLandscape Landscape mode. Since 5.5
1300 \value ExposureNightPortrait Night portrait mode. Since 5.5
1301 \value ExposureTheatre Theatre mode. Since 5.5
1302 \value ExposureSunset Sunset mode. Since 5.5
1303 \value ExposureSteadyPhoto Steady photo mode. Since 5.5
1304 \value ExposureFireworks Fireworks mode. Since 5.5
1305 \value ExposureParty Party mode. Since 5.5
1306 \value ExposureCandlelight Candlelight mode. Since 5.5
1307 \value ExposureBarcode Barcode mode. Since 5.5
1308*/
1309
1310/*!
1311 \qmlproperty bool QtMultimedia::Camera::flashReady
1312
1313 Indicates if the flash is charged and ready to use.
1314*/
1315
1316/*!
1317 \property QCamera::flashReady
1318 \brief Indicates if the flash is charged and ready to use.
1319*/
1320
1321/*!
1322 \fn void QCamera::flashReady(bool ready)
1323
1324 Signal the flash \a ready status has changed.
1325*/
1326
1327/*!
1328 \fn void QCamera::isoSensitivityChanged(int value)
1329
1330 Signal emitted when sensitivity changes to \a value.
1331*/
1332
1333/*!
1334 \fn void QCamera::exposureCompensationChanged(float value)
1335
1336 Signal emitted when the exposure compensation changes to \a value.
1337*/
1338
1339
1340/*!
1341 \qmlproperty enumeration QtMultimedia::Camera::whiteBalanceMode
1342
1343 Gets or sets the white balance mode being used.
1344
1345 \qmlenumeratorsfrom QCamera::WhiteBalanceMode
1346
1347 \sa isWhiteBalanceModeSupported()
1348*/
1349
1350/*!
1351 \property QCamera::whiteBalanceMode
1352
1353 Returns the white balance mode being used.
1354*/
1355QCamera::WhiteBalanceMode QCamera::whiteBalanceMode() const
1356{
1357 Q_D(const QCamera);
1358 return d->control ? d->control->whiteBalanceMode() : QCamera::WhiteBalanceAuto;
1359}
1360
1361/*!
1362 Sets the white balance to \a mode.
1363*/
1364void QCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode)
1365{
1366 Q_D(QCamera);
1367 if (!d->control)
1368 return;
1369 if (!d->control->isWhiteBalanceModeSupported(mode))
1370 return;
1371 d->control->setWhiteBalanceMode(mode);
1372 if (mode == QCamera::WhiteBalanceManual)
1373 d->control->setColorTemperature(5600);
1374}
1375
1376/*!
1377 \qmlmethod bool QtMultimedia::Camera::isWhiteBalanceModeSupported(WhiteBalanceMode mode)
1378
1379 Returns true if the white balance \a mode is supported.
1380*/
1381
1382/*!
1383 Returns true if the white balance \a mode is supported.
1384*/
1385bool QCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const
1386{
1387 Q_D(const QCamera);
1388 return d->control && d->control->isWhiteBalanceModeSupported(mode);
1389}
1390
1391/*!
1392 \qmlmethod QtMultimedia::Camera::colorTemperature
1393
1394 Gets or sets the current color temperature.
1395
1396 Setting a color temperature will only have an effect if WhiteBalanceManual is
1397 supported. In this case, setting a temperature greater 0 will automatically set the
1398 white balance mode to WhiteBalanceManual. Setting the temperature to 0 will reset
1399 the white balance mode to WhiteBalanceAuto.
1400*/
1401
1402/*!
1403 \property QCamera::colorTemperature
1404
1405 Returns the current color temperature if the
1406 current white balance mode is \c WhiteBalanceManual. For other modes the
1407 return value is undefined.
1408*/
1409int QCamera::colorTemperature() const
1410{
1411 Q_D(const QCamera);
1412 return d->control ? d->control->colorTemperature() : 0;
1413}
1414
1415/*!
1416 Sets manual white balance to \a colorTemperature. This is used
1417 when whiteBalanceMode() is set to \c WhiteBalanceManual. The units are Kelvin.
1418
1419 Setting a color temperature will only have an effect if WhiteBalanceManual is
1420 supported. In this case, setting a temperature greater 0 will automatically set the
1421 white balance mode to WhiteBalanceManual. Setting the temperature to 0 will reset
1422 the white balance mode to WhiteBalanceAuto.
1423*/
1424
1425void QCamera::setColorTemperature(int colorTemperature)
1426{
1427 Q_D(QCamera);
1428 if (!d->control)
1429 return;
1430 if (colorTemperature < 0)
1431 colorTemperature = 0;
1432 if (colorTemperature == 0) {
1433 d->control->setWhiteBalanceMode(WhiteBalanceAuto);
1434 } else if (!isWhiteBalanceModeSupported(WhiteBalanceManual)) {
1435 return;
1436 } else {
1437 d->control->setWhiteBalanceMode(WhiteBalanceManual);
1438 }
1439 d->control->setColorTemperature(colorTemperature);
1440}
1441
1442/*!
1443 \enum QCamera::WhiteBalanceMode
1444
1445 \value WhiteBalanceAuto Auto white balance mode.
1446 \value WhiteBalanceManual Manual white balance. In this mode the white
1447 balance should be set with setColorTemperature()
1448 \value WhiteBalanceSunlight Sunlight white balance mode.
1449 \value WhiteBalanceCloudy Cloudy white balance mode.
1450 \value WhiteBalanceShade Shade white balance mode.
1451 \value WhiteBalanceTungsten Tungsten (incandescent) white balance mode.
1452 \value WhiteBalanceFluorescent Fluorescent white balance mode.
1453 \value WhiteBalanceFlash Flash white balance mode.
1454 \value WhiteBalanceSunset Sunset white balance mode.
1455*/
1456
1457/*!
1458 \fn void QCamera::brightnessChanged()
1459 \internal
1460*/
1461/*!
1462 \fn void QCamera::contrastChanged()
1463 \internal
1464*/
1465/*!
1466 \fn void QCamera::hueChanged()
1467 \internal
1468*/
1469/*!
1470 \fn void QCamera::saturationChanged()
1471 \internal
1472*/
1473QT_END_NAMESPACE
1474
1475#include "moc_qcamera.cpp"
QPlatformCamera * control
Definition qcamera_p.h:34
Combined button and popup list for selecting options.