From 630af723f5fd69a35614d48769502081ed801b43 Mon Sep 17 00:00:00 2001 From: Mohammed Sameer Date: Sat, 22 Sep 2012 23:45:28 +0300 Subject: [PATCH] Settings for aspect ration and resolution can now read from and save to the configuration --- imports/imageresolutionmodel.cpp | 107 +++++++++++++++++++++++++++++++ imports/imageresolutionmodel.h | 70 ++++++++++++++++++++ imports/imagesettings.cpp | 94 +++++++++++++++++++++++++++ imports/imagesettings.h | 67 +++++++++++++++++++ imports/imports.pro | 4 +- imports/mode.h | 4 +- imports/plugin.cpp | 5 ++ lib/qtcamimagesettings.cpp | 3 +- lib/qtcamvideosettings.cpp | 2 +- qml/ImageSettingsPage.qml | 48 +++++++++++--- qml/main.qml | 5 ++ src/settings.cpp | 44 ++++++++++--- src/settings.h | 11 ++++ 13 files changed, 439 insertions(+), 25 deletions(-) create mode 100644 imports/imageresolutionmodel.cpp create mode 100644 imports/imageresolutionmodel.h create mode 100644 imports/imagesettings.cpp create mode 100644 imports/imagesettings.h diff --git a/imports/imageresolutionmodel.cpp b/imports/imageresolutionmodel.cpp new file mode 100644 index 0000000..fde1448 --- /dev/null +++ b/imports/imageresolutionmodel.cpp @@ -0,0 +1,107 @@ +/*! + * 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 "imageresolutionmodel.h" +#include "qtcamimagesettings.h" +#include + +ImageResolutionModel::ImageResolutionModel(QtCamImageSettings *settings, QObject *parent) : + QAbstractListModel(parent), m_settings(settings) { + + QHash 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 index 0000000..2bfbad3 --- /dev/null +++ b/imports/imageresolutionmodel.h @@ -0,0 +1,70 @@ +// -*- c++ -*- + +/*! + * 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 + */ + +#ifndef IMAGE_RESOLUTION_MODEL_H +#define IMAGE_RESOLUTION_MODEL_H + +#include + +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 m_resolutions; +}; + +#endif /* IMAGE_RESOLUTION_MODEL_H */ diff --git a/imports/imagesettings.cpp b/imports/imagesettings.cpp new file mode 100644 index 0000000..4b69ce8 --- /dev/null +++ b/imports/imagesettings.cpp @@ -0,0 +1,94 @@ +/*! + * 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 "imagesettings.h" +#include "qtcamimagesettings.h" +#include "camera.h" +#include "qtcamdevice.h" +#include "qtcamimagemode.h" +#include "imageresolutionmodel.h" +#include + +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 index 0000000..7efdc7f --- /dev/null +++ b/imports/imagesettings.h @@ -0,0 +1,67 @@ +// -*- c++ -*- + +/*! + * 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 + */ + +#ifndef IMAGE_SETTINGS_H +#define IMAGE_SETTINGS_H + +#include +#include + +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 */ diff --git a/imports/imports.pro b/imports/imports.pro index 8b190d3..4a366b7 100644 --- a/imports/imports.pro +++ b/imports/imports.pro @@ -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 diff --git a/imports/mode.h b/imports/mode.h index d2032d0..790be38 100644 --- a/imports/mode.h +++ b/imports/mode.h @@ -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; }; diff --git a/imports/plugin.cpp b/imports/plugin.cpp index 10c6908..e7a30d9 100644 --- a/imports/plugin.cpp +++ b/imports/plugin.cpp @@ -38,6 +38,8 @@ #include "flickerreduction.h" #include "mute.h" #include "metadata.h" +#include "imagesettings.h" +#include "imageresolutionmodel.h" #include @@ -63,7 +65,10 @@ void Plugin::registerTypes(QDeclarativeEngine *engine) { qmlRegisterType(URI, MAJOR, MINOR, "FlickerReduction"); qmlRegisterType(URI, MAJOR, MINOR, "Mute"); qmlRegisterType(URI, MAJOR, MINOR, "MetaData"); + qmlRegisterType(URI, MAJOR, MINOR, "ImageSettings"); + qmlRegisterUncreatableType(URI, MAJOR, MINOR, "ImageResolutionModel", + "ImageResolutionModel can be obtained from ImageSettings"); qmlRegisterType(); qmlRegisterType(); diff --git a/lib/qtcamimagesettings.cpp b/lib/qtcamimagesettings.cpp index 1f95296..6f38d3b 100644 --- a/lib/qtcamimagesettings.cpp +++ b/lib/qtcamimagesettings.cpp @@ -20,6 +20,7 @@ #include "qtcamimagesettings.h" #include +#include class QtCamImageResolutionPrivate : public QSharedData { public: @@ -181,7 +182,7 @@ QList QtCamImageSettings::resolutions(const QString& aspec } } - return d_ptr->resolutions; + return res; } QStringList QtCamImageSettings::aspectRatios() const { diff --git a/lib/qtcamvideosettings.cpp b/lib/qtcamvideosettings.cpp index 5383c41..f79b8b4 100644 --- a/lib/qtcamvideosettings.cpp +++ b/lib/qtcamvideosettings.cpp @@ -175,7 +175,7 @@ QList QtCamVideoSettings::resolutions(const QString& aspec } } - return d_ptr->resolutions; + return res; } QStringList QtCamVideoSettings::aspectRatios() const { diff --git a/qml/ImageSettingsPage.qml b/qml/ImageSettingsPage.qml index acad3a3..31f782a 100644 --- a/qml/ImageSettingsPage.qml +++ b/qml/ImageSettingsPage.qml @@ -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 { diff --git a/qml/main.qml b/qml/main.qml index ceda507..4c4df1f 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -163,6 +163,11 @@ PageStackWindow { background: " " } + ImageSettings { + id: imageSettings + camera: cam + } + Camera { /* onDeviceIdChanged: { diff --git a/src/settings.cpp b/src/settings.cpp index 4a4acf5..9eb2b49 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -24,16 +24,18 @@ #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(); + } +} diff --git a/src/settings.h b/src/settings.h index 23a023a..15f3663 100644 --- a/src/settings.h +++ b/src/settings.h @@ -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; -- 2.25.1