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