From: Mohammed Sameer Date: Sat, 8 Dec 2012 18:06:38 +0000 (+0200) Subject: VideoTorch and VideoMute are now properties of Camera X-Git-Url: http://cgit.sxemacs.org/?p=harmattan%2Fcameraplus;a=commitdiff_plain;h=3338e949958e3f5264c0be6a043940469b3111ae VideoTorch and VideoMute are now properties of Camera Renamed Mute to VideoMute VideoTorch state is now stored and restored upon startup --- diff --git a/imports/camera.cpp b/imports/camera.cpp index a3b1e69..833b580 100644 --- a/imports/camera.cpp +++ b/imports/camera.cpp @@ -45,6 +45,9 @@ #include "focus.h" #include "autofocus.h" +#include "videomute.h" +#include "videotorch.h" + // TODO: a viewfinder class that inherits QDeclarativeItem Camera::Camera(QDeclarativeItem *parent) : @@ -66,8 +69,9 @@ Camera::Camera(QDeclarativeItem *parent) : m_noiseReduction(0), m_flickerReduction(0), m_focus(0), - m_autoFocus(0) { - + m_autoFocus(0), + m_videoMute(0), + m_videoTorch(0) { // TODO: } @@ -92,7 +96,8 @@ Camera::~Camera() { delete m_flickerReduction; delete m_focus; delete m_autoFocus; - + delete m_videoMute; + delete m_videoTorch; // TODO: cleanup } @@ -333,6 +338,14 @@ void Camera::resetCapabilities() { delete m_autoFocus; m_autoFocus = new AutoFocus(dev, this); emit autoFocusChanged(); + + delete m_videoMute; + m_videoMute = new VideoMute(dev, this); + emit videoMuteChanged(); + + delete m_videoTorch; + m_videoTorch = new VideoTorch(dev, this); + emit videoTorchChanged(); } Zoom *Camera::zoom() const { @@ -386,3 +399,11 @@ Focus *Camera::focus() const { AutoFocus *Camera::autoFocus() const { return m_autoFocus; } + +VideoMute *Camera::videoMute() const { + return m_videoMute; +} + +VideoTorch *Camera::videoTorch() const { +return m_videoTorch; +} diff --git a/imports/camera.h b/imports/camera.h index a393aff..13bcb30 100644 --- a/imports/camera.h +++ b/imports/camera.h @@ -45,6 +45,8 @@ class NoiseReduction; class FlickerReduction; class Focus; class AutoFocus; +class VideoMute; +class VideoTorch; class Camera : public QDeclarativeItem { Q_OBJECT @@ -72,6 +74,9 @@ class Camera : public QDeclarativeItem { Q_PROPERTY(Focus *focus READ focus NOTIFY focusChanged); Q_PROPERTY(AutoFocus *autoFocus READ autoFocus NOTIFY autoFocusChanged); + Q_PROPERTY(VideoMute *videoMute READ videoMute NOTIFY videoMuteChanged); + Q_PROPERTY(VideoTorch *videoTorch READ videoTorch NOTIFY videoTorchChanged); + Q_ENUMS(CameraMode); public: @@ -124,6 +129,9 @@ public: Focus *focus() const; AutoFocus *autoFocus() const; + VideoMute *videoMute() const; + VideoTorch *videoTorch() const; + signals: void deviceCountChanged(); void deviceIdChanged(); @@ -148,6 +156,9 @@ signals: void focusChanged(); void autoFocusChanged(); + void videoMuteChanged(); + void videoTorchChanged(); + protected: void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry); @@ -178,6 +189,9 @@ private: FlickerReduction *m_flickerReduction; Focus *m_focus; AutoFocus *m_autoFocus; + + VideoMute *m_videoMute; + VideoTorch *m_videoTorch; }; #endif /* CAMERA_H */ diff --git a/imports/imports.pro b/imports/imports.pro index 11ea5ec..097fa5f 100644 --- a/imports/imports.pro +++ b/imports/imports.pro @@ -13,13 +13,13 @@ QT += declarative HEADERS += plugin.h previewprovider.h camera.h mode.h imagemode.h videomode.h \ zoom.h flash.h scene.h evcomp.h videotorch.h whitebalance.h \ colortone.h exposure.h aperture.h iso.h noisereduction.h \ - flickerreduction.h mute.h metadata.h imagesettings.h imageresolutionmodel.h \ - videosettings.h videoresolutionmodel.h notifications.h \ - notificationscontainer.h sounds.h focus.h autofocus.h + flickerreduction.h videomute.h metadata.h imagesettings.h \ + imageresolutionmodel.h videosettings.h videoresolutionmodel.h \ + notifications.h notificationscontainer.h sounds.h focus.h autofocus.h SOURCES += plugin.cpp previewprovider.cpp camera.cpp mode.cpp imagemode.cpp videomode.cpp \ zoom.cpp flash.cpp scene.cpp evcomp.cpp videotorch.cpp whitebalance.cpp \ colortone.cpp exposure.cpp aperture.cpp iso.cpp noisereduction.cpp \ - flickerreduction.cpp mute.cpp metadata.cpp imagesettings.cpp imageresolutionmodel.cpp \ - videosettings.cpp videoresolutionmodel.cpp notifications.cpp \ - notificationscontainer.cpp sounds.cpp focus.cpp autofocus.cpp + flickerreduction.cpp videomute.cpp metadata.cpp imagesettings.cpp \ + imageresolutionmodel.cpp videosettings.cpp videoresolutionmodel.cpp \ + notifications.cpp notificationscontainer.cpp sounds.cpp focus.cpp autofocus.cpp diff --git a/imports/mute.cpp b/imports/mute.cpp deleted file mode 100644 index b9b5f72..0000000 --- a/imports/mute.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/*! - * This file is part of CameraPlus. - * - * Copyright (C) 2012 Mohammed Sameer - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mute.h" -#include "qtcammute.h" -#include "camera.h" -#include "qtcamdevice.h" - -Mute::Mute(QObject *parent) : - QObject(parent), m_cam(0), m_mute(0) { - -} - -Mute::~Mute() { - m_cam = 0; -} - -Camera *Mute::camera() { - return m_cam; -} - -void Mute::setCamera(Camera *camera) { - if (camera == m_cam) { - return; - } - - if (m_cam) { - QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged())); - } - - m_cam = camera; - - if (m_cam) { - QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged())); - } - - emit cameraChanged(); - - deviceChanged(); -} - -bool Mute::isEnabled() const { - return m_mute ? m_mute->isEnabled() : false; -} - -void Mute::setEnabled(bool enabled) { - if (m_mute) { - m_mute->setEnabled(enabled); - } -} - -void Mute::deviceChanged() { - if (m_mute) { - delete m_mute; m_mute = 0; - } - - if (m_cam->device()) { - m_mute = new QtCamMute(m_cam->device(), this); - QObject::connect(m_mute, SIGNAL(stateChanged()), this, SIGNAL(stateChanged())); - - emit stateChanged(); - } -} diff --git a/imports/plugin.cpp b/imports/plugin.cpp index 571eb95..08ef8df 100644 --- a/imports/plugin.cpp +++ b/imports/plugin.cpp @@ -37,7 +37,7 @@ #include "flickerreduction.h" #include "focus.h" #include "autofocus.h" -#include "mute.h" +#include "videomute.h" #include "metadata.h" #include "imagesettings.h" #include "imageresolutionmodel.h" @@ -71,8 +71,8 @@ void Plugin::registerTypes(QDeclarativeEngine *engine) { qmlRegisterUncreatableType(URI, MAJOR, MINOR, "Focus", QObject::tr("Cannot create separate instance of Focus")); qmlRegisterUncreatableType(URI, MAJOR, MINOR, "AutoFocus", QObject::tr("Cannot create separate instance of AutoFocus")); - qmlRegisterType(URI, MAJOR, MINOR, "Mute"); - qmlRegisterType(URI, MAJOR, MINOR, "VideoTorch"); + qmlRegisterUncreatableType(URI, MAJOR, MINOR, "VideoMute", QObject::tr("Cannot create separate instance of VideoMute")); + qmlRegisterUncreatableType(URI, MAJOR, MINOR, "VideoTorch", QObject::tr("Cannot create separate instance of VideoTorch")); qmlRegisterType(URI, MAJOR, MINOR, "MetaData"); qmlRegisterType(URI, MAJOR, MINOR, "ImageSettings"); diff --git a/imports/videomute.cpp b/imports/videomute.cpp new file mode 100644 index 0000000..7fbe4e1 --- /dev/null +++ b/imports/videomute.cpp @@ -0,0 +1,41 @@ +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012 Mohammed Sameer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "videomute.h" +#include "qtcamvideomute.h" + +VideoMute::VideoMute(QtCamDevice *dev, QObject *parent) : + QObject(parent), + m_mute(new QtCamVideoMute(dev, this)) { + + QObject::connect(m_mute, SIGNAL(stateChanged()), this, SIGNAL(stateChanged())); +} + +VideoMute::~VideoMute() { + delete m_mute; m_mute = 0; +} + +bool VideoMute::isEnabled() const { + return m_mute->isEnabled(); +} + +void VideoMute::setEnabled(bool enabled) { + m_mute->setEnabled(enabled); +} diff --git a/imports/mute.h b/imports/videomute.h similarity index 73% rename from imports/mute.h rename to imports/videomute.h index b453153..8ae471b 100644 --- a/imports/mute.h +++ b/imports/videomute.h @@ -20,39 +20,30 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef MUTE_H -#define MUTE_H +#ifndef VIDEO_MUTE_H +#define VIDEO_MUTE_H #include -class Camera; -class QtCamMute; +class QtCamVideoMute; +class QtCamDevice; -class Mute : public QObject { +class VideoMute : public QObject { Q_OBJECT - Q_PROPERTY(Camera* camera READ camera WRITE setCamera NOTIFY cameraChanged); Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY stateChanged); public: - Mute(QObject *parent = 0); - ~Mute(); - - Camera *camera(); - void setCamera(Camera *camera); + VideoMute(QtCamDevice *dev, QObject *parent = 0); + ~VideoMute(); bool isEnabled() const; void setEnabled(bool enabled); signals: void stateChanged(); - void cameraChanged(); - -private slots: - void deviceChanged(); private: - Camera *m_cam; - QtCamMute *m_mute; + QtCamVideoMute *m_mute; }; -#endif /* MUTE_H */ +#endif /* VIDEO_MUTE_H */ diff --git a/imports/videotorch.cpp b/imports/videotorch.cpp index f5fb1b2..4dce14e 100644 --- a/imports/videotorch.cpp +++ b/imports/videotorch.cpp @@ -20,62 +20,22 @@ #include "videotorch.h" #include "qtcamvideotorch.h" -#include "camera.h" -#include "qtcamdevice.h" -#include "qtcamvideomode.h" -VideoTorch::VideoTorch(QObject *parent) : - QObject(parent), m_cam(0), m_torch(0) { +VideoTorch::VideoTorch(QtCamDevice *dev, QObject *parent) : + QObject(parent), + m_torch(new QtCamVideoTorch(dev, this)) { + QObject::connect(m_torch, SIGNAL(stateChanged()), this, SIGNAL(stateChanged())); } VideoTorch::~VideoTorch() { - m_cam = 0; -} - -Camera *VideoTorch::camera() { - return m_cam; -} - -void VideoTorch::setCamera(Camera *camera) { - if (camera == m_cam) { - return; - } - - if (m_cam) { - QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged())); - } - - m_cam = camera; - - if (m_cam) { - QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged())); - } - - emit cameraChanged(); - - deviceChanged(); + delete m_torch; m_torch = 0; } bool VideoTorch::isOn() const { - return m_torch ? m_torch->isOn() : false; + return m_torch->isOn(); } void VideoTorch::setOn(bool on) { - if (m_torch) { - m_torch->setOn(on); - } -} - -void VideoTorch::deviceChanged() { - if (m_torch) { - delete m_torch; m_torch = 0; - } - - if (m_cam->device()) { - m_torch = new QtCamVideoTorch(m_cam->device(), this); - QObject::connect(m_torch, SIGNAL(stateChanged()), this, SIGNAL(stateChanged())); - - emit stateChanged(); - } + m_torch->setOn(on); } diff --git a/imports/videotorch.h b/imports/videotorch.h index c833aca..5c5397a 100644 --- a/imports/videotorch.h +++ b/imports/videotorch.h @@ -25,33 +25,24 @@ #include -class Camera; class QtCamVideoTorch; +class QtCamDevice; class VideoTorch : public QObject { Q_OBJECT - Q_PROPERTY(Camera* camera READ camera WRITE setCamera NOTIFY cameraChanged); Q_PROPERTY(bool on READ isOn WRITE setOn NOTIFY stateChanged); public: - VideoTorch(QObject *parent = 0); + VideoTorch(QtCamDevice *dev, QObject *parent = 0); ~VideoTorch(); - Camera *camera(); - void setCamera(Camera *camera); - bool isOn() const; void setOn(bool on); signals: void stateChanged(); - void cameraChanged(); - -private slots: - void deviceChanged(); private: - Camera *m_cam; QtCamVideoTorch *m_torch; }; diff --git a/lib/lib.pro b/lib/lib.pro index 163c55b..17f6b05 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -18,7 +18,7 @@ HEADERS += qtcamconfig.h qtcamera.h qtcamscanner.h qtcamdevice.h qtcamviewfinder qtcamzoom.h qtcamflash.h qtcamscene.h qtcamevcomp.h qtcamvideotorch.h \ qtcamwhitebalance.h qtcamcolortone.h qtcamflickerreduction.h \ qtcamnoisereduction.h qtcamiso.h qtcamaperture.h qtcamexposure.h \ - qtcammute.h qtcamnotifications.h qtcamfocus.h qtcamautofocus.h + qtcamvideomute.h qtcamnotifications.h qtcamfocus.h qtcamautofocus.h SOURCES += qtcamconfig.cpp qtcamera.cpp qtcamscanner.cpp qtcamdevice.cpp qtcamviewfinder.cpp \ qtcammode.cpp qtcamgstreamermessagehandler.cpp qtcamgstreamermessagelistener.cpp \ @@ -28,7 +28,7 @@ SOURCES += qtcamconfig.cpp qtcamera.cpp qtcamscanner.cpp qtcamdevice.cpp qtcamvi qtcamzoom.cpp qtcamflash.cpp qtcamscene.cpp qtcamevcomp.cpp qtcamvideotorch.cpp \ qtcamwhitebalance.cpp qtcamcolortone.cpp qtcamflickerreduction.cpp \ qtcamnoisereduction.cpp qtcamiso.cpp qtcamaperture.cpp qtcamexposure.cpp \ - qtcammute.cpp qtcamnotifications.cpp qtcamfocus.cpp qtcamautofocus.cpp + qtcamvideomute.cpp qtcamnotifications.cpp qtcamfocus.cpp qtcamautofocus.cpp HEADERS += qtcammode_p.h qtcamdevice_p.h qtcamcapability_p.h qtcamautofocus_p.h diff --git a/lib/qtcamdevice.h b/lib/qtcamdevice.h index 0428f4d..692c401 100644 --- a/lib/qtcamdevice.h +++ b/lib/qtcamdevice.h @@ -81,7 +81,7 @@ private: friend class QtCamMetaData; friend class QtCamCapability; friend class QtCamVideoTorch; - friend class QtCamMute; + friend class QtCamVideoMute; friend class QtCamAutoFocusPrivate; QtCamDevicePrivate *d_ptr; diff --git a/lib/qtcammute.cpp b/lib/qtcamvideomute.cpp similarity index 82% rename from lib/qtcammute.cpp rename to lib/qtcamvideomute.cpp index bdc5848..21de3fa 100644 --- a/lib/qtcammute.cpp +++ b/lib/qtcamvideomute.cpp @@ -18,14 +18,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "qtcammute.h" +#include "qtcamvideomute.h" #include "qtcamdevice.h" #include "qtcamdevice_p.h" #include -class QtCamMutePrivate { +class QtCamVideoMutePrivate { public: - static void mute_notify(GObject *gobject, GParamSpec *pspec, QtCamMute *q) { + static void mute_notify(GObject *gobject, GParamSpec *pspec, QtCamVideoMute *q) { Q_UNUSED(gobject); Q_UNUSED(pspec); @@ -36,8 +36,8 @@ public: gulong handler; }; -QtCamMute::QtCamMute(QtCamDevice *dev, QObject *parent) : - QObject(parent), d_ptr(new QtCamMutePrivate) { +QtCamVideoMute::QtCamVideoMute(QtCamDevice *dev, QObject *parent) : + QObject(parent), d_ptr(new QtCamVideoMutePrivate) { d_ptr->dev = dev; d_ptr->handler = 0; @@ -45,11 +45,11 @@ QtCamMute::QtCamMute(QtCamDevice *dev, QObject *parent) : if (d_ptr->dev->d_ptr->cameraBin) { d_ptr->handler = g_signal_connect(d_ptr->dev->d_ptr->cameraBin, "notify::mute", - G_CALLBACK(QtCamMutePrivate::mute_notify), this); + G_CALLBACK(QtCamVideoMutePrivate::mute_notify), this); } } -QtCamMute::~QtCamMute() { +QtCamVideoMute::~QtCamVideoMute() { if (d_ptr->dev && d_ptr->handler) { g_signal_handler_disconnect(d_ptr->dev->d_ptr->cameraBin, d_ptr->handler); } @@ -57,7 +57,7 @@ QtCamMute::~QtCamMute() { delete d_ptr; d_ptr = 0; } -void QtCamMute::setEnabled(bool enabled) { +void QtCamVideoMute::setEnabled(bool enabled) { gboolean val = enabled ? TRUE : FALSE; if (d_ptr->dev->d_ptr->cameraBin) { @@ -65,7 +65,7 @@ void QtCamMute::setEnabled(bool enabled) { } } -bool QtCamMute::isEnabled() const { +bool QtCamVideoMute::isEnabled() const { gboolean val = FALSE; if (d_ptr->dev->d_ptr->cameraBin) { diff --git a/lib/qtcammute.h b/lib/qtcamvideomute.h similarity index 79% rename from lib/qtcammute.h rename to lib/qtcamvideomute.h index 3732e93..60466bf 100644 --- a/lib/qtcammute.h +++ b/lib/qtcamvideomute.h @@ -20,20 +20,20 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef QT_CAM_MUTE_H -#define QT_CAM_MUTE_H +#ifndef QT_CAM_VIDEO_MUTE_H +#define QT_CAM_VIDEO_MUTE_H #include class QtCamDevice; -class QtCamMutePrivate; +class QtCamVideoMutePrivate; -class QtCamMute : public QObject { +class QtCamVideoMute : public QObject { Q_OBJECT public: - QtCamMute(QtCamDevice *dev, QObject *parent = 0); - ~QtCamMute(); + QtCamVideoMute(QtCamDevice *dev, QObject *parent = 0); + ~QtCamVideoMute(); void setEnabled(bool enabled); bool isEnabled() const; @@ -42,7 +42,7 @@ signals: void stateChanged(); private: - QtCamMutePrivate *d_ptr; + QtCamVideoMutePrivate *d_ptr; }; -#endif /* QT_CAM_MUTE_H */ +#endif /* QT_CAM_VIDEO_MUTE_H */ diff --git a/qml/VideoPage.qml b/qml/VideoPage.qml index ec09db0..85c14cf 100644 --- a/qml/VideoPage.qml +++ b/qml/VideoPage.qml @@ -148,6 +148,7 @@ CameraPage { VideoTorchButton { id: torch + camera: cam visible: videoControlsVisible anchors.top: parent.top anchors.left: parent.left diff --git a/qml/VideoTorchButton.qml b/qml/VideoTorchButton.qml index 786e94b..3e820a6 100644 --- a/qml/VideoTorchButton.qml +++ b/qml/VideoTorchButton.qml @@ -30,10 +30,14 @@ Button { height: 56 opacity: 0.5 - iconSource: torch.on ? "image://theme/icon-m-camera-torch-on" : "image://theme/icon-m-camera-torch-off" - onClicked: torch.on = !torch.on - VideoTorch { - id: torch - camera: cam + property Camera camera: null + + iconSource: settings.videoTorchOn ? "image://theme/icon-m-camera-torch-on" : "image://theme/icon-m-camera-torch-off" + onClicked: settings.videoTorchOn = !settings.videoTorchOn + + Binding { + target: camera.videoTorch + property: "on" + value: settings.videoTorchOn } } diff --git a/src/settings.cpp b/src/settings.cpp index 5eaabbf..3114e50 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -38,6 +38,7 @@ #define DEFAULT_IMAGE_ASPECT_RATIO "16:9" #define DEFAULT_VIDEO_RESOLUTION "high" #define DEFAULT_SOUND_ENABLED true +#define DEFAULT_VIDEO_TORCH_ON false Settings::Settings(QObject *parent) : QObject(parent), @@ -284,3 +285,14 @@ void Settings::setSoundEnabled(bool enabled) { emit soundEnabledChanged(); } } + +bool Settings::isVideoTorchOn() const { + return m_settings->value("video/torchOn", DEFAULT_VIDEO_TORCH_ON).toBool(); +} + +void Settings::setVideoTorchOn(bool on) { + if (isVideoTorchOn() != on) { + m_settings->setValue("video/torchOn", on); + emit videoTorchOnChanged(); + } +} diff --git a/src/settings.h b/src/settings.h index 684b45b..4ccafc0 100644 --- a/src/settings.h +++ b/src/settings.h @@ -55,6 +55,7 @@ class Settings : public QObject { Q_PROPERTY(QString videoResolution READ videoResolution WRITE setVideoResolution NOTIFY videoResolutionChanged); Q_PROPERTY(bool soundEnabled READ isSoundEnabled WRITE setSoundEnabled NOTIFY soundEnabledChanged); + Q_PROPERTY(bool videoTorchOn READ isVideoTorchOn WRITE setVideoTorchOn NOTIFY videoTorchOnChanged); public: Settings(QObject *parent = 0); @@ -120,6 +121,9 @@ public: bool isSoundEnabled() const; void setSoundEnabled(bool enabled); + bool isVideoTorchOn() const; + void setVideoTorchOn(bool on); + signals: void modeChanged(); void creatorNameChanged(); @@ -141,6 +145,7 @@ signals: void videoAspectRatioChanged(); void videoResolutionChanged(); void soundEnabledChanged(); + void videoTorchOnChanged(); private: QSettings *m_settings;