summaryrefslogtreecommitdiffstats
path: root/src/multimedia/camera/qcamera.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/multimedia/camera/qcamera.cpp')
-rw-r--r--src/multimedia/camera/qcamera.cpp1789
1 files changed, 920 insertions, 869 deletions
diff --git a/src/multimedia/camera/qcamera.cpp b/src/multimedia/camera/qcamera.cpp
index b4515cfad..9cfbcc01d 100644
--- a/src/multimedia/camera/qcamera.cpp
+++ b/src/multimedia/camera/qcamera.cpp
@@ -1,87 +1,21 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qcamera_p.h"
-#include "qmediaserviceprovider_p.h"
-
-#include <qcamerainfo.h>
-#include <qcameracontrol.h>
-#include <qcameralockscontrol.h>
-#include <qcameraexposurecontrol.h>
-#include <qcamerafocuscontrol.h>
-#include <qmediarecordercontrol.h>
-#include <qcameraimageprocessingcontrol.h>
-#include <qcameraimagecapturecontrol.h>
-#include <qvideodeviceselectorcontrol.h>
-#include <qcamerainfocontrol.h>
-#include <qcameraviewfindersettingscontrol.h>
+
+#include <qcameradevice.h>
+#include <private/qplatformcamera_p.h>
+#include <private/qplatformimagecapture_p.h>
+#include <private/qplatformmediaintegration_p.h>
+#include <private/qplatformmediacapture_p.h>
+#include <qmediadevices.h>
+#include <qmediacapturesession.h>
#include <QDebug>
QT_BEGIN_NAMESPACE
-static void qRegisterCameraMetaTypes()
-{
- qRegisterMetaType<QCamera::Error>("QCamera::Error");
- qRegisterMetaType<QCamera::State>("QCamera::State");
- qRegisterMetaType<QCamera::Status>("QCamera::Status");
- qRegisterMetaType<QCamera::CaptureModes>("QCamera::CaptureModes");
- qRegisterMetaType<QCamera::LockType>("QCamera::LockType");
- qRegisterMetaType<QCamera::LockStatus>("QCamera::LockStatus");
- qRegisterMetaType<QCamera::LockChangeReason>("QCamera::LockChangeReason");
- qRegisterMetaType<QCamera::Position>("QCamera::Position");
-}
-
-Q_CONSTRUCTOR_FUNCTION(qRegisterCameraMetaTypes)
-
-Q_DECL_CONSTEXPR static bool qt_sizeLessThan(const QSize &s1, const QSize &s2) Q_DECL_NOTHROW
-{
- return (s1.width() * s1.height()) < (s2.width() * s2.height());
-}
-
-Q_DECL_CONSTEXPR static bool qt_frameRateRangeLessThan(const QCamera::FrameRateRange &s1, const QCamera::FrameRateRange &s2) Q_DECL_NOTHROW
-{
- return qFuzzyCompare(s1.maximumFrameRate, s2.maximumFrameRate) ? (s1.minimumFrameRate < s2.minimumFrameRate)
- : (s1.maximumFrameRate < s2.maximumFrameRate);
-}
-
/*!
\class QCamera
@@ -92,301 +26,173 @@ Q_DECL_CONSTEXPR static bool qt_frameRateRangeLessThan(const QCamera::FrameRateR
\ingroup multimedia
\ingroup multimedia_camera
- QCamera can be used with QCameraViewfinder for viewfinder display,
- QMediaRecorder for video recording and QCameraImageCapture for image taking.
+ QCamera can be used within a QMediaCaptureSession for video recording and image taking.
- You can use QCameraInfo to list available cameras and choose which one to use.
+ You can use QCameraDevice to list available cameras and choose which one to use.
\snippet multimedia-snippets/camera.cpp Camera selection
- See the \l{Camera Overview}{camera overview} for more information.
-*/
-
-void QCameraPrivate::_q_error(int error, const QString &errorString)
-{
- Q_Q(QCamera);
+ On hardware that supports it, QCamera lets you adjust the focus
+ and zoom. This also includes functionality such as a
+ "Macro" mode for close up work (e.g. reading barcodes, or
+ recognizing letters), or "touch to focus" - indicating an
+ interesting area of the image for the hardware to attempt
+ to focus on.
- this->error = QCamera::Error(error);
- this->errorString = errorString;
+ \snippet multimedia-snippets/camera.cpp Camera custom focus
- emit q->errorOccurred(this->error);
-}
+ The \l minimumZoomFactor() and \l maximumZoomFactor() methods provide the
+ range of supported zoom factors. The \l zoomTo() method allows changing
+ the zoom factor.
-void QCameraPrivate::setState(QCamera::State newState)
-{
- unsetError();
-
- if (!control) {
- _q_error(QCamera::ServiceMissingError, QCamera::tr("The camera service is missing"));
- return;
- }
+ \snippet multimedia-snippets/camera.cpp Camera zoom
- restartPending = false;
- control->setState(newState);
-}
-void QCameraPrivate::_q_updateState(QCamera::State newState)
-{
- Q_Q(QCamera);
+ After capturing the raw data for a camera frame, the camera hardware and
+ software performs various image processing tasks to produce the final
+ image. This includes compensating for ambient light color, reducing
+ noise, as well as making some other adjustments to the image.
- //omit changins state to Loaded when the camera is temporarily
- //stopped to apply shanges
- if (restartPending)
- return;
+ You can control many of these processing steps through the Camera properties.
+ For example, you can set the white balance (or color temperature) used
+ for processing images:
- if (newState != state) {
- state = newState;
- emit q->stateChanged(state);
- }
-}
+ \snippet multimedia-snippets/camera.cpp Camera image whitebalance
-void QCameraPrivate::_q_preparePropertyChange(int changeType)
-{
- if (!control)
- return;
+ For more information on image processing of camera frames, see
+ \l {camera_image_processing}{Camera Image Processing}.
- QCamera::Status status = control->status();
+ See the \l{Camera Overview}{camera overview} for more information.
+*/
- //all the changes are allowed until the camera is starting
- if (control->state() != QCamera::ActiveState)
- return;
+/*!
+ \qmltype Camera
+ \instantiates QCamera
+ \inqmlmodule QtMultimedia
+ \brief An interface for camera settings related to focus and zoom.
+ \ingroup multimedia_qml
+ \ingroup camera_qml
- if (control->canChangeProperty(QCameraControl::PropertyChangeType(changeType), status))
- return;
+ The Camera element can be used within a \l CaptureSession for video recording
+ and image taking.
- restartPending = true;
- control->setState(QCamera::LoadedState);
- QMetaObject::invokeMethod(q_ptr, "_q_restartCamera", Qt::QueuedConnection);
-}
+ You can use \l MediaDevices to list available cameras and choose which one to use.
-void QCameraPrivate::_q_restartCamera()
-{
- if (restartPending) {
- restartPending = false;
- control->setState(QCamera::ActiveState);
+ \qml
+ MediaDevices {
+ id: mediaDevices
}
-}
-
-void QCameraPrivate::init()
-{
- Q_Q(QCamera);
- provider = QMediaServiceProvider::defaultServiceProvider();
- initControls();
- cameraExposure = new QCameraExposure(q);
- cameraFocus = new QCameraFocus(q);
- imageProcessing = new QCameraImageProcessing(q);
-}
-
-void QCameraPrivate::initControls()
-{
- Q_Q(QCamera);
-
- if (service) {
- control = qobject_cast<QCameraControl *>(service->requestControl(QCameraControl_iid));
- locksControl = qobject_cast<QCameraLocksControl *>(service->requestControl(QCameraLocksControl_iid));
- deviceControl = qobject_cast<QVideoDeviceSelectorControl*>(service->requestControl(QVideoDeviceSelectorControl_iid));
- infoControl = qobject_cast<QCameraInfoControl*>(service->requestControl(QCameraInfoControl_iid));
- viewfinderSettingsControl2 = qobject_cast<QCameraViewfinderSettingsControl2*>(service->requestControl(QCameraViewfinderSettingsControl2_iid));
- if (!viewfinderSettingsControl2)
- viewfinderSettingsControl = qobject_cast<QCameraViewfinderSettingsControl*>(service->requestControl(QCameraViewfinderSettingsControl_iid));
-
- if (control) {
- q->connect(control, SIGNAL(stateChanged(QCamera::State)), q, SLOT(_q_updateState(QCamera::State)));
- q->connect(control, SIGNAL(statusChanged(QCamera::Status)), q, SIGNAL(statusChanged(QCamera::Status)));
- q->connect(control, SIGNAL(captureModeChanged(QCamera::CaptureModes)),
- q, SIGNAL(captureModeChanged(QCamera::CaptureModes)));
- q->connect(control, SIGNAL(error(int,QString)), q, SLOT(_q_error(int,QString)));
-
+ CaptureSession {
+ camera: Camera {
+ cameraDevice: mediaDevices.defaultVideoInput
}
-
- if (locksControl) {
- q->connect(locksControl, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus,QCamera::LockChangeReason)),
- q, SLOT(_q_updateLockStatus(QCamera::LockType,QCamera::LockStatus,QCamera::LockChangeReason)));
- }
-
- error = QCamera::NoError;
- } else {
- control = nullptr;
- locksControl = nullptr;
- deviceControl = nullptr;
- infoControl = nullptr;
- viewfinderSettingsControl = nullptr;
- viewfinderSettingsControl2 = nullptr;
-
- error = QCamera::ServiceMissingError;
- errorString = QCamera::tr("The camera service is missing");
}
-}
+ \endqml
-void QCameraPrivate::clear()
-{
- delete cameraExposure;
- delete cameraFocus;
- delete imageProcessing;
-
- if (service) {
- if (control)
- service->releaseControl(control);
- if (locksControl)
- service->releaseControl(locksControl);
- if (deviceControl)
- service->releaseControl(deviceControl);
- if (infoControl)
- service->releaseControl(infoControl);
- if (viewfinderSettingsControl)
- service->releaseControl(viewfinderSettingsControl);
- if (viewfinderSettingsControl2)
- service->releaseControl(viewfinderSettingsControl2);
-
- provider->releaseService(service);
- }
+ On hardware that supports it, QCamera lets you adjust the focus
+ and zoom. This also includes functionality such as a
+ "Macro" mode for close up work (e.g. reading barcodes, or
+ recognizing letters), or "touch to focus" - indicating an
+ interesting area of the image for the hardware to attempt
+ to focus on.
- cameraExposure = nullptr;
- cameraFocus = nullptr;
- imageProcessing = nullptr;
- control = nullptr;
- locksControl = nullptr;
- deviceControl = nullptr;
- infoControl = nullptr;
- viewfinderSettingsControl = nullptr;
- viewfinderSettingsControl2 = nullptr;
- service = nullptr;
-}
+ \qml
-void QCameraPrivate::updateLockStatus()
-{
- Q_Q(QCamera);
+ Item {
+ width: 640
+ height: 360
- QCamera::LockStatus oldStatus = lockStatus;
+ CaptureSession {
+ camera: Camera {
+ id: camera
- QMap<QCamera::LockStatus, int> lockStatusPriority;
- lockStatusPriority.insert(QCamera::Locked, 1);
- lockStatusPriority.insert(QCamera::Unlocked, 2);
- lockStatusPriority.insert(QCamera::Searching, 3);
+ focusMode: Camera.FocusModeAutoNear
+ customFocusPoint: Qt.point(0.2, 0.2) // Focus relative to top-left corner
+ }
+ videoOutput: videoOutput
+ }
- lockStatus = requestedLocks ? QCamera::Locked : QCamera::Unlocked;
- int priority = 0;
+ VideoOutput {
+ id: videoOutput
+ anchors.fill: parent
+ }
+ }
- QList<QCamera::LockStatus> lockStatuses;
+ \endqml
- if (requestedLocks & QCamera::LockFocus)
- lockStatuses << q->lockStatus(QCamera::LockFocus);
+ The \l minimumZoomFactor and \l maximumZoomFactor properties provide the
+ range of supported zoom factors. The \l zoomFactor property allows changing
+ the zoom factor.
- if (requestedLocks & QCamera::LockExposure)
- lockStatuses << q->lockStatus(QCamera::LockExposure);
+ \qml
+ Camera {
+ zoomFactor: maximumZoomFactor // zoom in as much as possible
+ }
+ \endqml
- if (requestedLocks & QCamera::LockWhiteBalance)
- lockStatuses << q->lockStatus(QCamera::LockWhiteBalance);
+ After capturing the raw data for a camera frame, the camera hardware and
+ software performs various image processing tasks to produce the final
+ image. This includes compensating for ambient light color, reducing
+ noise, as well as making some other adjustments to the image.
+ You can control many of these processing steps through the Camera properties.
+ For example, you can set the white balance (or color temperature) used
+ for processing images:
- for (QCamera::LockStatus currentStatus : qAsConst(lockStatuses)) {
- int currentPriority = lockStatusPriority.value(currentStatus, -1);
- if (currentPriority > priority) {
- priority = currentPriority;
- lockStatus = currentStatus;
- }
+ \qml
+ Camera {
+ whiteBalanceMode: Camera.WhiteBalanceManual
+ colorTemperature: 5600
}
+ \endqml
- if (!supressLockChangedSignal && oldStatus != lockStatus) {
- emit q->lockStatusChanged(lockStatus, lockChangeReason);
+ For more information on image processing of camera frames, see
+ \l {camera_image_processing}{Camera Image Processing}.
- if (lockStatus == QCamera::Locked)
- emit q->locked();
- else if (lockStatus == QCamera::Unlocked && lockChangeReason == QCamera::LockFailed)
- emit q->lockFailed();
- }
-/*
- qDebug() << "Requested locks:" << (requestedLocks & QCamera::LockExposure ? 'e' : ' ')
- << (requestedLocks & QCamera::LockFocus ? 'f' : ' ')
- << (requestedLocks & QCamera::LockWhiteBalance ? 'w' : ' ');
- qDebug() << "Lock status: f:" << q->lockStatus(QCamera::LockFocus)
- << " e:" << q->lockStatus(QCamera::LockExposure)
- << " w:" << q->lockStatus(QCamera::LockWhiteBalance)
- << " composite:" << lockStatus;
+ See the \l{Camera Overview}{camera overview} for more information.
*/
-}
-void QCameraPrivate::_q_updateLockStatus(QCamera::LockType type, QCamera::LockStatus status, QCamera::LockChangeReason reason)
+void QCameraPrivate::init(const QCameraDevice &device)
{
Q_Q(QCamera);
- lockChangeReason = reason;
- updateLockStatus();
- emit q->lockStatusChanged(type, status, reason);
-}
-
-
-/*!
- Construct a QCamera with a \a parent.
-*/
-
-QCamera::QCamera(QObject *parent):
- QMediaObject(*new QCameraPrivate,
- parent,
- QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_CAMERA))
-{
- Q_D(QCamera);
- d->init();
- // Select the default camera
- if (d->service != nullptr && d->deviceControl)
- d->deviceControl->setSelectedDevice(d->deviceControl->defaultDevice());
+ auto maybeControl = QPlatformMediaIntegration::instance()->createCamera(q);
+ if (!maybeControl) {
+ qWarning() << "Failed to initialize QCamera" << maybeControl.error();
+ return;
+ }
+ control = maybeControl.value();
+ cameraDevice = !device.isNull() ? device : QMediaDevices::defaultVideoInput();
+ if (cameraDevice.isNull())
+ control->updateError(QCamera::CameraError, QStringLiteral("No camera detected"));
+ control->setCamera(cameraDevice);
+ q->connect(control, &QPlatformVideoSource::activeChanged, q, &QCamera::activeChanged);
+ q->connect(control, &QPlatformCamera::errorChanged, q, &QCamera::errorChanged);
+ q->connect(control, &QPlatformCamera::errorOccurred, q, &QCamera::errorOccurred);
}
/*!
- Construct a QCamera from \a deviceName and \a parent.
+ Construct a QCamera with a \a parent.
- If no camera with that \a deviceName exists, the camera object will
- be invalid.
+ Selects the default camera on the system if more than one camera is available.
*/
-QCamera::QCamera(const QByteArray& deviceName, QObject *parent):
- QMediaObject(*new QCameraPrivate, parent,
- QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_CAMERA,
- QMediaServiceProviderHint(deviceName)))
+QCamera::QCamera(QObject *parent)
+ : QCamera(QMediaDevices::defaultVideoInput(), parent)
{
- Q_D(QCamera);
- d->init();
-
- bool found = false;
- // Pass device name to service.
- if (d->deviceControl) {
- const QString name = QString::fromLatin1(deviceName);
- for (int i = 0; i < d->deviceControl->deviceCount(); i++) {
- if (d->deviceControl->deviceName(i) == name) {
- d->deviceControl->setSelectedDevice(i);
- found = true;
- break;
- }
- }
- }
-
- // The camera should not be used if device with requested name does not exist.
- if (!found) {
- if (d->service) {
- if (d->control)
- d->service->releaseControl(d->control);
- if (d->deviceControl)
- d->service->releaseControl(d->deviceControl);
- if (d->infoControl)
- d->service->releaseControl(d->infoControl);
- }
- d->control = nullptr;
- d->deviceControl = nullptr;
- d->infoControl = nullptr;
- d->error = QCamera::ServiceMissingError;
- d->errorString = QCamera::tr("The camera service is missing");
- }
}
/*!
\since 5.3
- Construct a QCamera from a camera description \a cameraInfo and \a parent.
+ Construct a QCamera from a camera description \a cameraDevice and \a parent.
*/
-QCamera::QCamera(const QCameraInfo &cameraInfo, QObject *parent)
- : QCamera(cameraInfo.deviceName().toLatin1(), parent)
+QCamera::QCamera(const QCameraDevice &cameraDevice, QObject *parent)
+ : QObject(*new QCameraPrivate, parent)
{
+ Q_D(QCamera);
+ d->init(cameraDevice);
}
/*!
@@ -398,33 +204,23 @@ QCamera::QCamera(const QCameraInfo &cameraInfo, QObject *parent)
back-facing cameras.
If no camera is available at the specified \a position or if \a position is
- QCamera::UnspecifiedPosition, the default camera is used.
+ QCameraDevice::UnspecifiedPosition, the default camera is used.
*/
-QCamera::QCamera(QCamera::Position position, QObject *parent)
- : QMediaObject(*new QCameraPrivate,
- parent,
- QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_CAMERA, QMediaServiceProviderHint(position)))
+QCamera::QCamera(QCameraDevice::Position position, QObject *parent)
+ : QObject(*new QCameraPrivate, parent)
{
Q_D(QCamera);
- d->init();
-
- if (d->service != nullptr && d->deviceControl) {
- bool selectDefault = true;
-
- if (d->infoControl && position != UnspecifiedPosition) {
- for (int i = 0; i < d->deviceControl->deviceCount(); i++) {
- if (d->infoControl->cameraPosition(d->deviceControl->deviceName(i)) == position) {
- d->deviceControl->setSelectedDevice(i);
- selectDefault = false;
- break;
- }
- }
- }
- if (selectDefault)
- d->deviceControl->setSelectedDevice(d->deviceControl->defaultDevice());
+ QCameraDevice device;
+ auto cameras = QMediaDevices::videoInputs();
+ for (const auto &c : cameras) {
+ if (c.position() == position) {
+ device = c;
+ break;
+ }
}
+ d->init(device);
}
/*!
@@ -434,873 +230,1128 @@ QCamera::QCamera(QCamera::Position position, QObject *parent)
QCamera::~QCamera()
{
Q_D(QCamera);
- d->clear();
+ if (d->captureSession)
+ d->captureSession->setCamera(nullptr);
}
/*!
- Returns the availability state of the camera service.
+ Returns true if the camera can be used.
*/
-QMultimedia::AvailabilityStatus QCamera::availability() const
+bool QCamera::isAvailable() const
{
Q_D(const QCamera);
- if (d->control == nullptr)
- return QMultimedia::ServiceMissing;
+ return d->control && !d->cameraDevice.isNull();
+}
- if (d->deviceControl && d->deviceControl->deviceCount() == 0)
- return QMultimedia::ResourceError;
+/*! \qmlproperty bool QtMultimedia::Camera::active
- if (d->error != QCamera::NoError)
- return QMultimedia::ResourceError;
+ Describes whether the camera is currently active.
+*/
- return QMediaObject::availability();
-}
+/*! \property QCamera::active
+ Describes whether the camera is currently active.
+*/
/*!
- Returns the camera exposure control object.
+ Returns true if the camera is currently active.
*/
-QCameraExposure *QCamera::exposure() const
+bool QCamera::isActive() const
{
- return d_func()->cameraExposure;
+ Q_D(const QCamera);
+ return d->control && d->control->isActive();
}
/*!
- Returns the camera focus control object.
+ Turns the camera on if \a active is \c{true}, or off if it's \c{false}.
*/
-QCameraFocus *QCamera::focus() const
+void QCamera::setActive(bool active)
{
- return d_func()->cameraFocus;
+ Q_D(const QCamera);
+ if (d->control)
+ d->control->setActive(active);
}
/*!
- Returns the camera image processing control object.
+ \qmlproperty enumeration QtMultimedia::Camera::error
+
+ Returns the error state of the camera.
+
+ \sa QCamera::Error
*/
-QCameraImageProcessing *QCamera::imageProcessing() const
+
+/*!
+ \property QCamera::error
+
+ Returns the error state of the camera.
+*/
+
+QCamera::Error QCamera::error() const
{
- return d_func()->imageProcessing;
+ Q_D(const QCamera);
+
+ return d->control ? d->control->error() : QCamera::CameraError;
}
/*!
- Sets the QVideoWidget based camera \a viewfinder.
- The previously set viewfinder is detached.
+ \qmlproperty string QtMultimedia::Camera::errorString
- //! QVideoWidget is forward declared.
+ Returns a human readable string describing a camera's error state.
*/
-void QCamera::setViewfinder(QVideoWidget *viewfinder)
-{
- Q_D(QCamera);
- d->_q_preparePropertyChange(QCameraControl::Viewfinder);
- if (d->viewfinder)
- unbind(d->viewfinder);
+/*!
+ \property QCamera::errorString
- // We don't know (in this library) that QVideoWidget inherits QObject
- QObject *viewFinderObject = reinterpret_cast<QObject*>(viewfinder);
+ Returns a human readable string describing a camera's error state.
+*/
+QString QCamera::errorString() const
+{
+ Q_D(const QCamera);
- d->viewfinder = viewFinderObject && bind(viewFinderObject) ? viewFinderObject : nullptr;
+ return d->control ? d->control->errorString()
+ : QStringLiteral("Camera is not supported on the platform");
}
+/*! \enum QCamera::Feature
+
+ Describes a set of features supported by the camera. The returned value can be a
+ combination of:
+
+ \value ColorTemperature
+ The Camera supports setting a custom \l{colorTemperature}.
+ \value ExposureCompensation
+ The Camera supports setting a custom \l{exposureCompensation}.
+ \value IsoSensitivity
+ The Camera supports setting a custom \l{isoSensitivity}.
+ \value ManualExposureTime
+ The Camera supports setting a \l{QCamera::manualExposureTime}{manual exposure Time}.
+ \value CustomFocusPoint
+ The Camera supports setting a \l{QCamera::customFocusPoint}{custom focus point}.
+ \value FocusDistance
+ The Camera supports setting the \l{focusDistance} property.
+*/
+
/*!
- Sets the QGraphicsVideoItem based camera \a viewfinder.
- The previously set viewfinder is detached.
+ \qmlproperty Features QtMultimedia::Camera::supportedFeatures
+ Returns the features supported by this camera.
- //! QGraphicsVideoItem is forward declared.
+ \sa QCamera::Feature
*/
-void QCamera::setViewfinder(QGraphicsVideoItem *viewfinder)
-{
- Q_D(QCamera);
- d->_q_preparePropertyChange(QCameraControl::Viewfinder);
- if (d->viewfinder)
- unbind(d->viewfinder);
+/*!
+ \property QCamera::supportedFeatures
- // We don't know (in this library) that QGraphicsVideoItem (multiply) inherits QObject
- // but QObject inheritance depends on QObject coming first, so try this out.
- QObject *viewFinderObject = reinterpret_cast<QObject*>(viewfinder);
+ Returns the features supported by this camera.
- d->viewfinder = viewFinderObject && bind(viewFinderObject) ? viewFinderObject : nullptr;
+ \sa QCamera::Feature
+*/
+QCamera::Features QCamera::supportedFeatures() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->supportedFeatures() : QCamera::Features{};
}
-/*!
- Sets a video \a surface as the viewfinder of a camera.
+/*! \qmlmethod void Camera::start()
+
+ Starts the camera.
- If a viewfinder has already been set on the camera the new surface
- will replace it.
+ Same as setting the active property to true.
+
+ If the camera can't be started for some reason, the errorOccurred() signal is emitted.
*/
-void QCamera::setViewfinder(QAbstractVideoSurface *surface)
-{
- Q_D(QCamera);
+/*! \fn void QCamera::start()
- d->surfaceViewfinder.setVideoSurface(surface);
+ Starts the camera.
- if (d->viewfinder != &d->surfaceViewfinder) {
- if (d->viewfinder)
- unbind(d->viewfinder);
+ Same as setActive(true).
- d->viewfinder = nullptr;
+ If the camera can't be started for some reason, the errorOccurred() signal is emitted.
+*/
- if (surface && bind(&d->surfaceViewfinder))
- d->viewfinder = &d->surfaceViewfinder;
- } else if (!surface) {
- //unbind the surfaceViewfinder if null surface is set
- unbind(&d->surfaceViewfinder);
- d->viewfinder = nullptr;
- }
-}
+/*! \qmlmethod void Camera::stop()
-/*!
- Returns the viewfinder settings being used by the camera.
+ Stops the camera.
+ Same as setting the active property to false.
+*/
- Settings may change when the camera is started, for example if the viewfinder settings
- are undefined or if unsupported values are set.
+/*! \fn void QCamera::stop()
- If viewfinder settings are not supported by the camera, it always returns a null
- QCameraViewfinderSettings object.
+ Stops the camera.
+ Same as setActive(false).
+*/
- \sa setViewfinderSettings()
+/*!
+ Returns the capture session this camera is connected to, or
+ a nullptr if the camera is not connected to a capture session.
- \since 5.5
+ use QMediaCaptureSession::setCamera() to connect the camera to
+ a session.
*/
-QCameraViewfinderSettings QCamera::viewfinderSettings() const
+QMediaCaptureSession *QCamera::captureSession() const
{
Q_D(const QCamera);
+ return d->captureSession;
+}
- if (d->viewfinderSettingsControl2)
- return d->viewfinderSettingsControl2->viewfinderSettings();
+/*!
+ \internal
+*/
+void QCamera::setCaptureSession(QMediaCaptureSession *session)
+{
+ Q_D(QCamera);
+ d->captureSession = session;
+}
- QCameraViewfinderSettings settings;
- if (d->viewfinderSettingsControl) {
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::Resolution))
- settings.setResolution(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::Resolution).toSize());
+/*!
+ \internal
+*/
+QPlatformCamera *QCamera::platformCamera()
+{
+ Q_D(const QCamera);
+ return d->control;
+}
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::MinimumFrameRate))
- settings.setMinimumFrameRate(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::MinimumFrameRate).toReal());
+/*! \qmlproperty cameraDevice QtMultimedia::Camera::cameraDevice
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::MaximumFrameRate))
- settings.setMaximumFrameRate(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::MaximumFrameRate).toReal());
+ Gets or sets the currently active camera device.
+*/
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::PixelAspectRatio))
- settings.setPixelAspectRatio(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::PixelAspectRatio).toSize());
+/*!
+ \property QCamera::cameraDevice
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::PixelFormat))
- settings.setPixelFormat(qvariant_cast<QVideoFrame::PixelFormat>(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::PixelFormat)));
- }
- return settings;
+ Returns the QCameraDevice object associated with this camera.
+ */
+QCameraDevice QCamera::cameraDevice() const
+{
+ Q_D(const QCamera);
+ return d->cameraDevice;
}
/*!
- Sets the viewfinder \a settings.
+ Connects the camera object to the physical camera device described by
+ \a cameraDevice. Using a default constructed QCameraDevice object as
+ \a cameraDevice will connect the camera to the system default camera device.
+*/
+void QCamera::setCameraDevice(const QCameraDevice &cameraDevice)
+{
+ Q_D(QCamera);
+ auto dev = cameraDevice;
+ if (dev.isNull())
+ dev = QMediaDevices::defaultVideoInput();
+ if (d->cameraDevice == dev)
+ return;
+ d->cameraDevice = dev;
+ if (d->control)
+ d->control->setCamera(d->cameraDevice);
+ emit cameraDeviceChanged();
+ setCameraFormat({});
+}
+
+/*! \qmlproperty cameraFormat QtMultimedia::Camera::cameraFormat
+
+ Gets or sets the currently active camera format.
+
+ \note When using the FFMPEG backend on an Android target device if you request
+ \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
+ semi-planar NV12/NV21. This depends on the codec implemented by the device
+ OEM.
- If some parameters are not specified, or null settings are passed, the camera will choose
- default values.
+ \sa cameraDevice::videoFormats
+*/
- If the camera is used to capture videos or images, the viewfinder settings might be
- ignored if they conflict with the capture settings. You can check the actual viewfinder settings
- once the camera is in the \c QCamera::ActiveStatus status.
+/*!
+ \property QCamera::cameraFormat
- Changing the viewfinder settings while the camera is in the QCamera::ActiveState state may
- cause the camera to be restarted.
+ Returns the camera format currently used by the camera.
- \sa viewfinderSettings(), supportedViewfinderResolutions(), supportedViewfinderFrameRateRanges(),
- supportedViewfinderPixelFormats()
+ \note When using the FFMPEG backend on an Android target device if you request
+ \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
+ semi-planar NV12/NV21. This depends on the codec implemented by the device
+ OEM.
- \since 5.5
+ \sa QCameraDevice::videoFormats
*/
-void QCamera::setViewfinderSettings(const QCameraViewfinderSettings &settings)
+QCameraFormat QCamera::cameraFormat() const
+{
+ Q_D(const QCamera);
+ return d->cameraFormat;
+}
+
+/*!
+ Tells the camera to use the format described by \a format. This can be used to define
+ a specific resolution and frame rate to be used for recording and image capture.
+
+ \note When using the FFMPEG backend on an Android target device if you request
+ \b YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a
+ semi-planar NV12/NV21. This depends on the codec implemented by the device
+ OEM.
+*/
+void QCamera::setCameraFormat(const QCameraFormat &format)
{
Q_D(QCamera);
+ if (!d->control || !d->control->setCameraFormat(format))
+ return;
- if (d->viewfinderSettingsControl || d->viewfinderSettingsControl2)
- d->_q_preparePropertyChange(QCameraControl::ViewfinderSettings);
+ d->cameraFormat = format;
+ emit cameraFormatChanged();
+}
- if (d->viewfinderSettingsControl2) {
- d->viewfinderSettingsControl2->setViewfinderSettings(settings);
+/*!
+ \enum QCamera::Error
- } else if (d->viewfinderSettingsControl) {
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::Resolution))
- d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::Resolution, settings.resolution());
+ This enum holds the last error code.
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::MinimumFrameRate))
- d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::MinimumFrameRate, settings.minimumFrameRate());
+ \value NoError No errors have occurred.
+ \value CameraError An error has occurred.
+*/
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::MaximumFrameRate))
- d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::MaximumFrameRate, settings.maximumFrameRate());
+/*!
+ \qmlsignal void Camera::errorOccurred(Camera::Error error, string errorString)
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::PixelAspectRatio))
- d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::PixelAspectRatio, settings.pixelAspectRatio());
+ This signal is emitted when error state changes to \a error. A description
+ of the error is provided as \a errorString.
+*/
- if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::PixelFormat))
- d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::PixelFormat, settings.pixelFormat());
- }
-}
+/*!
+ \fn void QCamera::errorOccurred(QCamera::Error error, const QString &errorString)
+
+ This signal is emitted when error state changes to \a error. A description
+ of the error is provided as \a errorString.
+*/
/*!
- Returns a list of supported viewfinder settings.
+ \qmlproperty enumeration Camera::focusMode
+
+ This property holds the current camera focus mode.
- The list is ordered by preference; preferred settings come first.
+ \note In automatic focusing modes and where supported, the \l focusPoint property provides
+ information and control over the area of the image that is being focused.
- The optional \a settings argument can be used to conveniently filter the results.
- If \a settings is non null, the returned list is reduced to settings matching the given partial
- \a settings.
+ \value Camera.FocusModeAuto Continuous auto focus mode.
+ \value Camera.FocusModeAutoNear Continuous auto focus, preferring objects near to
+ the camera.
+ \value Camera.FocusModeAutoFar Continuous auto focus, preferring objects far away
+ from the camera.
+ \value Camera.FocusModeHyperfocal Focus to hyperfocal distance, with the maximum
+ depth of field achieved. All objects at distances from half of this
+ distance out to infinity will be acceptably sharp.
+ \value Camera.FocusModeInfinity Focus strictly to infinity.
+ \value Camera.FocusModeManual Manual or fixed focus mode.
+
+ If a certain focus mode is not supported, setting it will have no effect.
+
+ \sa isFocusModeSupported
+*/
- The status of the camera must be LoadedStatus before calling this function, otherwise the returned list
- is empty.
+/*!
+ \property QCamera::focusMode
+ \brief the current camera focus mode.
- \sa setViewfinderSettings(), supportedViewfinderResolutions(), supportedViewfinderFrameRateRanges(),
- supportedViewfinderPixelFormats()
+ Sets up different focus modes for the camera. All auto focus modes will focus continuously.
+ Locking the focus is possible by setting the focus mode to \l FocusModeManual. This will keep
+ the current focus and stop any automatic focusing.
- \since 5.5
+ \sa isFocusModeSupported
*/
-QList<QCameraViewfinderSettings> QCamera::supportedViewfinderSettings(const QCameraViewfinderSettings &settings) const
+QCamera::FocusMode QCamera::focusMode() const
{
Q_D(const QCamera);
+ return d->control ? d->control->focusMode() : QCamera::FocusModeAuto;
+}
- if (!d->viewfinderSettingsControl2)
- return QList<QCameraViewfinderSettings>();
-
- if (settings.isNull())
- return d->viewfinderSettingsControl2->supportedViewfinderSettings();
-
- QList<QCameraViewfinderSettings> results;
- const QList<QCameraViewfinderSettings> supported = d->viewfinderSettingsControl2->supportedViewfinderSettings();
- for (const QCameraViewfinderSettings &s : supported) {
- if ((settings.resolution().isEmpty() || settings.resolution() == s.resolution())
- && (qFuzzyIsNull(settings.minimumFrameRate()) || qFuzzyCompare((float)settings.minimumFrameRate(), (float)s.minimumFrameRate()))
- && (qFuzzyIsNull(settings.maximumFrameRate()) || qFuzzyCompare((float)settings.maximumFrameRate(), (float)s.maximumFrameRate()))
- && (settings.pixelFormat() == QVideoFrame::Format_Invalid || settings.pixelFormat() == s.pixelFormat())
- && (settings.pixelAspectRatio().isEmpty() || settings.pixelAspectRatio() == s.pixelAspectRatio())) {
- results.append(s);
- }
- }
+/*!
+ \fn void QCamera::focusModeChanged()
- return results;
+ Signals when the focusMode changes.
+*/
+void QCamera::setFocusMode(QCamera::FocusMode mode)
+{
+ Q_D(QCamera);
+ if (!d->control || d->control->focusMode() == mode)
+ return;
+ d->control->setFocusMode(mode);
+ emit focusModeChanged();
}
/*!
- Returns a list of supported viewfinder resolutions.
+ \qmlmethod bool Camera::isFocusModeSupported(FocusMode mode)
- This is a convenience function which retrieves unique resolutions from the supported settings.
+ Returns true if the focus \a mode is supported by the camera.
+*/
- If non null viewfinder \a settings are passed, the returned list is reduced to resolutions
- supported with partial \a settings applied.
+/*!
+ Returns true if the focus \a mode is supported by the camera.
+*/
+bool QCamera::isFocusModeSupported(FocusMode mode) const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->isFocusModeSupported(mode) : false;
+}
- The camera must be loaded before calling this function, otherwise the returned list
- is empty.
+/*!
+ \qmlproperty point QtMultimedia::Camera::focusPoint
+ Returns the point currently used by the auto focus system to focus onto.
+*/
- \sa QCameraViewfinderSettings::resolution(), setViewfinderSettings()
+/*!
+ \property QCamera::focusPoint
- \since 5.5
-*/
-QList<QSize> QCamera::supportedViewfinderResolutions(const QCameraViewfinderSettings &settings) const
+ Returns the point currently used by the auto focus system to focus onto.
+ */
+QPointF QCamera::focusPoint() const
{
- QList<QSize> resolutions;
- const QList<QCameraViewfinderSettings> capabilities = supportedViewfinderSettings(settings);
- for (const QCameraViewfinderSettings &s : capabilities) {
- if (!resolutions.contains(s.resolution()))
- resolutions.append(s.resolution());
- }
- std::sort(resolutions.begin(), resolutions.end(), qt_sizeLessThan);
+ Q_D(const QCamera);
+ return d->control ? d->control->focusPoint() : QPointF(-1., -1.);
- return resolutions;
}
/*!
- Returns a list of supported viewfinder frame rate ranges.
+ \qmlproperty point QtMultimedia::Camera::customFocusPoint
+
+ This property holds the position of custom focus point, in relative frame
+ coordinates. This means that QPointF(0,0) points to the top-left corner
+ of the frame, and QPointF(0.5,0.5) points to the center of the frame.
- This is a convenience function which retrieves unique frame rate ranges from the supported settings.
+ Custom focus point is used only in \c FocusPointCustom focus mode.
- If non null viewfinder \a settings are passed, the returned list is reduced to frame rate ranges
- supported with partial \a settings applied.
+ You can check whether custom focus points are supported by querying
+ supportedFeatures() with the Feature.CustomFocusPoint flag.
+*/
- The camera must be loaded before calling this function, otherwise the returned list
- is empty.
+/*!
+ \property QCamera::customFocusPoint
- \sa QCameraViewfinderSettings::minimumFrameRate(), QCameraViewfinderSettings::maximumFrameRate(),
- setViewfinderSettings()
+ This property represents the position of the custom focus point, in relative frame coordinates:
+ QPointF(0,0) points to the left top frame point, QPointF(0.5,0.5) points to the frame center.
- \since 5.5
+ The custom focus point property is used only in \c FocusPointCustom focus mode.
+
+ You can check whether custom focus points are supported by querying
+ supportedFeatures() with the Feature.CustomFocusPoint flag.
*/
-QList<QCamera::FrameRateRange> QCamera::supportedViewfinderFrameRateRanges(const QCameraViewfinderSettings &settings) const
+QPointF QCamera::customFocusPoint() const
{
- QList<QCamera::FrameRateRange> frameRateRanges;
- const QList<QCameraViewfinderSettings> capabilities = supportedViewfinderSettings(settings);
- for (const QCameraViewfinderSettings &s : capabilities) {
- QCamera::FrameRateRange range(s.minimumFrameRate(), s.maximumFrameRate());
- if (!frameRateRanges.contains(range))
- frameRateRanges.append(range);
- }
- std::sort(frameRateRanges.begin(), frameRateRanges.end(), qt_frameRateRangeLessThan);
+ Q_D(const QCamera);
+ return d->control ? d->control->customFocusPoint() : QPointF{-1., -1.};
+}
- return frameRateRanges;
+void QCamera::setCustomFocusPoint(const QPointF &point)
+{
+ Q_D(QCamera);
+ if (d->control)
+ d->control->setCustomFocusPoint(point);
}
/*!
- Returns a list of supported viewfinder pixel formats.
+ \qmlproperty float QtMultimedia::Camera::focusDistance
- This is a convenience function which retrieves unique pixel formats from the supported settings.
+ This property return an approximate focus distance of the camera. The value reported
+ is between 0 and 1, 0 being the closest possible focus distance, 1 being as far away
+ as possible. Note that 1 is often, but not always infinity.
- If non null viewfinder \a settings are passed, the returned list is reduced to pixel formats
- supported with partial \a settings applied.
+ Setting the focus distance will be ignored unless the focus mode is set to
+ \l {focusMode}{FocusModeManual}.
+*/
- The camera must be loaded before calling this function, otherwise the returned list
- is empty.
+/*!
+ \property QCamera::focusDistance
- \sa QCameraViewfinderSettings::pixelFormat(), setViewfinderSettings()
+ This property return an approximate focus distance of the camera. The value reported
+ is between 0 and 1, 0 being the closest possible focus distance, 1 being as far away
+ as possible. Note that 1 is often, but not always infinity.
- \since 5.5
+ Setting the focus distance will be ignored unless the focus mode is set to
+ \l FocusModeManual.
*/
-QList<QVideoFrame::PixelFormat> QCamera::supportedViewfinderPixelFormats(const QCameraViewfinderSettings &settings) const
+void QCamera::setFocusDistance(float d)
{
- QList<QVideoFrame::PixelFormat> pixelFormats;
- const QList<QCameraViewfinderSettings> capabilities = supportedViewfinderSettings(settings);
- for (const QCameraViewfinderSettings &s : capabilities) {
- if (!pixelFormats.contains(s.pixelFormat()))
- pixelFormats.append(s.pixelFormat());
- }
+ if (!d_func()->control || focusMode() != FocusModeManual)
+ return;
+ d_func()->control->setFocusDistance(d);
+}
- return pixelFormats;
+float QCamera::focusDistance() const
+{
+ if (d_func()->control && focusMode() == FocusModeManual)
+ return d_func()->control->focusDistance();
+ return 0.;
}
/*!
- Returns the error state of the object.
+ \qmlproperty real QtMultimedia::Camera::maximumZoomFactor
+
+ This property holds the maximum zoom factor supported.
+
+ This will be \c 1.0 on cameras that do not support zooming.
*/
-QCamera::Error QCamera::error() const
-{
- return d_func()->error;
-}
/*!
- Returns a string describing a camera's error state.
+ \property QCamera::maximumZoomFactor
+
+ Returns the maximum zoom factor.
+
+ This will be \c 1.0 on cameras that do not support zooming.
*/
-QString QCamera::errorString() const
+
+float QCamera::maximumZoomFactor() const
{
- return d_func()->errorString;
+ Q_D(const QCamera);
+ return d->control ? d->control->maxZoomFactor() : 1.f;
}
+/*!
+ \qmlproperty real QtMultimedia::Camera::minimumZoomFactor
+
+ This property holds the minimum zoom factor supported.
+
+ This will be \c 1.0 on cameras that do not support zooming.
+*/
/*!
- Returns true if the capture \a mode is suported.
+ \property QCamera::minimumZoomFactor
+
+ Returns the minimum zoom factor.
+
+ This will be \c 1.0 on cameras that do not support zooming.
*/
-bool QCamera::isCaptureModeSupported(QCamera::CaptureModes mode) const
+
+float QCamera::minimumZoomFactor() const
{
- return d_func()->control ? d_func()->control->isCaptureModeSupported(mode) : false;
+ Q_D(const QCamera);
+ return d->control ? d->control->minZoomFactor() : 1.f;
}
/*!
- \property QCamera::captureMode
+ \qmlproperty real QtMultimedia::Camera::zoomFactor
- The type of media (video or still images),
- the camera is configured to capture.
-
- It's allowed to change capture mode in any camera state,
- but if the camera is currently active,
- chaging capture mode is likely to lead to camera status
- chaged to QCamera::LoadedStatus, QCamera::LoadingStatus,
- and when the camera is ready to QCamera::ActiveStatus.
+ Gets or sets the current zoom factor. Values will be clamped between
+ \l minimumZoomFactor and \l maximumZoomFactor.
*/
-QCamera::CaptureModes QCamera::captureMode() const
+/*!
+ \property QCamera::zoomFactor
+ \brief The current zoom factor.
+
+ Gets or sets the current zoom factor. Values will be clamped between
+ \l minimumZoomFactor and \l maximumZoomFactor.
+*/
+float QCamera::zoomFactor() const
{
- return d_func()->control ? d_func()->control->captureMode() : QCamera::CaptureStillImage;
+ Q_D(const QCamera);
+ return d->control ? d->control->zoomFactor() : 1.f;
}
-
-void QCamera::setCaptureMode(QCamera::CaptureModes mode)
+/*!
+ Zooms to a zoom factor \a factor at a rate of 1 factor per second.
+ */
+void QCamera::setZoomFactor(float factor)
{
- Q_D(QCamera);
-
- if (mode != captureMode()) {
- if (d->control) {
- d->_q_preparePropertyChange(QCameraControl::CaptureMode);
- d->control->setCaptureMode(mode);
- }
- }
+ zoomTo(factor, 0.f);
}
-
/*!
- Starts the camera.
+ \qmlmethod void QtMultimedia::Camera::zoomTo(factor, rate)
- State is changed to QCamera::ActiveState if camera is started
- successfully, otherwise errorOccurred() signal is emitted.
+ Zooms to a zoom factor \a factor using \a rate.
- While the camera state is changed to QCamera::ActiveState,
- starting the camera service can be asynchronous with the actual
- status reported with QCamera::status property.
+ The \a rate is specified in powers of two per second. At a rate of 1
+ it would take 2 seconds to go from a zoom factor of 1 to 4.
+
+ \note Using a specific rate is not supported on all cameras. If not supported,
+ zooming will happen as fast as possible.
*/
-void QCamera::start()
-{
- Q_D(QCamera);
- d->setState(QCamera::ActiveState);
-}
/*!
- Stops the camera.
- The camera state is changed from QCamera::ActiveState to QCamera::LoadedState.
+ Zooms to a zoom factor \a factor using \a rate.
- In this state, the camera still consumes power.
+ The \a rate is specified in powers of two per second. At a rate of 1
+ it would take 2 seconds to go from a zoom factor of 1 to 4.
- \sa unload(), QCamera::UnloadedState
+ \note Using a specific rate is not supported on all cameras. If not supported,
+ zooming will happen as fast as possible.
*/
-void QCamera::stop()
+void QCamera::zoomTo(float factor, float rate)
{
+ Q_ASSERT(rate >= 0.f);
+ if (rate < 0.f)
+ rate = 0.f;
+
Q_D(QCamera);
- d->setState(QCamera::LoadedState);
+ if (!d->control)
+ return;
+ factor = qBound(d->control->minZoomFactor(), factor, d->control->maxZoomFactor());
+ d->control->zoomTo(factor, rate);
}
/*!
- Opens the camera device.
- The camera state is changed to QCamera::LoadedState.
+ \enum QCamera::FocusMode
+
+ \value FocusModeAuto Continuous auto focus mode.
+ \value FocusModeAutoNear Continuous auto focus mode on near objects.
+ \value FocusModeAutoFar Continuous auto focus mode on objects far away.
+ \value FocusModeHyperfocal Focus to hyperfocal distance, with the maximum depth of field achieved.
+ All objects at distances from half of this
+ distance out to infinity will be acceptably sharp.
+ \value FocusModeInfinity Focus strictly to infinity.
+ \value FocusModeManual Manual or fixed focus mode.
+*/
+
+/*!
+ \qmlproperty enumeration QtMultimedia::Camera::flashMode
- It's not necessary to explicitly load the camera, unless the application
- needs to read the supported camera settings and change the default values
- according to the camera capabilities.
+ Gets or sets a certain flash mode if the camera has a flash.
- In all the other cases, it's possible to start the camera directly
- from the unloaded state.
+ \value Camera.FlashOff Flash is Off.
+ \value Camera.FlashOn Flash is On.
+ \value Camera.FlashAuto Automatic flash.
- /sa QCamera::UnloadedState
+ \sa isFlashModeSupported, isFlashReady
*/
-void QCamera::load()
-{
- Q_D(QCamera);
- d->setState(QCamera::LoadedState);
-}
/*!
- Closes the camera device and deallocates the related resources.
- The camera state is changed to QCamera::UnloadedState.
+ \property QCamera::flashMode
+ \brief The flash mode being used.
+
+ Enables a certain flash mode if the camera has a flash.
+
+ \sa QCamera::FlashMode, QCamera::isFlashModeSupported, QCamera::isFlashReady
*/
-void QCamera::unload()
+QCamera::FlashMode QCamera::flashMode() const
{
- Q_D(QCamera);
- d->setState(QCamera::UnloadedState);
+ Q_D(const QCamera);
+ return d->control ? d->control->flashMode() : QCamera::FlashOff;
}
-QCamera::State QCamera::state() const
+void QCamera::setFlashMode(QCamera::FlashMode mode)
{
- return d_func()->state;
+ Q_D(QCamera);
+ if (d->control)
+ d->control->setFlashMode(mode);
}
-QCamera::Status QCamera::status() const
-{
- if(d_func()->control)
- return (QCamera::Status)d_func()->control->status();
-
- return QCamera::UnavailableStatus;
-}
+/*!
+ \qmlmethod bool QtMultimedia::Camera::isFlashModeSupported(FlashMode mode)
+ Returns true if the flash \a mode is supported.
+*/
/*!
- Returns the lock types that the camera supports.
+ Returns true if the flash \a mode is supported.
*/
-QCamera::LockTypes QCamera::supportedLocks() const
+bool QCamera::isFlashModeSupported(QCamera::FlashMode mode) const
{
Q_D(const QCamera);
-
- return d->locksControl
- ? d->locksControl->supportedLocks()
- : QCamera::LockTypes();
+ return d->control ? d->control->isFlashModeSupported(mode) : (mode == FlashOff);
}
/*!
- Returns the requested lock types.
+ \qmlmethod bool QtMultimedia::Camera::isFlashReady()
+
+ Returns true if flash is charged.
*/
-QCamera::LockTypes QCamera::requestedLocks() const
-{
- return d_func()->requestedLocks;
-}
/*!
- Returns the status of requested camera settings locks.
+ Returns true if flash is charged.
*/
-QCamera::LockStatus QCamera::lockStatus() const
+bool QCamera::isFlashReady() const
{
- return d_func()->lockStatus;
+ Q_D(const QCamera);
+ return d->control ? d->control->isFlashReady() : false;
}
/*!
- Returns the lock status for a given \a lockType.
+ \qmlproperty Camera::TorchMode Camera::torchMode
+
+ Gets or sets the torch mode being used.
+
+ A torch is a continuous source of light. It can be used during video recording in
+ low light conditions. Enabling torch mode will usually override any currently set
+ flash mode.
+
+ \sa QCamera::TorchMode, Camera::isTorchModeSupported(), Camera::flashMode
*/
-QCamera::LockStatus QCamera::lockStatus(QCamera::LockType lockType) const
-{
- const QCameraPrivate *d = d_func();
- if (!(lockType & d->requestedLocks))
- return QCamera::Unlocked;
+/*!
+ \property QCamera::torchMode
+ \brief The torch mode being used.
+
+ A torch is a continuous source of light. It can be used during video recording in
+ low light conditions. Enabling torch mode will usually override any currently set
+ flash mode.
- if (d->locksControl)
- return d->locksControl->lockStatus(lockType);
+ \sa QCamera::TorchMode, QCamera::isTorchModeSupported, QCamera::flashMode
+*/
+QCamera::TorchMode QCamera::torchMode() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->torchMode() : TorchOff;
+}
- return QCamera::Locked;
+void QCamera::setTorchMode(QCamera::TorchMode mode)
+{
+ Q_D(QCamera);
+ if (d->control)
+ d->control->setTorchMode(mode);
}
/*!
- \fn void QCamera::searchAndLock(QCamera::LockTypes locks)
+ \qmlmethod bool QtMultimedia::Camera::isTorchModeSupported(TorchMode mode)
- Locks the camera settings with the requested \a locks, including focusing in the single autofocus mode,
- exposure and white balance if the exposure and white balance modes are not manual.
+ Returns true if the torch \a mode is supported.
+*/
- The camera settings are usually locked before taking one or multiple still images,
- in responce to the shutter button being half pressed.
+/*!
+ Returns true if the torch \a mode is supported.
+*/
+bool QCamera::isTorchModeSupported(QCamera::TorchMode mode) const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->isTorchModeSupported(mode) : (mode == TorchOff);
+}
- The QCamera::locked() signal is emitted when camera settings are successfully locked,
- otherwise QCamera::lockFailed() is emitted.
+/*!
+ \qmlproperty ExposureMode QtMultimedia::Camera::exposureMode
+ \brief The exposure mode being used.
- QCamera also emits lockStatusChanged(QCamera::LockType, QCamera::LockStatus)
- on individual lock status changes and lockStatusChanged(QCamera::LockStatus) signal on composite status changes.
+ \sa QCamera::ExposureMode, Camera::isExposureModeSupported()
+*/
- Locking serves two roles: it initializes calculation of automatic parameter
- (focusing, calculating the correct exposure and white balance) and allows
- to keep some or all of those parameters during number of shots.
+/*!
+ \property QCamera::exposureMode
+ \brief The exposure mode being used.
- If the camera doesn't support keeping one of parameters between shots, the related
- lock state changes to QCamera::Unlocked.
+ \sa QCamera::isExposureModeSupported
+*/
+QCamera::ExposureMode QCamera::exposureMode() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->exposureMode() : QCamera::ExposureAuto;
+}
- It's also acceptable to relock already locked settings,
- depending on the lock parameter this initiates new focusing, exposure or white balance calculation.
- */
-void QCamera::searchAndLock(QCamera::LockTypes locks)
+void QCamera::setExposureMode(QCamera::ExposureMode mode)
{
Q_D(QCamera);
+ if (d->control)
+ d->control->setExposureMode(mode);
+}
- QCamera::LockStatus oldStatus = d->lockStatus;
- d->supressLockChangedSignal = true;
-
- if (d->locksControl) {
- locks &= d->locksControl->supportedLocks();
- d->requestedLocks |= locks;
- d->locksControl->searchAndLock(locks);
- }
+/*!
+ \qmlmethod bool QtMultimedia::Camera::isExposureModeSupported(ExposureMode mode)
- d->supressLockChangedSignal = false;
+ Returns true if the exposure \a mode is supported.
+*/
- d->lockStatus = oldStatus;
- d->updateLockStatus();
+/*!
+ Returns true if the exposure \a mode is supported.
+*/
+bool QCamera::isExposureModeSupported(QCamera::ExposureMode mode) const
+{
+ Q_D(const QCamera);
+ return d->control && d->control->isExposureModeSupported(mode);
}
/*!
- Lock all the supported camera settings.
- */
-void QCamera::searchAndLock()
+ \qmlproperty real QtMultimedia::Camera::exposureCompensation
+
+ Gets or sets the exposure compensation in EV units.
+
+ Exposure compensation property allows to adjust the automatically calculated
+ exposure.
+*/
+
+/*!
+ \property QCamera::exposureCompensation
+ \brief Exposure compensation in EV units.
+
+ Exposure compensation property allows to adjust the automatically calculated
+ exposure.
+*/
+float QCamera::exposureCompensation() const
{
- searchAndLock(LockExposure | LockWhiteBalance | LockFocus);
+ Q_D(const QCamera);
+ return d->control ? d->control->exposureCompensation() : 0.f;
}
-/*!
- Unlocks the camera settings specified with \a locks or cancel the current locking if one is active.
- */
-void QCamera::unlock(QCamera::LockTypes locks)
+void QCamera::setExposureCompensation(float ev)
{
Q_D(QCamera);
+ if (d->control)
+ d->control->setExposureCompensation(ev);
+}
- QCamera::LockStatus oldStatus = d->lockStatus;
- d->supressLockChangedSignal = true;
+/*!
+ \qmlproperty int QtMultimedia::Camera::isoSensitivity
- d->requestedLocks &= ~locks;
+ Describes the ISO sensitivity currently used by the camera.
- if (d->locksControl) {
- locks &= d->locksControl->supportedLocks();
- d->locksControl->unlock(locks);
- }
+*/
- d->supressLockChangedSignal = false;
+/*!
+ \property QCamera::isoSensitivity
+ \brief The sensor ISO sensitivity.
- d->lockStatus = oldStatus;
- d->updateLockStatus();
-}
+ Describes the ISO sensitivity currently used by the camera.
-/*!
- Unlock all the requested camera locks.
- */
-void QCamera::unlock()
+ \sa setAutoIsoSensitivity(), setManualIsoSensitivity()
+*/
+int QCamera::isoSensitivity() const
{
- unlock(d_func()->requestedLocks);
+ Q_D(const QCamera);
+ return d->control ? d->control->isoSensitivity() : -1;
}
-
/*!
- \class QCamera::FrameRateRange
- \inmodule QtMultimedia
- \ingroup multimedia
- \ingroup multimedia_camera
- \since 5.5
-
- \brief A FrameRateRange represents a range of frame rates as minimum and maximum rate.
+ \qmlproperty int QtMultimedia::Camera::manualIsoSensitivity
- If the minimum frame rate is equal to the maximum frame rate, the frame rate is fixed.
- If not, the actual frame rate fluctuates between the minimum and the maximum.
+ Describes a manually set ISO sensitivity
- \sa QCamera::supportedViewfinderFrameRateRanges(), QCameraViewfinderSettings
+ Setting this property to -1 (the default), implies that the camera
+ automatically adjusts the ISO sensitivity.
*/
/*!
- \fn QCamera::FrameRateRange::FrameRateRange()
+ \property QCamera::manualIsoSensitivity
+ \brief Describes a manually set ISO sensitivity
- Constructs a null frame rate range, with both minimumFrameRate and maximumFrameRate
- equal to \c 0.0.
+ Setting this property to -1 (the default), implies that the camera
+ automatically adjusts the ISO sensitivity.
*/
+void QCamera::setManualIsoSensitivity(int iso)
+{
+ Q_D(QCamera);
+ if (iso <= 0)
+ iso = -1;
+ if (d->control)
+ d->control->setManualIsoSensitivity(iso);
+}
+
+int QCamera::manualIsoSensitivity() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->manualIsoSensitivity() : 100;
+}
/*!
- \fn QCamera::FrameRateRange::FrameRateRange(qreal minimum, qreal maximum)
+ \fn QCamera::setAutoIsoSensitivity()
+ Turn on auto sensitivity
+*/
- Constructs a frame rate range with the given \a minimum and \a maximum frame rates.
+void QCamera::setAutoIsoSensitivity()
+{
+ Q_D(QCamera);
+ if (d->control)
+ d->control->setManualIsoSensitivity(-1);
+}
+
+/*!
+ Returns the minimum ISO sensitivity supported by the camera.
*/
+int QCamera::minimumIsoSensitivity() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->minIso() : -1;
+}
/*!
- \variable QCamera::FrameRateRange::minimumFrameRate
- The minimum frame rate supported by the range, in frames per second.
+ Returns the maximum ISO sensitivity supported by the camera.
*/
+int QCamera::maximumIsoSensitivity() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->maxIso() : -1;
+}
/*!
- \variable QCamera::FrameRateRange::maximumFrameRate
- The maximum frame rate supported by the range, in frames per second.
+ The minimal exposure time in seconds.
*/
+float QCamera::minimumExposureTime() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->minExposureTime() : -1.f;
+}
/*!
- \enum QCamera::State
+ The maximal exposure time in seconds.
+*/
+float QCamera::maximumExposureTime() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->maxExposureTime() : -1.f;
+}
- This enum holds the current state of the camera.
+/*!
+ \qmlproperty float QtMultimedia::Camera::exposureTime
+ Returns the Camera's exposure time in seconds.
- \value UnloadedState
- The initial camera state, with camera not loaded.
- The camera capabilities, except supported capture modes,
- are unknown.
- While the supported settings are unknown in this state,
- it's allowed to set the camera capture settings like codec,
- resolution, or frame rate.
- \value LoadedState
- The camera is loaded and ready to be configured.
- In this state it's allowed to query camera capabilities,
- set capture resolution, codecs, etc.
- The viewfinder is not active in the loaded state.
- The camera consumes power in the loaded state.
- \value ActiveState
- In the active state as soon as camera is started
- the viewfinder displays video frames and the
- camera is ready for capture.
+ \sa manualExposureTime
*/
-
/*!
- \property QCamera::state
- \brief The current state of the camera object.
+ \property QCamera::exposureTime
+ \brief Camera's exposure time in seconds.
+
+ \sa minimumExposureTime(), maximumExposureTime(), setManualExposureTime()
*/
/*!
- \enum QCamera::Status
+ \fn QCamera::exposureTimeChanged(float speed)
- This enum holds the current status of the camera.
-
- \value ActiveStatus
- The camera has been started and can produce data.
- The viewfinder displays video frames in active state.
- Depending on backend, changing some camera settings like
- capture mode, codecs or resolution in ActiveState may lead
- to changing the camera status to LoadedStatus and StartingStatus while
- the settings are applied and back to ActiveStatus when the camera is ready.
- \value StartingStatus
- The camera is starting in result of state transition to QCamera::ActiveState.
- The camera service is not ready to capture yet.
- \value StoppingStatus
- The camera is stopping in result of state transition from QCamera::ActiveState
- to QCamera::LoadedState or QCamera::UnloadedState.
- \value StandbyStatus
- The camera is in the power saving standby mode.
- The camera may come to the standby mode after some time of inactivity
- in the QCamera::LoadedState state.
- \value LoadedStatus
- The camera is loaded and ready to be configured.
- This status indicates the camera device is opened and
- it's possible to query for supported image and video capture settings,
- like resolution, framerate and codecs.
- \value LoadingStatus
- The camera device loading in result of state transition from
- QCamera::UnloadedState to QCamera::LoadedState or QCamera::ActiveState.
- \value UnloadingStatus
- The camera device is unloading in result of state transition from
- QCamera::LoadedState or QCamera::ActiveState to QCamera::UnloadedState.
- \value UnloadedStatus
- The initial camera status, with camera not loaded.
- The camera capabilities including supported capture settings may be unknown.
- \value UnavailableStatus
- The camera or camera backend is not available.
+ Signals that a camera's exposure \a speed has changed.
*/
-
/*!
- \property QCamera::status
- \brief The current status of the camera object.
+ Returns the current exposure time in seconds.
*/
+float QCamera::exposureTime() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->exposureTime() : -1;
+}
/*!
- \enum QCamera::CaptureMode
+ \qmlproperty real QtMultimedia::Camera::manualExposureTime
- This enum holds the capture mode of the camera.
+ Gets or sets a manual exposure time.
- \value CaptureViewfinder Camera is only configured to display viewfinder.
- \value CaptureStillImage Camera is configured for still frames capture.
- \value CaptureVideo Camera is configured for video capture.
+ Setting this property to -1 (the default) means that the camera
+ automatically determines the exposure time.
*/
/*!
- \enum QCamera::LockType
-
- This enum holds the camera lock type.
+ \property QCamera::manualExposureTime
- \value NoLock
- \value LockExposure
- Lock camera exposure.
- \value LockWhiteBalance
- Lock the white balance.
- \value LockFocus
- Lock camera focus.
+ Set the manual exposure time to \a seconds
*/
+void QCamera::setManualExposureTime(float seconds)
+{
+ Q_D(QCamera);
+ if (d->control)
+ d->control->setManualExposureTime(seconds);
+}
/*!
- \property QCamera::lockStatus
- \brief The overall status for all the requested camera locks.
+ Returns the manual exposure time in seconds, or -1
+ if the camera is using automatic exposure times.
*/
+float QCamera::manualExposureTime() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->manualExposureTime() : -1;
+}
/*!
- \fn void QCamera::locked()
-
- Signals all the requested camera settings are locked.
+ Use automatically calculated exposure time
*/
+void QCamera::setAutoExposureTime()
+{
+ Q_D(QCamera);
+ if (d->control)
+ d->control->setManualExposureTime(-1);
+}
+
/*!
- \fn void QCamera::lockFailed()
+ \enum QCamera::FlashMode
- Signals locking of at least one requested camera settings failed.
+ \value FlashOff Flash is Off.
+ \value FlashOn Flash is On.
+ \value FlashAuto Automatic flash.
*/
/*!
- \fn QCamera::lockStatusChanged(QCamera::LockStatus status, QCamera::LockChangeReason reason)
+ \enum QCamera::TorchMode
- Signals the overall \a status for all the requested camera locks was changed with specified \a reason.
+ \value TorchOff Torch is Off.
+ \value TorchOn Torch is On.
+ \value TorchAuto Automatic torch.
*/
/*!
- \fn QCamera::lockStatusChanged(QCamera::LockType lock, QCamera::LockStatus status, QCamera::LockChangeReason reason)
- Signals the \a lock \a status was changed with specified \a reason.
+ \enum QCamera::ExposureMode
+
+ \value ExposureAuto Automatic mode.
+ \value ExposureManual Manual mode.
+ \value ExposurePortrait Portrait exposure mode.
+ \value ExposureNight Night mode.
+ \value ExposureSports Spots exposure mode.
+ \value ExposureSnow Snow exposure mode.
+ \value ExposureBeach Beach exposure mode.
+ \value ExposureAction Action mode. Since 5.5
+ \value ExposureLandscape Landscape mode. Since 5.5
+ \value ExposureNightPortrait Night portrait mode. Since 5.5
+ \value ExposureTheatre Theatre mode. Since 5.5
+ \value ExposureSunset Sunset mode. Since 5.5
+ \value ExposureSteadyPhoto Steady photo mode. Since 5.5
+ \value ExposureFireworks Fireworks mode. Since 5.5
+ \value ExposureParty Party mode. Since 5.5
+ \value ExposureCandlelight Candlelight mode. Since 5.5
+ \value ExposureBarcode Barcode mode. Since 5.5
*/
/*!
- \enum QCamera::LockStatus
+ \qmlproperty bool QtMultimedia::Camera::flashReady
- This enum holds the overall status for all the requested camera locks.
-
- \value Unlocked
- The application is not interested in camera settings value.
- The camera may keep this parameter without changes, this is common with camera focus,
- or adjust exposure and white balance constantly to keep the viewfinder image nice.
- \value Searching
- The application has requested the camera focus, exposure or white balance lock with
- QCamera::searchAndLock(). This state indicates the camera is focusing or
- calculating exposure and white balance.
- \value Locked
- The camera focus, exposure or white balance is locked.
- The camera is ready to capture, application may check the exposure
- stays the same, parameters. The \c Locked status usually means the
- requested parameter except in the cases when the parameter is requested
- to be constantly updated. For example, in continuous focusing mode,
- the focus is considered locked as long as the object is in focus, even
- while the actual focusing distance may be constantly changing.
+ Indicates if the flash is charged and ready to use.
*/
/*!
- \enum QCamera::LockChangeReason
+ \property QCamera::flashReady
+ \brief Indicates if the flash is charged and ready to use.
+*/
- This enum holds the reason why the camera lock status changed.
+/*!
+ \fn void QCamera::flashReady(bool ready)
- \value UserRequest
- The lock status changed in result of user request, usually to unlock camera settings.
- \value LockAcquired
- The lock status successfuly changed to QCamera::Locked.
- \value LockFailed
- The camera failed to acquire the requested lock in result of
- autofocus failure, exposure out of supported range, etc.
- \value LockLost
- The camera is not able to maintain the requested lock any more.
- Lock status is changed to QCamera::Unlocked.
- \value LockTemporaryLost
- The lock is lost, but the camera is working hard to reacquire it.
- This value may be used in continuous focusing mode,
- when the camera loses the focus, the focus lock state is changed to Qcamera::Searching
- with LockTemporaryLost reason.
+ Signal the flash \a ready status has changed.
*/
/*!
- \enum QCamera::Error
-
- This enum holds the last error code.
+ \fn void QCamera::isoSensitivityChanged(int value)
- \value NoError No errors have occurred.
- \value CameraError An error has occurred.
- \value InvalidRequestError System resource doesn't support requested functionality.
- \value ServiceMissingError No camera service available.
- \value NotSupportedFeatureError The feature is not supported.
+ Signal emitted when sensitivity changes to \a value.
*/
/*!
- \fn void QCamera::error(QCamera::Error value)
- \obsolete
+ \fn void QCamera::exposureCompensationChanged(float value)
- Use errorOccurred() instead.
+ Signal emitted when the exposure compensation changes to \a value.
*/
+
/*!
- \fn void QCamera::errorOccurred(QCamera::Error value)
- \since 5.15
+ \qmlproperty WhiteBalanceMode QtMultimedia::Camera::whiteBalanceMode
+
+ Gets or sets the white balance mode being used.
- Signal emitted when error state changes to \a value.
+ \sa QCamera::WhiteBalanceMode
*/
/*!
- \enum QCamera::Position
- \since 5.3
+ \property QCamera::whiteBalanceMode
- This enum specifies the physical position of the camera on the system hardware.
+ Returns the white balance mode being used.
+*/
+QCamera::WhiteBalanceMode QCamera::whiteBalanceMode() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->whiteBalanceMode() : QCamera::WhiteBalanceAuto;
+}
- \value UnspecifiedPosition The camera position is unspecified or unknown.
+/*!
+ Sets the white balance to \a mode.
+*/
+void QCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode)
+{
+ Q_D(QCamera);
+ if (!d->control)
+ return;
+ if (!d->control->isWhiteBalanceModeSupported(mode))
+ return;
+ d->control->setWhiteBalanceMode(mode);
+ if (mode == QCamera::WhiteBalanceManual)
+ d->control->setColorTemperature(5600);
+}
- \value BackFace The camera is on the back face of the system hardware. For example on a
- mobile device, it means it is on the opposite side to that of the screen.
+/*!
+ \qmlmethod bool QtMultimedia::Camera::isWhiteBalanceModeSupported(WhiteBalanceMode mode)
- \value FrontFace The camera is on the front face of the system hardware. For example on a
- mobile device, it means it is on the same side as that of the screen. Viewfinder frames of
- front-facing cameras are mirrored horizontally, so the users can see themselves as looking
- into a mirror. Captured images or videos are not mirrored.
+ Returns true if the white balance \a mode is supported.
+*/
- \sa QCameraInfo::position()
+/*!
+ Returns true if the white balance \a mode is supported.
*/
+bool QCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const
+{
+ Q_D(const QCamera);
+ return d->control && d->control->isWhiteBalanceModeSupported(mode);
+}
/*!
- \fn void QCamera::captureModeChanged(QCamera::CaptureModes mode)
+ \qmlmethod QtMultimedia::Camera::colorTemperature
- Signals the capture \a mode has changed.
+ Gets or sets the current color temperature.
+
+ Setting a color temperature will only have an effect if WhiteBalanceManual is
+ supported. In this case, setting a temperature greater 0 will automatically set the
+ white balance mode to WhiteBalanceManual. Setting the temperature to 0 will reset
+ the white balance mode to WhiteBalanceAuto.
*/
/*!
- \fn QCamera::stateChanged(QCamera::State state)
-
- Signals the camera \a state has changed.
+ \property QCamera::colorTemperature
- Usually the state changes is caused by calling
- load(), unload(), start() and stop(),
- but the state can also be changed change as a result of camera error.
+ Returns the current color temperature if the
+ current white balance mode is \c WhiteBalanceManual. For other modes the
+ return value is undefined.
*/
+int QCamera::colorTemperature() const
+{
+ Q_D(const QCamera);
+ return d->control ? d->control->colorTemperature() : 0;
+}
/*!
- \fn QCamera::statusChanged(QCamera::Status status)
+ Sets manual white balance to \a colorTemperature. This is used
+ when whiteBalanceMode() is set to \c WhiteBalanceManual. The units are Kelvin.
- Signals the camera \a status has changed.
+ Setting a color temperature will only have an effect if WhiteBalanceManual is
+ supported. In this case, setting a temperature greater 0 will automatically set the
+ white balance mode to WhiteBalanceManual. Setting the temperature to 0 will reset
+ the white balance mode to WhiteBalanceAuto.
+*/
+void QCamera::setColorTemperature(int colorTemperature)
+{
+ Q_D(QCamera);
+ if (!d->control)
+ return;
+ if (colorTemperature < 0)
+ colorTemperature = 0;
+ if (colorTemperature == 0) {
+ d->control->setWhiteBalanceMode(WhiteBalanceAuto);
+ } else if (!isWhiteBalanceModeSupported(WhiteBalanceManual)) {
+ return;
+ } else {
+ d->control->setWhiteBalanceMode(WhiteBalanceManual);
+ }
+ d->control->setColorTemperature(colorTemperature);
+}
+
+/*!
+ \enum QCamera::WhiteBalanceMode
+
+ \value WhiteBalanceAuto Auto white balance mode.
+ \value WhiteBalanceManual Manual white balance. In this mode the white
+ balance should be set with setColorTemperature()
+ \value WhiteBalanceSunlight Sunlight white balance mode.
+ \value WhiteBalanceCloudy Cloudy white balance mode.
+ \value WhiteBalanceShade Shade white balance mode.
+ \value WhiteBalanceTungsten Tungsten (incandescent) white balance mode.
+ \value WhiteBalanceFluorescent Fluorescent white balance mode.
+ \value WhiteBalanceFlash Flash white balance mode.
+ \value WhiteBalanceSunset Sunset white balance mode.
*/
+/*!
+ \fn void QCamera::brightnessChanged()
+ \internal
+*/
+/*!
+ \fn void QCamera::contrastChanged()
+ \internal
+*/
+/*!
+ \fn void QCamera::hueChanged()
+ \internal
+*/
+/*!
+ \fn void QCamera::saturationChanged()
+ \internal
+*/
QT_END_NAMESPACE
#include "moc_qcamera.cpp"