Settings for aspect ration and resolution can now read from and save to the configuration
authorMohammed Sameer <msameer@foolab.org>
Sat, 22 Sep 2012 20:45:28 +0000 (23:45 +0300)
committerMohammed Sameer <msameer@foolab.org>
Sat, 22 Sep 2012 20:45:28 +0000 (23:45 +0300)
13 files changed:
imports/imageresolutionmodel.cpp [new file with mode: 0644]
imports/imageresolutionmodel.h [new file with mode: 0644]
imports/imagesettings.cpp [new file with mode: 0644]
imports/imagesettings.h [new file with mode: 0644]
imports/imports.pro
imports/mode.h
imports/plugin.cpp
lib/qtcamimagesettings.cpp
lib/qtcamvideosettings.cpp
qml/ImageSettingsPage.qml
qml/main.qml
src/settings.cpp
src/settings.h

diff --git a/imports/imageresolutionmodel.cpp b/imports/imageresolutionmodel.cpp
new file mode 100644 (file)
index 0000000..fde1448
--- /dev/null
@@ -0,0 +1,107 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * 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 "imageresolutionmodel.h"
+#include "qtcamimagesettings.h"
+#include <QDebug>
+
+ImageResolutionModel::ImageResolutionModel(QtCamImageSettings *settings, QObject *parent) :
+  QAbstractListModel(parent), m_settings(settings) {
+
+  QHash<int, QByteArray> roles;
+  roles[IdRole] = "resolutionId";
+  roles[NameRole] = "resolutionName";
+  roles[CaptureRole] = "captureResolution";
+  roles[PreviewRole] = "previewResolution";
+  roles[FpsRole] = "frameRate";
+  roles[NightFpsRole] = "nightFrameRate";
+  roles[MegaPixelsRole] = "megaPixels";
+  roles[AspectRatioRole] = "resolutionAspectRatio";
+
+  setRoleNames(roles);
+}
+
+ImageResolutionModel::~ImageResolutionModel() {
+  m_settings = 0;
+}
+
+int ImageResolutionModel::rowCount(const QModelIndex& parent) const {
+  if (!parent.isValid()) {
+    return m_resolutions.size();
+  }
+
+  return 0;
+}
+
+QVariant ImageResolutionModel::data(const QModelIndex& index, int role) const {
+  if (index.row() < 0 || index.row() > m_resolutions.size()) {
+    return QVariant();
+  }
+
+  const QtCamImageResolution& res = m_resolutions[index.row()];
+
+  switch (role) {
+  case IdRole:
+    return res.id();
+
+  case NameRole:
+    return res.name();
+
+  case CaptureRole:
+    return res.captureResolution();
+
+  case PreviewRole:
+    return res.previewResolution();
+
+  case FpsRole:
+    return res.frameRate();
+
+  case NightFpsRole:
+    return res.nightFrameRate();
+
+  case MegaPixelsRole:
+    return res.megaPixels();
+
+  case AspectRatioRole:
+    return res.aspectRatio();
+
+  default:
+    return QVariant();
+  }
+}
+
+QString ImageResolutionModel::aspectRatio() const {
+  return m_aspectRatio;
+}
+
+void ImageResolutionModel::setAspectRatio(const QString& aspectRatio) {
+  if (aspectRatio != m_aspectRatio) {
+
+    m_aspectRatio = aspectRatio;
+
+    emit aspectRatioChanged();
+
+    beginResetModel();
+
+    m_resolutions = m_settings->resolutions(m_aspectRatio);
+
+    endResetModel();
+  }
+}
diff --git a/imports/imageresolutionmodel.h b/imports/imageresolutionmodel.h
new file mode 100644 (file)
index 0000000..2bfbad3
--- /dev/null
@@ -0,0 +1,70 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * 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
+ */
+
+#ifndef IMAGE_RESOLUTION_MODEL_H
+#define IMAGE_RESOLUTION_MODEL_H
+
+#include <QAbstractListModel>
+
+class QtCamImageSettings;
+class QtCamImageResolution;
+
+class ImageResolutionModel : public QAbstractListModel {
+  Q_OBJECT
+
+  Q_PROPERTY(QString aspectRatio READ aspectRatio WRITE setAspectRatio NOTIFY aspectRatioChanged);
+
+public:
+
+  enum ResolutionRoles {
+    IdRole = Qt::UserRole + 1,
+    NameRole,
+    CaptureRole,
+    PreviewRole,
+    FpsRole,
+    NightFpsRole,
+    MegaPixelsRole,
+    AspectRatioRole,
+  };
+
+  ImageResolutionModel(QtCamImageSettings *settings, QObject *parent = 0);
+  ~ImageResolutionModel();
+
+  int rowCount(const QModelIndex& parent = QModelIndex()) const;
+
+  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+
+  QString aspectRatio() const;
+  void setAspectRatio(const QString& aspectRatio);
+
+signals:
+  void aspectRatioChanged();
+
+private:
+  QString m_aspectRatio;
+
+  QtCamImageSettings *m_settings;
+
+  QList<QtCamImageResolution> m_resolutions;
+};
+
+#endif /* IMAGE_RESOLUTION_MODEL_H */
diff --git a/imports/imagesettings.cpp b/imports/imagesettings.cpp
new file mode 100644 (file)
index 0000000..4b69ce8
--- /dev/null
@@ -0,0 +1,94 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * 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 "imagesettings.h"
+#include "qtcamimagesettings.h"
+#include "camera.h"
+#include "qtcamdevice.h"
+#include "qtcamimagemode.h"
+#include "imageresolutionmodel.h"
+#include <QDebug>
+
+ImageSettings::ImageSettings(QObject *parent) :
+  QObject(parent), m_cam(0), m_settings(0), m_resolutions(0) {
+
+}
+
+ImageSettings::~ImageSettings() {
+  m_settings = 0;
+}
+
+QString ImageSettings::suffix() const {
+  return m_settings ? m_settings->suffix() : QString();
+}
+
+QStringList ImageSettings::aspectRatios() const {
+  return m_settings ? m_settings->aspectRatios() : QStringList();
+}
+
+Camera *ImageSettings::camera() {
+  return m_cam;
+}
+
+void ImageSettings::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();
+
+  if (m_cam->device()) {
+    deviceChanged();
+  }
+}
+
+void ImageSettings::deviceChanged() {
+  m_settings = m_cam->device()->imageMode()->settings();
+
+  emit settingsChanged();
+
+  delete m_resolutions;
+  m_resolutions = 0;
+
+  emit resolutionsChanged();
+}
+
+ImageResolutionModel *ImageSettings::resolutions() {
+  if (!m_settings) {
+    return 0;
+  }
+
+
+  if (!m_resolutions) {
+    m_resolutions = new ImageResolutionModel(m_settings, this);
+  }
+
+  return m_resolutions;
+}
diff --git a/imports/imagesettings.h b/imports/imagesettings.h
new file mode 100644 (file)
index 0000000..7efdc7f
--- /dev/null
@@ -0,0 +1,67 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * 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
+ */
+
+#ifndef IMAGE_SETTINGS_H
+#define IMAGE_SETTINGS_H
+
+#include <QObject>
+#include <QStringList>
+
+class Camera;
+class QtCamImageSettings;
+class ImageResolutionModel;
+
+class ImageSettings : public QObject {
+  Q_OBJECT
+
+  Q_PROPERTY(Camera* camera READ camera WRITE setCamera NOTIFY cameraChanged);
+  Q_PROPERTY(QString suffix READ suffix NOTIFY settingsChanged);
+  Q_PROPERTY(QStringList aspectRatios READ aspectRatios NOTIFY settingsChanged);
+  Q_PROPERTY(ImageResolutionModel *resolutions READ resolutions NOTIFY resolutionsChanged);
+
+public:
+  ImageSettings(QObject *parent = 0);
+  ~ImageSettings();
+
+  QString suffix() const;
+  QStringList aspectRatios() const;
+
+  Camera *camera();
+  void setCamera(Camera *camera);
+
+  ImageResolutionModel *resolutions();
+
+signals:
+  void settingsChanged();
+  void cameraChanged();
+  void resolutionsChanged();
+
+private slots:
+  void deviceChanged();
+
+private:
+  Camera *m_cam;
+  QtCamImageSettings *m_settings;
+  ImageResolutionModel *m_resolutions;
+};
+
+#endif /* IMAGE_SETTINGS_H */
index 8b190d3..4a366b7 100644 (file)
@@ -13,9 +13,9 @@ QT += declarative
 HEADERS += plugin.h previewprovider.h camera.h mode.h imagemode.h videomode.h \
            capability.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
