1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the plugins of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qdeclarativecamera_p.h" |
41 | #include "qdeclarativecamerapreviewprovider_p.h" |
42 | |
43 | #include "qdeclarativecameraexposure_p.h" |
44 | #include "qdeclarativecameraflash_p.h" |
45 | #include "qdeclarativecamerafocus_p.h" |
46 | #include "qdeclarativecameraimageprocessing_p.h" |
47 | #include "qdeclarativecameraviewfinder_p.h" |
48 | |
49 | #include "qdeclarativemediametadata_p.h" |
50 | |
51 | #include <qmediaplayercontrol.h> |
52 | #include <qmediaservice.h> |
53 | #include <qvideorenderercontrol.h> |
54 | #include <qvideodeviceselectorcontrol.h> |
55 | #include <QtQml/qqmlinfo.h> |
56 | |
57 | #include <QtCore/QTimer> |
58 | #include <QtGui/qevent.h> |
59 | |
60 | QT_BEGIN_NAMESPACE |
61 | |
62 | void QDeclarativeCamera::_q_errorOccurred(QCamera::Error errorCode) |
63 | { |
64 | emit error(errorCode: Error(errorCode), errorString: errorString()); |
65 | emit errorOccurred(errorCode: Error(errorCode), errorString: errorString()); |
66 | emit errorChanged(); |
67 | } |
68 | |
69 | void QDeclarativeCamera::_q_updateState(QCamera::State state) |
70 | { |
71 | emit cameraStateChanged(QDeclarativeCamera::State(state)); |
72 | } |
73 | |
74 | void QDeclarativeCamera::_q_availabilityChanged(QMultimedia::AvailabilityStatus availability) |
75 | { |
76 | emit availabilityChanged(availability: Availability(availability)); |
77 | } |
78 | |
79 | /*! |
80 | \qmltype Camera |
81 | \instantiates QDeclarativeCamera |
82 | \brief Access viewfinder frames, and take photos and movies. |
83 | \ingroup multimedia_qml |
84 | \ingroup camera_qml |
85 | \inqmlmodule QtMultimedia |
86 | |
87 | \inherits QtObject |
88 | |
89 | You can use \c Camera to capture images and movies from a camera, and manipulate |
90 | the capture and processing settings that get applied to the images. To display the |
91 | viewfinder you can use \l VideoOutput with the Camera set as the source. |
92 | |
93 | \qml |
94 | Item { |
95 | width: 640 |
96 | height: 360 |
97 | |
98 | Camera { |
99 | id: camera |
100 | |
101 | imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash |
102 | |
103 | exposure { |
104 | exposureCompensation: -1.0 |
105 | exposureMode: Camera.ExposurePortrait |
106 | } |
107 | |
108 | flash.mode: Camera.FlashRedEyeReduction |
109 | |
110 | imageCapture { |
111 | onImageCaptured: { |
112 | photoPreview.source = preview // Show the preview in an Image |
113 | } |
114 | } |
115 | } |
116 | |
117 | VideoOutput { |
118 | source: camera |
119 | anchors.fill: parent |
120 | focus : visible // to receive focus and capture key events when visible |
121 | } |
122 | |
123 | Image { |
124 | id: photoPreview |
125 | } |
126 | } |
127 | \endqml |
128 | |
129 | If multiple cameras are available, you can select which one to use by setting the \l deviceId |
130 | property to a value from |
131 | \l{QtMultimedia::QtMultimedia::availableCameras}{QtMultimedia.availableCameras}. |
132 | On a mobile device, you can conveniently switch between front-facing and back-facing cameras |
133 | by setting the \l position property. |
134 | |
135 | The various settings and functionality of the Camera stack is spread |
136 | across a few different child properties of Camera. |
137 | |
138 | \table |
139 | \header \li Property \li Description |
140 | \row \li \l {CameraCapture} {imageCapture} |
141 | \li Methods and properties for capturing still images. |
142 | \row \li \l {CameraRecorder} {videoRecorder} |
143 | \li Methods and properties for capturing movies. |
144 | \row \li \l {CameraExposure} {exposure} |
145 | \li Methods and properties for adjusting exposure (aperture, shutter speed etc). |
146 | \row \li \l {CameraFocus} {focus} |
147 | \li Methods and properties for adjusting focus and providing feedback on autofocus progress. |
148 | \row \li \l {CameraFlash} {flash} |
149 | \li Methods and properties for controlling the camera flash. |
150 | \row \li \l {CameraImageProcessing} {imageProcessing} |
151 | \li Methods and properties for adjusting camera image processing parameters. |
152 | \endtable |
153 | |
154 | Basic camera state management, error reporting, and simple zoom properties are |
155 | available in the Camera itself. For integration with C++ code, the |
156 | \l mediaObject property allows you to |
157 | access the standard Qt Multimedia camera controls. |
158 | |
159 | Many of the camera settings may take some time to apply, and might be limited |
160 | to certain supported values depending on the hardware. Some camera settings may be |
161 | set manually or automatically. These settings properties contain the current set value. |
162 | For example, when autofocus is enabled the focus zones are exposed in the |
163 | \l {CameraFocus}{focus} property. |
164 | |
165 | For additional information, read also the \l{Camera Overview}{camera overview}. |
166 | */ |
167 | |
168 | /*! |
169 | \class QDeclarativeCamera |
170 | \internal |
171 | \brief The QDeclarativeCamera class provides a camera item that you can add to a QQuickView. |
172 | */ |
173 | |
174 | /*! |
175 | Construct a declarative camera object using \a parent object. |
176 | */ |
177 | QDeclarativeCamera::QDeclarativeCamera(QObject *parent) : |
178 | QObject(parent), |
179 | m_camera(0), |
180 | m_metaData(0), |
181 | m_pendingState(ActiveState), |
182 | m_componentComplete(false) |
183 | { |
184 | m_currentCameraInfo = QCameraInfo::defaultCamera(); |
185 | m_camera = new QCamera(m_currentCameraInfo); |
186 | |
187 | m_imageCapture = new QDeclarativeCameraCapture(m_camera); |
188 | m_videoRecorder = new QDeclarativeCameraRecorder(m_camera); |
189 | m_exposure = new QDeclarativeCameraExposure(m_camera); |
190 | m_flash = new QDeclarativeCameraFlash(m_camera); |
191 | m_focus = new QDeclarativeCameraFocus(m_camera); |
192 | m_imageProcessing = new QDeclarativeCameraImageProcessing(m_camera); |
193 | m_viewfinder = new QDeclarativeCameraViewfinder(m_camera); |
194 | |
195 | connect(sender: m_camera, SIGNAL(captureModeChanged(QCamera::CaptureModes)), |
196 | receiver: this, SIGNAL(captureModeChanged())); |
197 | connect(sender: m_camera, SIGNAL(lockStatusChanged(QCamera::LockStatus,QCamera::LockChangeReason)), |
198 | receiver: this, SIGNAL(lockStatusChanged())); |
199 | connect(sender: m_camera, signal: &QCamera::stateChanged, receiver: this, slot: &QDeclarativeCamera::_q_updateState); |
200 | connect(sender: m_camera, SIGNAL(statusChanged(QCamera::Status)), receiver: this, SIGNAL(cameraStatusChanged())); |
201 | connect(sender: m_camera, SIGNAL(errorOccurred(QCamera::Error)), receiver: this, SLOT(_q_errorOccurred(QCamera::Error))); |
202 | connect(sender: m_camera, SIGNAL(availabilityChanged(QMultimedia::AvailabilityStatus)), |
203 | receiver: this, SLOT(_q_availabilityChanged(QMultimedia::AvailabilityStatus))); |
204 | |
205 | connect(sender: m_camera->focus(), signal: &QCameraFocus::opticalZoomChanged, |
206 | receiver: this, slot: &QDeclarativeCamera::opticalZoomChanged); |
207 | connect(sender: m_camera->focus(), signal: &QCameraFocus::digitalZoomChanged, |
208 | receiver: this, slot: &QDeclarativeCamera::digitalZoomChanged); |
209 | connect(sender: m_camera->focus(), signal: &QCameraFocus::maximumOpticalZoomChanged, |
210 | receiver: this, slot: &QDeclarativeCamera::maximumOpticalZoomChanged); |
211 | connect(sender: m_camera->focus(), signal: &QCameraFocus::maximumDigitalZoomChanged, |
212 | receiver: this, slot: &QDeclarativeCamera::maximumDigitalZoomChanged); |
213 | } |
214 | |
215 | /*! Destructor, clean up memory */ |
216 | QDeclarativeCamera::~QDeclarativeCamera() |
217 | { |
218 | m_camera->unload(); |
219 | |
220 | // These must be deleted before QCamera |
221 | delete m_imageCapture; |
222 | delete m_videoRecorder; |
223 | delete m_exposure; |
224 | delete m_flash; |
225 | delete m_focus; |
226 | delete m_imageProcessing; |
227 | delete m_metaData; |
228 | delete m_viewfinder; |
229 | |
230 | delete m_camera; |
231 | } |
232 | |
233 | void QDeclarativeCamera::classBegin() |
234 | { |
235 | } |
236 | |
237 | void QDeclarativeCamera::componentComplete() |
238 | { |
239 | m_componentComplete = true; |
240 | setCameraState(m_pendingState); |
241 | } |
242 | |
243 | /*! |
244 | \qmlproperty string QtMultimedia::Camera::deviceId |
245 | |
246 | This property holds the unique identifier for the camera device being used. It may not be human-readable. |
247 | |
248 | You can get all available device IDs from \l{QtMultimedia::QtMultimedia::availableCameras}{QtMultimedia.availableCameras}. |
249 | If no value is provided or if set to an empty string, the system's default camera will be used. |
250 | |
251 | If possible, \l cameraState, \l captureMode, \l digitalZoom and other camera parameters are |
252 | preserved when changing the camera device. |
253 | |
254 | \sa displayName, position |
255 | \since 5.4 |
256 | */ |
257 | |
258 | QString QDeclarativeCamera::deviceId() const |
259 | { |
260 | return m_currentCameraInfo.deviceName(); |
261 | } |
262 | |
263 | void QDeclarativeCamera::setDeviceId(const QString &name) |
264 | { |
265 | if (name == m_currentCameraInfo.deviceName()) |
266 | return; |
267 | |
268 | setupDevice(name); |
269 | } |
270 | |
271 | /*! |
272 | \qmlproperty enumeration QtMultimedia::Camera::position |
273 | |
274 | This property holds the physical position of the camera on the hardware system. |
275 | |
276 | On a mobile device, this property can be used to easily choose between |
277 | front-facing and back-facing cameras. If this property is set to |
278 | \c Camera.UnspecifiedPosition, the system's default camera is used. |
279 | |
280 | If possible, \l cameraState, \l captureMode, \l digitalZoom and other camera |
281 | parameters are preserved when changing the camera device. |
282 | |
283 | \value Camera.UnspecifiedPosition |
284 | The camera position is unspecified or unknown. |
285 | \value Camera.BackFace |
286 | The camera is on the back face of the system hardware. For example, |
287 | on a mobile device, it is on side opposite from the screen. |
288 | \value Camera.FrontFace |
289 | The camera is on the front face of the system hardware. For example, |
290 | on a mobile device, it means it is on the same side as the screen. |
291 | Viewfinder frames of front-facing cameras are mirrored horizontally, |
292 | so the users can see themselves as looking into a mirror. Captured |
293 | images or videos are not mirrored. |
294 | |
295 | \sa deviceId |
296 | \since 5.4 |
297 | */ |
298 | |
299 | QDeclarativeCamera::Position QDeclarativeCamera::position() const |
300 | { |
301 | return QDeclarativeCamera::Position(m_currentCameraInfo.position()); |
302 | } |
303 | |
304 | void QDeclarativeCamera::setPosition(Position position) |
305 | { |
306 | QCamera::Position pos = QCamera::Position(position); |
307 | if (pos == m_currentCameraInfo.position()) |
308 | return; |
309 | |
310 | QString id; |
311 | |
312 | if (pos == QCamera::UnspecifiedPosition) { |
313 | id = QCameraInfo::defaultCamera().deviceName(); |
314 | } else { |
315 | QList<QCameraInfo> cameras = QCameraInfo::availableCameras(position: pos); |
316 | if (!cameras.isEmpty()) |
317 | id = cameras.first().deviceName(); |
318 | } |
319 | |
320 | if (!id.isEmpty()) |
321 | setupDevice(id); |
322 | } |
323 | |
324 | /*! |
325 | \qmlproperty string QtMultimedia::Camera::displayName |
326 | |
327 | This property holds the human-readable name of the camera. |
328 | |
329 | You can use this property to display the name of the camera in a user interface. |
330 | |
331 | \readonly |
332 | \sa deviceId |
333 | \since 5.4 |
334 | */ |
335 | |
336 | QString QDeclarativeCamera::displayName() const |
337 | { |
338 | return m_currentCameraInfo.description(); |
339 | } |
340 | |
341 | /*! |
342 | \qmlproperty int QtMultimedia::Camera::orientation |
343 | |
344 | This property holds the physical orientation of the camera sensor. |
345 | |
346 | The value is the orientation angle (clockwise, in steps of 90 degrees) of the camera sensor in |
347 | relation to the display in its natural orientation. |
348 | |
349 | For example, suppose a mobile device which is naturally in portrait orientation. The back-facing |
350 | camera is mounted in landscape. If the top side of the camera sensor is aligned with the right |
351 | edge of the screen in natural orientation, \c orientation returns \c 270. If the top side of a |
352 | front-facing camera sensor is aligned with the right edge of the screen, \c orientation |
353 | returns \c 90. |
354 | |
355 | \readonly |
356 | \sa VideoOutput::orientation |
357 | \since 5.4 |
358 | */ |
359 | |
360 | int QDeclarativeCamera::orientation() const |
361 | { |
362 | return m_currentCameraInfo.orientation(); |
363 | } |
364 | |
365 | void QDeclarativeCamera::setupDevice(const QString &deviceName) |
366 | { |
367 | QMediaService *service = m_camera->service(); |
368 | if (!service) |
369 | return; |
370 | |
371 | QVideoDeviceSelectorControl *deviceControl = qobject_cast<QVideoDeviceSelectorControl*>(object: service->requestControl(QVideoDeviceSelectorControl_iid)); |
372 | if (!deviceControl) |
373 | return; |
374 | |
375 | int deviceIndex = -1; |
376 | |
377 | if (deviceName.isEmpty()) { |
378 | deviceIndex = deviceControl->defaultDevice(); |
379 | } else { |
380 | for (int i = 0; i < deviceControl->deviceCount(); ++i) { |
381 | if (deviceControl->deviceName(index: i) == deviceName) { |
382 | deviceIndex = i; |
383 | break; |
384 | } |
385 | } |
386 | } |
387 | |
388 | if (deviceIndex == -1) |
389 | return; |
390 | |
391 | State previousState = cameraState(); |
392 | setCameraState(UnloadedState); |
393 | |
394 | deviceControl->setSelectedDevice(deviceIndex); |
395 | |
396 | QCameraInfo oldCameraInfo = m_currentCameraInfo; |
397 | m_currentCameraInfo = QCameraInfo(*m_camera); |
398 | |
399 | emit deviceIdChanged(); |
400 | if (oldCameraInfo.description() != m_currentCameraInfo.description()) |
401 | emit displayNameChanged(); |
402 | if (oldCameraInfo.position() != m_currentCameraInfo.position()) |
403 | emit positionChanged(); |
404 | if (oldCameraInfo.orientation() != m_currentCameraInfo.orientation()) |
405 | emit orientationChanged(); |
406 | |
407 | setCameraState(previousState); |
408 | } |
409 | |
410 | /*! |
411 | Returns any camera error. |
412 | \sa QDeclarativeCameraError::Error |
413 | */ |
414 | QDeclarativeCamera::Error QDeclarativeCamera::errorCode() const |
415 | { |
416 | return QDeclarativeCamera::Error(m_camera->error()); |
417 | } |
418 | |
419 | /*! |
420 | \qmlproperty string QtMultimedia::Camera::errorString |
421 | |
422 | This property holds the last error string, if any. |
423 | |
424 | \sa errorOccurred, errorCode |
425 | */ |
426 | QString QDeclarativeCamera::errorString() const |
427 | { |
428 | return m_camera->errorString(); |
429 | } |
430 | |
431 | /*! |
432 | \qmlproperty enumeration QtMultimedia::Camera::availability |
433 | |
434 | This property holds the availability state of the camera. |
435 | |
436 | \value Camera.Available |
437 | The camera is available for use. |
438 | \value Camera.Busy |
439 | The camera is busy at the moment as it is being used by another |
440 | process. |
441 | \value Camera.Unavailable |
442 | The camera is not available for use (there may be no camera |
443 | hardware). |
444 | \value Camera.ResourceMissing |
445 | The camera cannot be used because of missing resources. |
446 | It may be possible to try again at a later time. |
447 | */ |
448 | QDeclarativeCamera::Availability QDeclarativeCamera::availability() const |
449 | { |
450 | return Availability(m_camera->availability()); |
451 | } |
452 | |
453 | |
454 | /*! |
455 | \qmlproperty enumeration QtMultimedia::Camera::captureMode |
456 | |
457 | This property holds the camera capture mode. The default capture mode is |
458 | \c CaptureStillImage. |
459 | |
460 | \value Camera.CaptureViewfinder |
461 | Camera is only configured to display viewfinder. |
462 | \value Camera.CaptureStillImage |
463 | Prepares the Camera for capturing still images. |
464 | \value Camera.CaptureVideo |
465 | Prepares the Camera for capturing video. |
466 | */ |
467 | QDeclarativeCamera::CaptureMode QDeclarativeCamera::captureMode() const |
468 | { |
469 | return QDeclarativeCamera::CaptureMode(int(m_camera->captureMode())); |
470 | } |
471 | |
472 | void QDeclarativeCamera::setCaptureMode(QDeclarativeCamera::CaptureMode mode) |
473 | { |
474 | m_camera->setCaptureMode(QCamera::CaptureModes(int(mode))); |
475 | } |
476 | |
477 | |
478 | /*! |
479 | \qmlproperty enumeration QtMultimedia::Camera::cameraState |
480 | |
481 | This property holds the camera object's current state. The default camera |
482 | state is \c ActiveState. |
483 | |
484 | \value Camera.UnloadedState |
485 | The initial camera state, with the camera not loaded. |
486 | The camera capabilities (with the exception of supported capture modes) |
487 | are unknown. This state saves the most power, but takes the longest |
488 | time to be ready for capture. |
489 | While the supported settings are unknown in this state, |
490 | you can still set the camera capture settings like codec, |
491 | resolution, or frame rate. |
492 | \value Camera.LoadedState |
493 | The camera is loaded and ready to be configured. |
494 | In this state you can query camera capabilities, |
495 | set capture resolution, codecs, and so on. |
496 | The viewfinder is not active in the loaded state. |
497 | The camera consumes power in this state. |
498 | \value Camera.ActiveState |
499 | In the active state, the viewfinder frames are available |
500 | and the camera is ready for capture. |
501 | */ |
502 | QDeclarativeCamera::State QDeclarativeCamera::cameraState() const |
503 | { |
504 | return m_componentComplete ? QDeclarativeCamera::State(m_camera->state()) : m_pendingState; |
505 | } |
506 | |
507 | /*! |
508 | \qmlproperty enumeration QtMultimedia::Camera::cameraStatus |
509 | |
510 | This property holds the camera object's current status. |
511 | |
512 | \value Camera.ActiveStatus |
513 | The camera has been started and can produce data, |
514 | viewfinder displays video frames. |
515 | Depending on backend, changing camera settings such as |
516 | capture mode, codecs, or resolution in \c {Camera.ActiveState} may |
517 | lead to changing the status to \c LoadedStatus and \c StartingStatus |
518 | while the settings are applied, and back to \c ActiveStatus when |
519 | the camera is ready. |
520 | \value Camera.StartingStatus |
521 | The camera is transitioning to \c {Camera.ActiveState}. The camera |
522 | service is not ready to capture yet. |
523 | \value Camera.StoppingStatus |
524 | The camera is transitioning from \c {Camera.ActiveState} to |
525 | \c {Camera.LoadedState} or \c {Camera.UnloadedState}. |
526 | \value Camera.StandbyStatus |
527 | The camera is in the power saving standby mode. |
528 | The camera may enter standby mode after some time of inactivity |
529 | in the \c {Camera.LoadedState} state. |
530 | \value Camera.LoadedStatus |
531 | The camera is loaded and ready to be configured. |
532 | This status indicates that the camera is opened and it's |
533 | possible to query for supported image and video capture |
534 | settings, such as resolution, frame rate, and codecs. |
535 | \value Camera.LoadingStatus |
536 | The camera is transitioning from \c {Camera.UnloadedState} to |
537 | \c {Camera.LoadedState} or \c {Camera.ActiveState}. |
538 | \value Camera.UnloadingStatus |
539 | The camera is transitioning from \c {Camera.LoadedState} or |
540 | \c {Camera.ActiveState} to \c {Camera.UnloadedState}. |
541 | \value Camera.UnloadedStatus |
542 | The initial camera status, with camera not loaded. |
543 | The camera capabilities including supported capture |
544 | settings may be unknown. |
545 | \value Camera.UnavailableStatus |
546 | The camera or camera backend is not available. |
547 | */ |
548 | QDeclarativeCamera::Status QDeclarativeCamera::cameraStatus() const |
549 | { |
550 | return QDeclarativeCamera::Status(m_camera->status()); |
551 | } |
552 | |
553 | void QDeclarativeCamera::setCameraState(QDeclarativeCamera::State state) |
554 | { |
555 | if (!m_componentComplete) { |
556 | m_pendingState = state; |
557 | return; |
558 | } |
559 | |
560 | switch (state) { |
561 | case QDeclarativeCamera::ActiveState: |
562 | m_camera->start(); |
563 | break; |
564 | case QDeclarativeCamera::UnloadedState: |
565 | m_camera->unload(); |
566 | break; |
567 | case QDeclarativeCamera::LoadedState: |
568 | m_camera->load(); |
569 | break; |
570 | } |
571 | } |
572 | |
573 | /*! |
574 | \qmlmethod QtMultimedia::Camera::start() |
575 | |
576 | Starts the camera. Viewfinder frames will |
577 | be available and image or movie capture will |
578 | be possible. |
579 | */ |
580 | void QDeclarativeCamera::start() |
581 | { |
582 | setCameraState(QDeclarativeCamera::ActiveState); |
583 | } |
584 | |
585 | /*! |
586 | \qmlmethod QtMultimedia::Camera::stop() |
587 | |
588 | Stops the camera, but leaves the camera |
589 | stack loaded. |
590 | |
591 | In this state, the camera still consumes power. |
592 | */ |
593 | void QDeclarativeCamera::stop() |
594 | { |
595 | setCameraState(QDeclarativeCamera::LoadedState); |
596 | } |
597 | |
598 | |
599 | /*! |
600 | \qmlproperty enumeration QtMultimedia::Camera::lockStatus |
601 | |
602 | This property holds the status of all the requested camera locks. |
603 | |
604 | \value Camera.Unlocked |
605 | The application is not interested in camera settings value. |
606 | The camera may keep this parameter without changes, which is common |
607 | with camera focus, or adjust exposure and white balance constantly |
608 | to keep the viewfinder image nice. |
609 | \value Camera.Searching |
610 | The application has requested the camera focus, exposure, or white |
611 | balance lock with searchAndLock(). This state indicates the camera |
612 | is focusing or calculating exposure and white balance. |
613 | \value Camera.Locked |
614 | The camera focus, exposure, or white balance is locked. |
615 | The camera is ready to capture, and the application may check the |
616 | exposure parameters. |
617 | The locked state usually means the requested parameter stays the |
618 | same, except in cases where the parameter is requested to be updated |
619 | constantly. For example, in continuous focusing mode, the focus is |
620 | considered locked as long as the object is in focus, even while the |
621 | actual focusing distance may be constantly changing. |
622 | */ |
623 | /*! |
624 | \property QDeclarativeCamera::lockStatus |
625 | |
626 | This property holds the status of all the requested camera locks. |
627 | */ |
628 | QDeclarativeCamera::LockStatus QDeclarativeCamera::lockStatus() const |
629 | { |
630 | return QDeclarativeCamera::LockStatus(m_camera->lockStatus()); |
631 | } |
632 | |
633 | /*! |
634 | \qmlmethod QtMultimedia::Camera::searchAndLock() |
635 | |
636 | Start focusing, exposure and white balance calculation. |
637 | |
638 | This is appropriate to call when the camera focus button is pressed |
639 | (or on a camera capture button half-press). If the camera supports |
640 | autofocusing, information on the focus zones is available through |
641 | the \l {CameraFocus}{focus} property. |
642 | */ |
643 | void QDeclarativeCamera::searchAndLock() |
644 | { |
645 | m_camera->searchAndLock(); |
646 | } |
647 | |
648 | /*! |
649 | \qmlmethod QtMultimedia::Camera::unlock() |
650 | |
651 | Unlock focus, exposure and white balance locks. |
652 | */ |
653 | void QDeclarativeCamera::unlock() |
654 | { |
655 | m_camera->unlock(); |
656 | } |
657 | /*! |
658 | \property QDeclarativeCamera::maximumOpticalZoom |
659 | |
660 | This property holds the maximum optical zoom factor supported, or 1.0 if optical zoom is not supported. |
661 | */ |
662 | /*! |
663 | \qmlproperty real QtMultimedia::Camera::maximumOpticalZoom |
664 | |
665 | This property holds the maximum optical zoom factor supported, or 1.0 if optical zoom is not supported. |
666 | */ |
667 | qreal QDeclarativeCamera::maximumOpticalZoom() const |
668 | { |
669 | return m_camera->focus()->maximumOpticalZoom(); |
670 | } |
671 | /*! |
672 | \property QDeclarativeCamera::maximumDigitalZoom |
673 | |
674 | This property holds the maximum digital zoom factor supported, or 1.0 if digital zoom is not supported. |
675 | */ |
676 | /*! |
677 | \qmlproperty real QtMultimedia::Camera::maximumDigitalZoom |
678 | |
679 | This property holds the maximum digital zoom factor supported, or 1.0 if digital zoom is not supported. |
680 | */ |
681 | qreal QDeclarativeCamera::maximumDigitalZoom() const |
682 | { |
683 | return m_camera->focus()->maximumDigitalZoom(); |
684 | } |
685 | /*! |
686 | \property QDeclarativeCamera::opticalZoom |
687 | |
688 | This property holds the current optical zoom factor. |
689 | */ |
690 | |
691 | /*! |
692 | \qmlproperty real QtMultimedia::Camera::opticalZoom |
693 | |
694 | This property holds the current optical zoom factor. |
695 | */ |
696 | qreal QDeclarativeCamera::opticalZoom() const |
697 | { |
698 | return m_camera->focus()->opticalZoom(); |
699 | } |
700 | |
701 | void QDeclarativeCamera::setOpticalZoom(qreal value) |
702 | { |
703 | m_camera->focus()->zoomTo(opticalZoom: value, digitalZoom: digitalZoom()); |
704 | } |
705 | /*! |
706 | \property QDeclarativeCamera::digitalZoom |
707 | |
708 | This property holds the current digital zoom factor. |
709 | */ |
710 | /*! |
711 | \qmlproperty real QtMultimedia::Camera::digitalZoom |
712 | |
713 | This property holds the current digital zoom factor. |
714 | */ |
715 | qreal QDeclarativeCamera::digitalZoom() const |
716 | { |
717 | return m_camera->focus()->digitalZoom(); |
718 | } |
719 | |
720 | void QDeclarativeCamera::setDigitalZoom(qreal value) |
721 | { |
722 | m_camera->focus()->zoomTo(opticalZoom: opticalZoom(), digitalZoom: value); |
723 | } |
724 | |
725 | /*! |
726 | \qmlproperty variant QtMultimedia::Camera::mediaObject |
727 | |
728 | This property holds the native media object for the camera. |
729 | |
730 | It can be used to get a pointer to a QCamera object in order to integrate with C++ code. |
731 | |
732 | \code |
733 | QObject *qmlCamera; // The QML Camera object |
734 | QCamera *camera = qvariant_cast<QCamera *>(qmlCamera->property("mediaObject")); |
735 | \endcode |
736 | |
737 | \note This property is not accessible from QML. |
738 | */ |
739 | |
740 | /*! |
741 | \qmlproperty enumeration QtMultimedia::Camera::errorCode |
742 | |
743 | This property holds the last error code. |
744 | |
745 | \value Camera.NoError |
746 | No errors have occurred. |
747 | \value Camera.CameraError |
748 | An error has occurred. |
749 | \value Camera.InvalidRequestError |
750 | System resources do not support the requested functionality. |
751 | \value Camera.ServiceMissingError |
752 | No camera service available. |
753 | \value Camera.NotSupportedFeatureError |
754 | The feature is not supported. |
755 | |
756 | \sa errorOccurred, errorString |
757 | */ |
758 | |
759 | /*! |
760 | \qmlsignal QtMultimedia::Camera::error(errorCode, errorString) |
761 | \obsolete |
762 | |
763 | Use errorOccurred() instead. |
764 | */ |
765 | |
766 | /*! |
767 | \qmlsignal QtMultimedia::Camera::errorOccurred(errorCode, errorString) |
768 | \since 5.15 |
769 | |
770 | This signal is emitted when an error specified by \a errorCode occurs. |
771 | A descriptive string value is available in \a errorString. |
772 | |
773 | The corresponding handler is \c onError. |
774 | |
775 | \sa errorCode, errorString |
776 | */ |
777 | |
778 | /*! |
779 | \qmlsignal Camera::lockStatusChanged() |
780 | |
781 | This signal is emitted when the lock status (focus, exposure etc) changes. |
782 | This can happen when locking (e.g. autofocusing) is complete or has failed. |
783 | |
784 | The corresponding handler is \c onLockStatusChanged. |
785 | */ |
786 | |
787 | /*! |
788 | \qmlsignal Camera::cameraStateChanged(state) |
789 | |
790 | This signal is emitted when the camera state has changed to \a state. Since the |
791 | state changes may take some time to occur this signal may arrive sometime |
792 | after the state change has been requested. |
793 | |
794 | The corresponding handler is \c onCameraStateChanged. |
795 | */ |
796 | |
797 | /*! |
798 | \qmlsignal Camera::opticalZoomChanged(zoom) |
799 | |
800 | This signal is emitted when the optical zoom setting has changed to \a zoom. |
801 | |
802 | The corresponding handler is \c onOpticalZoomChanged. |
803 | */ |
804 | |
805 | /*! |
806 | \qmlsignal Camera::digitalZoomChanged(zoom) |
807 | |
808 | This signal is emitted when the digital zoom setting has changed to \a zoom. |
809 | |
810 | The corresponding handler is \c onDigitalZoomChanged. |
811 | */ |
812 | |
813 | /*! |
814 | \qmlsignal Camera::maximumOpticalZoomChanged(zoom) |
815 | |
816 | This signal is emitted when the maximum optical zoom setting has |
817 | changed to \a zoom. This can occur when you change between video |
818 | and still image capture modes, or the capture settings are changed. |
819 | |
820 | The corresponding handler is \c onMaximumOpticalZoomChanged. |
821 | */ |
822 | |
823 | /*! |
824 | \qmlsignal Camera::maximumDigitalZoomChanged(zoom) |
825 | |
826 | This signal is emitted when the maximum digital zoom setting has |
827 | changed to \a zoom. This can occur when you change between video |
828 | and still image capture modes, or the capture settings are changed. |
829 | |
830 | The corresponding handler is \c onMaximumDigitalZoomChanged. |
831 | */ |
832 | |
833 | /*! |
834 | \qmlpropertygroup QtMultimedia::Camera::metaData |
835 | \qmlproperty variant QtMultimedia::Camera::metaData.cameraManufacturer |
836 | \qmlproperty variant QtMultimedia::Camera::metaData.cameraModel |
837 | \qmlproperty variant QtMultimedia::Camera::metaData.event |
838 | \qmlproperty variant QtMultimedia::Camera::metaData.subject |
839 | \qmlproperty variant QtMultimedia::Camera::metaData.orientation |
840 | \qmlproperty variant QtMultimedia::Camera::metaData.dateTimeOriginal |
841 | \qmlproperty variant QtMultimedia::Camera::metaData.gpsLatitude |
842 | \qmlproperty variant QtMultimedia::Camera::metaData.gpsLongitude |
843 | \qmlproperty variant QtMultimedia::Camera::metaData.gpsAltitude |
844 | \qmlproperty variant QtMultimedia::Camera::metaData.gpsTimestamp |
845 | \qmlproperty variant QtMultimedia::Camera::metaData.gpsTrack |
846 | \qmlproperty variant QtMultimedia::Camera::metaData.gpsSpeed |
847 | \qmlproperty variant QtMultimedia::Camera::metaData.gpsImgDirection |
848 | \qmlproperty variant QtMultimedia::Camera::metaData.gpsProcessingMethod |
849 | |
850 | These properties hold the meta data for the camera captures. |
851 | |
852 | \list |
853 | \li \c metaData.cameraManufacturer holds the name of the manufacturer of the camera. |
854 | \li \c metaData.cameraModel holds the name of the model of the camera. |
855 | \li \c metaData.event holds the event during which the photo or video is to be captured. |
856 | \li \c metaData.subject holds the name of the subject of the capture or recording. |
857 | \li \c metaData.orientation holds the clockwise rotation of the camera at time of capture. |
858 | \li \c metaData.dateTimeOriginal holds the initial time at which the photo or video is captured. |
859 | \li \c metaData.gpsLatitude holds the latitude of the camera in decimal degrees at time of capture. |
860 | \li \c metaData.gpsLongitude holds the longitude of the camera in decimal degrees at time of capture. |
861 | \li \c metaData.gpsAltitude holds the altitude of the camera in meters at time of capture. |
862 | \li \c metaData.gpsTimestamp holds the timestamp of the GPS position data. |
863 | \li \c metaData.gpsTrack holds direction of movement of the camera at the time of |
864 | capture. It is measured in degrees clockwise from north. |
865 | \li \c metaData.gpsSpeed holds the velocity in kilometers per hour of the camera at time of capture. |
866 | \li \c metaData.gpsImgDirection holds direction the camera is facing at the time of capture. |
867 | It is measured in degrees clockwise from north. |
868 | \li \c metaData.gpsProcessingMethod holds the name of the method for determining the GPS position. |
869 | \endlist |
870 | |
871 | \sa {QMediaMetaData} |
872 | \since 5.4 |
873 | */ |
874 | |
875 | QDeclarativeMediaMetaData *QDeclarativeCamera::metaData() |
876 | { |
877 | if (!m_metaData) |
878 | m_metaData = new QDeclarativeMediaMetaData(m_camera); |
879 | return m_metaData; |
880 | } |
881 | |
882 | /*! |
883 | \qmlpropertygroup QtMultimedia::Camera::viewfinder |
884 | \qmlproperty size QtMultimedia::Camera::viewfinder.resolution |
885 | \qmlproperty real QtMultimedia::Camera::viewfinder.minimumFrameRate |
886 | \qmlproperty real QtMultimedia::Camera::viewfinder.maximumFrameRate |
887 | |
888 | These properties hold the viewfinder settings. |
889 | |
890 | \c viewfinder.resolution holds the resolution of the camera viewfinder. If no |
891 | resolution is given or if it is empty, the backend uses a default value. |
892 | |
893 | \c viewfinder.minimumFrameRate holds the minimum frame rate for the viewfinder in |
894 | frames per second. If no value is given or if set to \c 0, the backend uses a default value. |
895 | |
896 | \c viewfinder.maximumFrameRate holds the maximum frame rate for the viewfinder in |
897 | frames per second. If no value is given or if set to \c 0, the backend uses a default value. |
898 | |
899 | If \c viewfinder.minimumFrameRate is equal to \c viewfinder.maximumFrameRate, the frame rate is |
900 | fixed. If not, the actual frame rate fluctuates between the two values. |
901 | |
902 | Changing the viewfinder settings while the camera is in the \c Camera.ActiveState state may |
903 | cause the camera to be restarted. |
904 | |
905 | If the camera is used to capture videos or images, the viewfinder settings might be |
906 | ignored if they conflict with the capture settings. You can check the actual viewfinder settings |
907 | once the camera is in the \c Camera.ActiveStatus status. |
908 | |
909 | Supported values can be retrieved with supportedViewfinderResolutions() and |
910 | supportedViewfinderFrameRateRanges(). |
911 | |
912 | \since 5.4 |
913 | */ |
914 | |
915 | QDeclarativeCameraViewfinder *QDeclarativeCamera::viewfinder() |
916 | { |
917 | return m_viewfinder; |
918 | } |
919 | |
920 | /*! |
921 | \qmlmethod list<size> QtMultimedia::Camera::supportedViewfinderResolutions(real minimumFrameRate, real maximumFrameRate) |
922 | |
923 | Returns a list of supported viewfinder resolutions. |
924 | |
925 | If both optional parameters \a minimumFrameRate and \a maximumFrameRate are specified, the |
926 | returned list is reduced to resolutions supported for the given frame rate range. |
927 | |
928 | The camera must be loaded before calling this function, otherwise the returned list |
929 | is empty. |
930 | |
931 | \sa {QtMultimedia::Camera::viewfinder}{viewfinder} |
932 | |
933 | \since 5.5 |
934 | */ |
935 | QJSValue QDeclarativeCamera::supportedViewfinderResolutions(qreal minimumFrameRate, qreal maximumFrameRate) |
936 | { |
937 | QQmlEngine *engine = qmlEngine(this); |
938 | |
939 | QCameraViewfinderSettings settings; |
940 | settings.setMinimumFrameRate(minimumFrameRate); |
941 | settings.setMaximumFrameRate(maximumFrameRate); |
942 | const QList<QSize> resolutions = m_camera->supportedViewfinderResolutions(settings); |
943 | |
944 | QJSValue supportedResolutions = engine->newArray(length: resolutions.count()); |
945 | int i = 0; |
946 | for (const QSize &resolution : resolutions) { |
947 | QJSValue size = engine->newObject(); |
948 | size.setProperty(QStringLiteral("width" ), value: resolution.width()); |
949 | size.setProperty(QStringLiteral("height" ), value: resolution.height()); |
950 | supportedResolutions.setProperty(arrayIndex: i++, value: size); |
951 | } |
952 | |
953 | return supportedResolutions; |
954 | } |
955 | |
956 | /*! |
957 | \qmlmethod list<object> QtMultimedia::Camera::supportedViewfinderFrameRateRanges(size resolution) |
958 | |
959 | Returns a list of supported viewfinder frame rate ranges. |
960 | |
961 | Each range object in the list has the \c minimumFrameRate and \c maximumFrameRate properties. |
962 | |
963 | If the optional parameter \a resolution is specified, the returned list is reduced to frame rate |
964 | ranges supported for the given \a resolution. |
965 | |
966 | The camera must be loaded before calling this function, otherwise the returned list |
967 | is empty. |
968 | |
969 | \sa {QtMultimedia::Camera::viewfinder}{viewfinder} |
970 | |
971 | \since 5.5 |
972 | */ |
973 | QJSValue QDeclarativeCamera::supportedViewfinderFrameRateRanges(const QJSValue &resolution) |
974 | { |
975 | QQmlEngine *engine = qmlEngine(this); |
976 | |
977 | QCameraViewfinderSettings settings; |
978 | if (!resolution.isUndefined()) { |
979 | QJSValue width = resolution.property(QStringLiteral("width" )); |
980 | QJSValue height = resolution.property(QStringLiteral("height" )); |
981 | if (width.isNumber() && height.isNumber()) |
982 | settings.setResolution(width: width.toInt(), height: height.toInt()); |
983 | } |
984 | const QList<QCamera::FrameRateRange> frameRateRanges = m_camera->supportedViewfinderFrameRateRanges(settings); |
985 | |
986 | QJSValue supportedFrameRateRanges = engine->newArray(length: frameRateRanges.count()); |
987 | int i = 0; |
988 | for (const QCamera::FrameRateRange &frameRateRange : frameRateRanges) { |
989 | QJSValue range = engine->newObject(); |
990 | range.setProperty(QStringLiteral("minimumFrameRate" ), value: frameRateRange.minimumFrameRate); |
991 | range.setProperty(QStringLiteral("maximumFrameRate" ), value: frameRateRange.maximumFrameRate); |
992 | supportedFrameRateRanges.setProperty(arrayIndex: i++, value: range); |
993 | } |
994 | |
995 | return supportedFrameRateRanges; |
996 | } |
997 | |
998 | QT_END_NAMESPACE |
999 | |
1000 | #include "moc_qdeclarativecamera_p.cpp" |
1001 | |