c05ec754450dabffcca1c2661c0a782ca6f85129
[harmattan/cameraplus] / lib / qtcamvideosettings.cpp
1 /*!
2  * This file is part of CameraPlus.
3  *
4  * Copyright (C) 2012-2013 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 (d_ptr->resolutions.isEmpty()) {
153     return QtCamVideoResolution(QString(), QString(), QSize(), QSize(),
154                                 -1, -1, QString(), QString());
155   }
156
157   if (aspectRatio.isEmpty()) {
158     return d_ptr->resolutions[0];
159   }
160
161   foreach (const QtCamVideoResolution& r, d_ptr->resolutions) {
162     if (r.aspectRatio() == aspectRatio) {
163       return r;
164     }
165   }
166
167   return d_ptr->resolutions[0];
168 }
169
170 QList<QtCamVideoResolution> QtCamVideoSettings::resolutions(const QString& aspectRatio) const {
171   if (aspectRatio.isEmpty()) {
172     return d_ptr->resolutions;
173   }
174
175   QList<QtCamVideoResolution> res;
176
177   foreach (const QtCamVideoResolution& r, d_ptr->resolutions) {
178     if (r.aspectRatio() == aspectRatio) {
179       res << r;
180     }
181   }
182
183   return res;
184 }
185
186 QStringList QtCamVideoSettings::aspectRatios() const {
187   QStringList aspects;
188
189   foreach (const QtCamVideoResolution& r, d_ptr->resolutions) {
190     if (aspects.indexOf(r.aspectRatio()) == -1) {
191       aspects << r.aspectRatio();
192     }
193   }
194
195   return aspects;
196 }