Settings for aspect ration and resolution can now read from and save to the configuration
[harmattan/cameraplus] / imports / imageresolutionmodel.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21 #include "imageresolutionmodel.h"
22 #include "qtcamimagesettings.h"
23 #include <QDebug>
24
25 ImageResolutionModel::ImageResolutionModel(QtCamImageSettings *settings, QObject *parent) :
26   QAbstractListModel(parent), m_settings(settings) {
27
28   QHash<int, QByteArray> roles;
29   roles[IdRole] = "resolutionId";
30   roles[NameRole] = "resolutionName";
31   roles[CaptureRole] = "captureResolution";
32   roles[PreviewRole] = "previewResolution";
33   roles[FpsRole] = "frameRate";
34   roles[NightFpsRole] = "nightFrameRate";
35   roles[MegaPixelsRole] = "megaPixels";
36   roles[AspectRatioRole] = "resolutionAspectRatio";
37
38   setRoleNames(roles);
39 }
40
41 ImageResolutionModel::~ImageResolutionModel() {
42   m_settings = 0;
43 }
44
45 int ImageResolutionModel::rowCount(const QModelIndex& parent) const {
46   if (!parent.isValid()) {
47     return m_resolutions.size();
48   }
49
50   return 0;
51 }
52
53 QVariant ImageResolutionModel::data(const QModelIndex& index, int role) const {
54   if (index.row() < 0 || index.row() > m_resolutions.size()) {
55     return QVariant();
56   }
57
58   const QtCamImageResolution& res = m_resolutions[index.row()];
59
60   switch (role) {
61   case IdRole:
62     return res.id();
63
64   case NameRole:
65     return res.name();
66
67   case CaptureRole:
68     return res.captureResolution();
69
70   case PreviewRole:
71     return res.previewResolution();
72
73   case FpsRole:
74     return res.frameRate();
75
76   case NightFpsRole:
77     return res.nightFrameRate();
78
79   case MegaPixelsRole:
80     return res.megaPixels();
81
82   case AspectRatioRole:
83     return res.aspectRatio();
84
85   default:
86     return QVariant();
87   }
88 }
89
90 QString ImageResolutionModel::aspectRatio() const {
91   return m_aspectRatio;
92 }
93
94 void ImageResolutionModel::setAspectRatio(const QString& aspectRatio) {
95   if (aspectRatio != m_aspectRatio) {
96
97     m_aspectRatio = aspectRatio;
98
99     emit aspectRatioChanged();
100
101     beginResetModel();
102
103     m_resolutions = m_settings->resolutions(m_aspectRatio);
104
105     endResetModel();
106   }
107 }