+           flickerreduction.h mute.h metadata.h imagesettings.h imageresolutionmodel.h
 
 SOURCES += plugin.cpp previewprovider.cpp camera.cpp mode.cpp imagemode.cpp videomode.cpp \
            capability.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
+           flickerreduction.cpp mute.cpp metadata.cpp imagesettings.cpp imageresolutionmodel.cpp
index d2032d0..790be38 100644 (file)
@@ -60,6 +60,7 @@ signals:
 
 private slots:
   void gotPreview(const QImage& image, const QString& fileName);
+  void deviceChanged();
 
 protected:
   virtual void preChangeMode() = 0;
@@ -69,9 +70,6 @@ protected:
   Camera *m_cam;
   QtCamMode *m_mode;
 
-private slots:
-  void deviceChanged();
-
 private:
   unsigned long long m_seq;
 };
index 10c6908..e7a30d9 100644 (file)
@@ -38,6 +38,8 @@
 #include "flickerreduction.h"
 #include "mute.h"
 #include "metadata.h"
+#include "imagesettings.h"
+#include "imageresolutionmodel.h"
 
 #include <QtDeclarative>
 
@@ -63,7 +65,10 @@ void Plugin::registerTypes(QDeclarativeEngine *engine) {
   qmlRegisterType<FlickerReduction>(URI, MAJOR, MINOR, "FlickerReduction");
   qmlRegisterType<Mute>(URI, MAJOR, MINOR, "Mute");
   qmlRegisterType<MetaData>(URI, MAJOR, MINOR, "MetaData");
+  qmlRegisterType<ImageSettings>(URI, MAJOR, MINOR, "ImageSettings");
 
+  qmlRegisterUncreatableType<ImageResolutionModel>(URI, MAJOR, MINOR, "ImageResolutionModel",
+                         "ImageResolutionModel can be obtained from ImageSettings");
   qmlRegisterType<Mode>();
   qmlRegisterType<Capability>();
 
index 1f95296..6f38d3b 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "qtcamimagesettings.h"
 #include <QSharedData>
+#include <QDebug>
 
 class QtCamImageResolutionPrivate : public QSharedData {
 public:
@@ -181,7 +182,7 @@ QList<QtCamImageResolution> QtCamImageSettings::resolutions(const QString& aspec
     }
   }
 
-  return d_ptr->resolutions;
+  return res;
 }
 
 QStringList QtCamImageSettings::aspectRatios() const {
index 5383c41..f79b8b4 100644 (file)
@@ -175,7 +175,7 @@ QList<QtCamVideoResolution> QtCamVideoSettings::resolutions(const QString& aspec
     }
   }
 
