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