Added methods to find VideoResolution and set it
authorMohammed Sameer <msameer@foolab.org>
Tue, 13 Aug 2013 18:19:47 +0000 (21:19 +0300)
committerMohammed Sameer <msameer@foolab.org>
Tue, 13 Aug 2013 18:19:47 +0000 (21:19 +0300)
declarative/videosettings.cpp
declarative/videosettings.h

index ec29a7a..0a8f517 100644 (file)
 #include "qtcamdevice.h"
 #include "qtcamvideomode.h"
 #include "videoresolutionmodel.h"
 #include "qtcamdevice.h"
 #include "qtcamvideomode.h"
 #include "videoresolutionmodel.h"
+#include "videoresolution.h"
 #include <QDebug>
 
 VideoSettings::VideoSettings(QObject *parent) :
 #include <QDebug>
 
 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;
 
 }
 
 VideoSettings::~VideoSettings() {
   m_settings = 0;
+
+  if (m_currentResolution) {
+    delete m_currentResolution;
+    m_currentResolution = 0;
+  }
 }
 
 QString VideoSettings::suffix() const {
 }
 
 QString VideoSettings::suffix() const {
@@ -67,6 +77,11 @@ void VideoSettings::setCamera(Camera *camera) {
   if (m_cam->device()) {
     deviceChanged();
   }
   if (m_cam->device()) {
     deviceChanged();
   }
+  else {
+    delete m_currentResolution;
+    m_currentResolution = 0;
+    emit currentResolutionChanged();
+  }
 }
 
 void VideoSettings::deviceChanged() {
 }
 
 void VideoSettings::deviceChanged() {
@@ -79,8 +94,12 @@ void VideoSettings::deviceChanged() {
   delete m_resolutions;
   m_resolutions = 0;
 
   delete m_resolutions;
   m_resolutions = 0;
 
+  delete m_currentResolution;
+  m_currentResolution = 0;
+
   emit aspectRatioCountChanged();
   emit resolutionsChanged();
   emit aspectRatioCountChanged();
   emit resolutionsChanged();
+  emit currentResolutionChanged();
 }
 
 VideoResolutionModel *VideoSettings::resolutions() {
 }
 
 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) {
 
   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();
 }
 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<QtCamVideoResolution> 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;
+}
index aa7b6f4..da4cf30 100644 (file)
@@ -29,6 +29,8 @@
 class Camera;
 class QtCamVideoSettings;
 class VideoResolutionModel;
 class Camera;
 class QtCamVideoSettings;
 class VideoResolutionModel;
+class VideoResolution;
+class QtCamVideoResolution;
 
 class VideoSettings : public QObject {
   Q_OBJECT
 
 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(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);
 
 public:
   VideoSettings(QObject *parent = 0);
@@ -54,6 +57,12 @@ public:
 
   bool isReady() const;
 
 
   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;
   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 resolutionsChanged();
   void readyChanged();
   void aspectRatioCountChanged();
+  void currentResolutionChanged();
 
 private slots:
   void deviceChanged();
 
 private:
 
 private slots:
   void deviceChanged();
 
 private:
+  bool setResolution(const QtCamVideoResolution& resolution);
+
   Camera *m_cam;
   QtCamVideoSettings *m_settings;
   VideoResolutionModel *m_resolutions;
   Camera *m_cam;
   QtCamVideoSettings *m_settings;
   VideoResolutionModel *m_resolutions;
+  VideoResolution *m_currentResolution;
 };
 
 #endif /* VIDEO_SETTINGS_H */
 };
 
 #endif /* VIDEO_SETTINGS_H */