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