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