diff options
author | Michael Goddard <michael.goddard@nokia.com> | 2012-01-17 16:46:11 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-19 01:16:55 +0100 |
commit | 8c74e5e7e7a5654f1af670b6d40f98e736d1f7d9 (patch) | |
tree | cd8fb3be484adc0c8714b0b89a818559f6b4a32a | |
parent | c40d79106c056057bfd38cd74c4d9c8df90277b3 (diff) |
Add a simple Torch class that wraps the camera flash.
Since nearly all programmable torch hardware doubles as camera flash
hardware, offer this class here that wraps the QCameraFlashControl.
Change-Id: Ib2c061c21c14221d67477d8a3fd89a76fc26ed71
Reviewed-by: Jonas Rabbe <jonas.rabbe@nokia.com>
-rw-r--r-- | src/imports/multimedia/multimedia.cpp | 2 | ||||
-rw-r--r-- | src/imports/multimedia/multimedia.pro | 6 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativetorch.cpp | 184 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativetorch_p.h | 93 |
4 files changed, 283 insertions, 2 deletions
diff --git a/src/imports/multimedia/multimedia.cpp b/src/imports/multimedia/multimedia.cpp index 8b8650604..b898c9c9d 100644 --- a/src/imports/multimedia/multimedia.cpp +++ b/src/imports/multimedia/multimedia.cpp @@ -57,6 +57,7 @@ #include "qdeclarativecameraflash_p.h" #include "qdeclarativecamerafocus_p.h" #include "qdeclarativecameraimageprocessing_p.h" +#include "qdeclarativetorch_p.h" QML_DECLARE_TYPE(QSoundEffect) @@ -103,6 +104,7 @@ public: qmlRegisterType<QDeclarativeRadioData>(uri, 5, 0, "RadioData"); qmlRegisterType<QDeclarativeBackgroundAudio>(uri, 5, 0, "BackgroundAudio"); qmlRegisterType<QDeclarativeCamera>(uri, 5, 0, "Camera"); + qmlRegisterType<QDeclarativeTorch>(uri, 5, 0, "Torch"); qmlRegisterUncreatableType<QDeclarativeCameraCapture>(uri, 5, 0, "CameraCapture", trUtf8("CameraCapture is only provided by Camera element")); qmlRegisterUncreatableType<QDeclarativeCameraRecorder>(uri, 5, 0, "CameraRecorder", diff --git a/src/imports/multimedia/multimedia.pro b/src/imports/multimedia/multimedia.pro index 99684ee49..f9c7f6e8a 100644 --- a/src/imports/multimedia/multimedia.pro +++ b/src/imports/multimedia/multimedia.pro @@ -26,7 +26,8 @@ HEADERS += \ qdeclarativecameraflash_p.h \ qdeclarativecamerafocus_p.h \ qdeclarativecameraimageprocessing_p.h \ - qdeclarativecamerapreviewprovider_p.h + qdeclarativecamerapreviewprovider_p.h \ + qdeclarativetorch_p.h SOURCES += \ multimedia.cpp \ @@ -46,7 +47,8 @@ SOURCES += \ qdeclarativecameraflash.cpp \ qdeclarativecamerafocus.cpp \ qdeclarativecameraimageprocessing.cpp \ - qdeclarativecamerapreviewprovider.cpp + qdeclarativecamerapreviewprovider.cpp \ + qdeclarativetorch.cpp OTHER_FILES += \ Video.qml diff --git a/src/imports/multimedia/qdeclarativetorch.cpp b/src/imports/multimedia/qdeclarativetorch.cpp new file mode 100644 index 000000000..35d7a78f6 --- /dev/null +++ b/src/imports/multimedia/qdeclarativetorch.cpp @@ -0,0 +1,184 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QDebug> +#include <QMediaService> + +#include "qdeclarativetorch_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass Torch QDeclarativeTorch + \brief The Torch element provides simple control over torch functionality + + \ingroup multimedia_qml + + This element is part of the \bold{QtMultimedia 5.0} module. + + In many cases the torch hardware is shared with camera flash functionality, + and might be automatically controlled by the device. You have control over + the power level (of course, higher power levels are brighter but reduce + battery life significantly). + + \qml + import QtQuick 2.0 + import QtMultimedia 5.0 + + Torch { + power: 75 // 75% of full power + enabled: true // On + } + + \endqml +*/ +QDeclarativeTorch::QDeclarativeTorch(QObject *parent) + : QObject(parent) +{ + m_camera = new QCamera(this); + QMediaService *service = m_camera->service(); + + m_exposure = service ? service->requestControl<QCameraExposureControl*>() : 0; + m_flash = service ? service->requestControl<QCameraFlashControl*>() : 0; + + if (m_exposure) + connect(m_exposure, SIGNAL(exposureParameterChanged(int)), SLOT(parameterChanged(int))); + + // XXX There's no signal for flash mode changed +} + +QDeclarativeTorch::~QDeclarativeTorch() +{ +} + +/*! + \qmlproperty bool Torch::enabled + \property QDeclarativeTorch::enabled + + Whether the torch is on. If the torch functionality is shared + with the camera flash hardware, the camera will take priority + over torch settings and the torch may be disabled. +*/ +/*! + Returns whether the torch is on. If the torch functionality + is shared with the camera flash hardware, the camera will take + priority and the torch may be disabled. + */ +bool QDeclarativeTorch::enabled() const +{ + if (!m_flash) + return false; + + return m_flash->flashMode() & QCameraExposure::FlashTorch; +} + + +/*! + If \a on is true, attempt to turn on the torch. + If the torch hardware is already in use by the camera, this will + be ignored. +*/ +void QDeclarativeTorch::setEnabled(bool on) +{ + if (!m_flash) + return; + + QCameraExposure::FlashModes mode = m_flash->flashMode(); + + if (mode & QCameraExposure::FlashTorch) { + if (!on) { + m_flash->setFlashMode(mode & ~QCameraExposure::FlashTorch); + emit enabledChanged(); + } + } else { + if (on) { + m_flash->setFlashMode(mode | QCameraExposure::FlashTorch); + emit enabledChanged(); + } + } +} + +/*! + \qmlproperty int Torch::power + \property QDeclarativeTorch::power + + The current torch power setting, as a percentage of full power. + + In some cases this setting may change automatically as a result + of temperature or battery conditions. +*/ +/*! + Returns the current torch power settings, as a percentage of full power. +*/ +int QDeclarativeTorch::power() const +{ + if (!m_exposure) + return 0; + + return m_exposure->exposureParameter(QCameraExposureControl::FlashPower).toInt(); +} + +/*! + Sets the current torch power setting to \a power, as a percentage of + full power. +*/ +void QDeclarativeTorch::setPower(int power) +{ + if (!m_exposure) + return; + + power = qBound(0, power, 100); + if (this->power() != power) { + m_exposure->setExposureParameter(QCameraExposureControl::FlashPower, power); + emit powerChanged(); + } +} + +/* Check for changes in flash power */ +void QDeclarativeTorch::parameterChanged(int parameter) +{ + if (parameter == QCameraExposureControl::FlashPower) { + emit powerChanged(); + } +} + +QT_END_NAMESPACE + diff --git a/src/imports/multimedia/qdeclarativetorch_p.h b/src/imports/multimedia/qdeclarativetorch_p.h new file mode 100644 index 000000000..0949c4f80 --- /dev/null +++ b/src/imports/multimedia/qdeclarativetorch_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QDECLARATIVETORCH_P_H +#define QDECLARATIVETORCH_P_H + +#include <QObject> +#include <QtDeclarative/qdeclarative.h> +#include <qcamera.h> +#include <qcameraexposurecontrol.h> +#include <qcameraflashcontrol.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QDeclarativeTorch : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(int power READ power WRITE setPower NOTIFY powerChanged) + + // Errors? + +public: + explicit QDeclarativeTorch(QObject *parent = 0); + ~QDeclarativeTorch(); + + bool enabled() const; + void setEnabled(bool enabled); + + int power() const; + void setPower(int power); + +signals: + void enabledChanged(); + void powerChanged(); + +private slots: + void parameterChanged(int parameter); + +private: + QCamera *m_camera; + QCameraExposureControl *m_exposure; + QCameraFlashControl *m_flash; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeTorch)) + +QT_END_HEADER + +#endif // QDECLARATIVETORCH_P_H |