From: Mohammed Sameer Date: Tue, 13 Aug 2013 18:19:47 +0000 (+0300) Subject: Added methods to find VideoResolution and set it X-Git-Url: http://cgit.sxemacs.org/?p=harmattan%2Fcameraplus;a=commitdiff_plain;h=e288015c39c4fb6d846d9e742de123ebea485573 Added methods to find VideoResolution and set it --- diff --git a/declarative/videosettings.cpp b/declarative/videosettings.cpp index ec29a7a..0a8f517 100644 --- a/declarative/videosettings.cpp +++ b/declarative/videosettings.cpp @@ -24,15 +24,25 @@ #include "qtcamdevice.h" #include "qtcamvideomode.h" #include "videoresolutionmodel.h" +#include "videoresolution.h" #include VideoSettings::VideoSettings(QObject *parent) : - QObject(parent), m_cam(0), m_settings(0), m_resolutions(0) { + QObject(parent), + m_cam(0), + m_settings(0), + m_resolutions(0), + m_currentResolution(0) { } VideoSettings::~VideoSettings() { m_settings = 0; + + if (m_currentResolution) { + delete m_currentResolution; + m_currentResolution = 0; + } } QString VideoSettings::suffix() const { @@ -67,6 +77,11 @@ void VideoSettings::setCamera(Camera *camera) { if (m_cam->device()) { deviceChanged(); } + else { + delete m_currentResolution; + m_currentResolution = 0; + emit currentResolutionChanged(); + } } void VideoSettings::deviceChanged() { @@ -79,8 +94,12 @@ void VideoSettings::deviceChanged() { delete m_resolutions; m_resolutions = 0; + delete m_currentResolution; + m_currentResolution = 0; + emit aspectRatioCountChanged(); emit resolutionsChanged(); + emit currentResolutionChanged(); } VideoResolutionModel *VideoSettings::resolutions() { @@ -108,7 +127,7 @@ bool VideoSettings::setResolution(const QString& aspectRatio, const QString& res foreach (const QtCamVideoResolution& r, res) { if (r.name() == resolution) { - return m_cam->device()->videoMode()->setResolution(r); + return setResolution(r); } } @@ -118,3 +137,59 @@ bool VideoSettings::setResolution(const QString& aspectRatio, const QString& res int VideoSettings::aspectRatioCount() const { return aspectRatios().count(); } + +VideoResolution *VideoSettings::currentResolution() { + if (m_currentResolution) { + return m_currentResolution; + } + + if (!m_cam || !m_cam->device()) { + return 0; + } + + m_currentResolution = new VideoResolution(m_cam->device()->videoMode()->currentResolution()); + + return m_currentResolution; +} + +VideoResolution *VideoSettings::findResolution(const QString& aspectRatio, + const QString& name) { + if (!isReady()) { + return 0; + } + + QList res = m_settings->resolutions(aspectRatio); + + foreach (const QtCamVideoResolution& r, res) { + if (r.name() == name) { + return new VideoResolution(r); + } + } + + return 0; +} + +bool VideoSettings::setResolution(VideoResolution *resolution) { + return setResolution(resolution->resolution()); +} + +bool VideoSettings::setResolution(const QtCamVideoResolution& resolution) { + if (!isReady()) { + return false; + } + + if (!m_cam || !m_cam->device()) { + return false; + } + + if (m_cam->device()->videoMode()->setResolution(resolution)) { + delete m_currentResolution; + m_currentResolution = 0; + + emit currentResolutionChanged(); + + return true; + } + + return false; +} diff --git a/declarative/videosettings.h b/declarative/videosettings.h index aa7b6f4..da4cf30 100644 --- a/declarative/videosettings.h +++ b/declarative/videosettings.h @@ -29,6 +29,8 @@ class Camera; class QtCamVideoSettings; class VideoResolutionModel; +class VideoResolution; +class QtCamVideoResolution; class VideoSettings : public QObject { Q_OBJECT @@ -39,6 +41,7 @@ class VideoSettings : public QObject { Q_PROPERTY(int aspectRatioCount READ aspectRatioCount NOTIFY aspectRatioCountChanged); Q_PROPERTY(VideoResolutionModel *resolutions READ resolutions NOTIFY resolutionsChanged); Q_PROPERTY(bool ready READ isReady NOTIFY readyChanged); + Q_PROPERTY(VideoResolution *currentResolution READ currentResolution NOTIFY currentResolutionChanged); public: VideoSettings(QObject *parent = 0); @@ -54,6 +57,12 @@ public: bool isReady() const; + VideoResolution *currentResolution(); + + Q_INVOKABLE VideoResolution *findResolution(const QString& aspectRatio, + const QString& name); + Q_INVOKABLE bool setResolution(VideoResolution *resolution); + Q_INVOKABLE bool setResolution(const QString& aspectRatio, const QString& resolution); int aspectRatioCount() const; @@ -64,14 +73,18 @@ signals: void resolutionsChanged(); void readyChanged(); void aspectRatioCountChanged(); + void currentResolutionChanged(); private slots: void deviceChanged(); private: + bool setResolution(const QtCamVideoResolution& resolution); + Camera *m_cam; QtCamVideoSettings *m_settings; VideoResolutionModel *m_resolutions; + VideoResolution *m_currentResolution; }; #endif /* VIDEO_SETTINGS_H */