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