-  return d_ptr->resolutions;
+  return res;
 }
 
 QStringList QtCamVideoSettings::aspectRatios() const {
index acad3a3..31f782a 100644 (file)
@@ -146,10 +146,26 @@ CameraPage {
 
                         ButtonRow {
                                 anchors.horizontalCenter: parent.horizontalCenter
-                                // TODO:
-                                Button { text: qsTr("16:9"); }
-                                Button { text: qsTr("4:3"); }
-                                Button { text: qsTr("3:2"); }
+                                exclusive: false
+                                onCheckedButtonChanged: {
+                                        // This is needed to initially setup the
+                                        // resolutions buttons
+                                        imageSettings.resolutions.aspectRatio = checkedButton.aspect;
+                                        settings.imageAspectRatio = imageSettings.resolutions.aspectRatio;
+                                }
+
+                                Repeater {
+                                        model: imageSettings.aspectRatios
+                                        delegate: Button {
+                                                property string aspect: modelData;
+                                                text: qsTr(modelData);
+                                                checked: settings.imageAspectRatio == modelData;
+                                                onClicked: {
+                                                        settings.imageAspectRatio = modelData;
+                                                        imageSettings.resolutions.aspectRatio = modelData;
+                                                }
+                                        }
+                                }
                         }
 
                         SectionHeader {
@@ -157,11 +173,27 @@ CameraPage {
                         }
 
                         ButtonRow {
+                                id: resolutionsRow
                                 anchors.horizontalCenter: parent.horizontalCenter
-                                // TODO:
-                                Button {}
-                                Button {}
-                                Button {}
+                                exclusive: false
+
+                                Repeater {
+                                        id: resolutions
+                                        model: imageSettings.resolutions
+
+                                        // http://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript
+                                        function name(name, mp) {
+                                                return name.charAt(0).toUpperCase() + name.slice(1) + " " + mp + " Mpx";
+                                        }
+
+                                        delegate: Button {
+                                                property string resolution: resolutionName
+                                                property string aspectRatio: resolutionAspectRatio
+                                                text: resolutions.name(resolutionName, megaPixels);
+                                                checked: settings.imageResolution == resolutionName
+                                                onClicked: settings.imageResolution = resolutionName;
+                                        }
+                                }
                         }
 
                         CameraSettings {
index ceda507..4c4df1f 100644 (file)
@@ -163,6 +163,11 @@ PageStackWindow {
                 background: " "
         }
 
+        ImageSettings {
+                id: imageSettings
+                camera: cam
+        }
+
         Camera {
 /*
                 onDeviceIdChanged: {
index 4a4acf5..9eb2b49 100644 (file)
 
 #define PATH QString("%1%2.config%2/cameraplus.conf").arg(QDir::homePath()).arg(QDir::separator())
 
-#define DEFAULT_MODE          0
-#define DEFAULT_SCENE_MODE    6 // Auto
-#define DEFAULT_TIMEOUT       0
-#define DEFAULT_USE_GPS       true
-#define DEFAULT_USE_GEOTAGS   true
-#define DEFAULT_COLOR_FILTER  0
-#define DEFAULT_WHITE_BALANCE 0
-#define DEFAULT_EV_COMP       0.0
-#define DEFAULT_FLASH_MODE    0
-#define DEFAULT_IMAGE_ISO     0
+#define DEFAULT_MODE               0
+#define DEFAULT_SCENE_MODE         6 // Auto
+#define DEFAULT_TIMEOUT            0
+#define DEFAULT_USE_GPS            true
+#define DEFAULT_USE_GEOTAGS        true
+#define DEFAULT_COLOR_FILTER       0
+#define DEFAULT_WHITE_BALANCE      0
+#define DEFAULT_EV_COMP            0.0
+#define DEFAULT_FLASH_MODE         0
+#define DEFAULT_IMAGE_ISO          0
+#define DEFAULT_IMAGE_RESOLUTION   "high"
+#define DEFAULT_IMAGE_ASPECT_RATIO "16:9"
 
 Settings::Settings(QObject *parent) :
   QObject(parent),
@@ -223,3 +225,25 @@ void Settings::setImageIso(int iso) {
     emit imageIsoChanged();
   }
 }
+
+QString Settings::imageAspectRatio() const {
+  return m_settings->value("image/aspectRatio", DEFAULT_IMAGE_ASPECT_RATIO).toString();
+}
+
+void Settings::setImageAspectRatio(const QString& aspectRatio) {
+  if (aspectRatio != imageAspectRatio()) {
+    m_settings->setValue("image/aspectRatio", aspectRatio);
+    emit imageAspectRatioChanged();
+  }
+}
+
+QString Settings::imageResolution() const {
+  return m_settings->value("image/resolution", DEFAULT_IMAGE_RESOLUTION).toString();
+}
+
+void Settings::setImageResolution(const QString& resolution) {
+  if (resolution != imageResolution()) {
+    m_settings->setValue("image/resolution", resolution);
+    emit imageResolutionChanged();
+  }
+}
index 23a023a..15f3663 100644 (file)
@@ -48,6 +48,9 @@ class Settings : public QObject {
   Q_PROPERTY(int imageFlashMode READ imageFlashMode WRITE setImageFlashMode NOTIFY imageFlashModeChanged);
   Q_PROPERTY(int imageIso READ imageIso WRITE setImageIso NOTIFY imageIsoChanged);
 
+  Q_PROPERTY(QString imageAspectRatio READ imageAspectRatio WRITE setImageAspectRatio NOTIFY imageAspectRatioChanged);
+  Q_PROPERTY(QString imageResolution READ imageResolution WRITE setImageResolution NOTIFY imageResolutionChanged);
+
 public:
   Settings(QObject *parent = 0);
   ~Settings();
@@ -97,6 +100,12 @@ public:
   int imageIso() const;
   void setImageIso(int iso);
 
+  QString imageAspectRatio() const;
+  void setImageAspectRatio(const QString& aspectRatio);
+
+  QString imageResolution() const;
+  void setImageResolution(const QString& resolution);
+
 signals:
   void modeChanged();
   void creatorNameChanged();
@@ -113,6 +122,8 @@ signals:
   void videoEvCompChanged();
   void imageFlashModeChanged();
   void imageIsoChanged();
+  void imageAspectRatioChanged();
+  void imageResolutionChanged();
 
 private:
   QSettings *m_settings;