Reworked how resolution is being specified in the configuration.
[harmattan/cameraplus] / lib / qtcamimagesettings.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 "qtcamimagesettings.h"
22 #include <QSharedData>
23
24 class QtCamImageResolutionPrivate : public QSharedData {
25 public:
26   QString id;
27   QString name;
28   QSize capture;
29   QSize preview;
30   QSize viewfinder;
31   int fps;
32   int nightFps;
33   int megaPixels;
34   QString aspectRatio;
35 };
36
37 class QtCamImageSettingsPrivate : public QSharedData {
38 public:
39   QString id;
40   QString suffix;
41   QString profileName;
42   QString profilePath;
43   QList<QtCamImageResolution> resolutions;
44 };
45
46
47 QtCamImageResolution::QtCamImageResolution(const QString& id, const QString& name,
48                                            const QSize& capture, const QSize& preview,
49                                            const QSize& viewfinder, int fps, int nightFps,
50                                            int megaPixels, QString aspectRatio) :
51   d_ptr(new QtCamImageResolutionPrivate) {
52   d_ptr->id = id;
53   d_ptr->name = name;
54   d_ptr->capture = capture;
55   d_ptr->preview = preview;
56   d_ptr->viewfinder = viewfinder;
57   d_ptr->fps = fps;
58   d_ptr->nightFps = nightFps;
59   d_ptr->megaPixels = megaPixels;
60   d_ptr->aspectRatio = aspectRatio;
61 }
62
63 QtCamImageResolution::QtCamImageResolution(const QtCamImageResolution& other) :
64   d_ptr(other.d_ptr) {
65
66 }
67
68 QtCamImageResolution& QtCamImageResolution::operator=(const QtCamImageResolution& other) {
69   d_ptr = other.d_ptr;
70
71   return *this;
72 }
73
74 QtCamImageResolution::~QtCamImageResolution() {
75   // QSharedData will take care of reference counting.
76 }
77
78 QString QtCamImageResolution::id() const {
79   return d_ptr->id;
80 }
81
82 QString QtCamImageResolution::name() const {
83   return d_ptr->name;
84 }
85
86 QSize QtCamImageResolution::captureResolution() const {
87   return d_ptr->capture;
88 }
89
90 QSize QtCamImageResolution::viewfinderResolution() const {
91   return d_ptr->viewfinder;
92 }
93
94 QSize QtCamImageResolution::previewResolution() const {
95   return d_ptr->preview;
96 }
97
98 int QtCamImageResolution::frameRate() const {
99   return d_ptr->fps;
100 }
101
102 int QtCamImageResolution::nightFrameRate() const {
103   return d_ptr->nightFps;
104 }
105
106 int QtCamImageResolution::megaPixels() const {
107   return d_ptr->megaPixels;
108 }
109
110 QString QtCamImageResolution::aspectRatio() const {
111   return d_ptr->aspectRatio;
112 }
113
114 QtCamImageSettings::QtCamImageSettings(const QString& id, const QString& suffix,
115                                        const QString& profileName, const QString& profilePath,
116                                        const QList<QtCamImageResolution>& resolutions) :
117   d_ptr(new QtCamImageSettingsPrivate) {
118
119   d_ptr->id = id;
120   d_ptr->suffix = suffix;
121   d_ptr->profileName = profileName;
122   d_ptr->profilePath = profilePath;
123   d_ptr->resolutions = resolutions;
124 }
125
126 QtCamImageSettings::QtCamImageSettings(const QtCamImageSettings& other) :
127   d_ptr(other.d_ptr) {
128
129 }
130
131 QtCamImageSettings& QtCamImageSettings::operator=(const QtCamImageSettings& other) {
132   d_ptr = other.d_ptr;
133
134   return *this;
135 }
136
137 QtCamImageSettings::~QtCamImageSettings() {
138   // QSharedData will take care of reference counting.
139 }
140
141 QString QtCamImageSettings::id() const {
142   return d_ptr->id;
143 }
144
145 QString QtCamImageSettings::suffix() const {
146   return d_ptr->suffix;
147 }
148
149 QString QtCamImageSettings::profileName() const {
150   return d_ptr->profileName;
151 }
152
153 QString QtCamImageSettings::profilePath() const {
154   return d_ptr->profilePath;
155 }
156
157 QtCamImageResolution QtCamImageSettings::defaultResolution(const QString& aspectRatio) const {
158   if (aspectRatio.isEmpty()) {
159     return d_ptr->resolutions[0];
160   }
161
162   foreach (const QtCamImageResolution& r, d_ptr->resolutions) {
163     if (r.aspectRatio() == aspectRatio) {
164       return r;
165     }
166   }
167
168   return d_ptr->resolutions[0];
169 }
170
171 QList<QtCamImageResolution> QtCamImageSettings::resolutions(const QString& aspectRatio) const {
172   if (aspectRatio.isEmpty()) {
173     return d_ptr->resolutions;
174   }
175
176   QList<QtCamImageResolution> res;
177
178   foreach (const QtCamImageResolution& r, d_ptr->resolutions) {
179     if (r.aspectRatio() == aspectRatio) {
180       res << r;
181     }
182   }
183
184   return d_ptr->resolutions;
185 }
186
187 QStringList QtCamImageSettings::aspectRatios() const {
188   QStringList aspects;
189
190   foreach (const QtCamImageResolution& r, d_ptr->resolutions) {
191     if (aspects.indexOf(r.aspectRatio()) == -1) {
192       aspects << r.aspectRatio();
193     }
194   }
195
196   return aspects;
197 }