1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qcameraviewfindersettings.h" |
41 | |
42 | QT_BEGIN_NAMESPACE |
43 | |
44 | static void qRegisterViewfinderSettingsMetaType() |
45 | { |
46 | qRegisterMetaType<QCameraViewfinderSettings>(); |
47 | } |
48 | |
49 | Q_CONSTRUCTOR_FUNCTION(qRegisterViewfinderSettingsMetaType) |
50 | |
51 | |
52 | class QCameraViewfinderSettingsPrivate : public QSharedData |
53 | { |
54 | public: |
55 | QCameraViewfinderSettingsPrivate() : |
56 | isNull(true), |
57 | minimumFrameRate(0.0), |
58 | maximumFrameRate(0.0), |
59 | pixelFormat(QVideoFrame::Format_Invalid) |
60 | { |
61 | } |
62 | |
63 | QCameraViewfinderSettingsPrivate(const QCameraViewfinderSettingsPrivate &other): |
64 | QSharedData(other), |
65 | isNull(other.isNull), |
66 | resolution(other.resolution), |
67 | minimumFrameRate(other.minimumFrameRate), |
68 | maximumFrameRate(other.maximumFrameRate), |
69 | pixelFormat(other.pixelFormat), |
70 | pixelAspectRatio(other.pixelAspectRatio) |
71 | { |
72 | } |
73 | |
74 | bool isNull; |
75 | QSize resolution; |
76 | qreal minimumFrameRate; |
77 | qreal maximumFrameRate; |
78 | QVideoFrame::PixelFormat pixelFormat; |
79 | QSize pixelAspectRatio; |
80 | |
81 | private: |
82 | QCameraViewfinderSettingsPrivate& operator=(const QCameraViewfinderSettingsPrivate &other); |
83 | }; |
84 | |
85 | |
86 | /*! |
87 | \class QCameraViewfinderSettings |
88 | \since 5.5 |
89 | \brief The QCameraViewfinderSettings class provides a set of viewfinder settings. |
90 | |
91 | \inmodule QtMultimedia |
92 | \ingroup multimedia |
93 | \ingroup multimedia_camera |
94 | |
95 | A viewfinder settings object is used to specify the viewfinder settings used by QCamera. |
96 | Viewfinder settings are selected by constructing a QCameraViewfinderSettings object, |
97 | setting the desired properties and then passing it to a QCamera instance using the |
98 | QCamera::setViewfinderSettings() function. |
99 | |
100 | \snippet multimedia-snippets/camera.cpp Camera viewfinder settings |
101 | |
102 | Different cameras may have different capabilities. The application should query the camera |
103 | capabilities before setting parameters. For example, the application should call |
104 | QCamera::supportedViewfinderResolutions() before calling setResolution(). |
105 | |
106 | \sa QCamera |
107 | */ |
108 | |
109 | /*! |
110 | Constructs a null viewfinder settings object. |
111 | */ |
112 | QCameraViewfinderSettings::QCameraViewfinderSettings() |
113 | : d(new QCameraViewfinderSettingsPrivate) |
114 | { |
115 | } |
116 | |
117 | /*! |
118 | Constructs a copy of the viewfinder settings object \a other. |
119 | */ |
120 | QCameraViewfinderSettings::QCameraViewfinderSettings(const QCameraViewfinderSettings &other) |
121 | : d(other.d) |
122 | { |
123 | |
124 | } |
125 | |
126 | /*! |
127 | Destroys a viewfinder settings object. |
128 | */ |
129 | QCameraViewfinderSettings::~QCameraViewfinderSettings() |
130 | { |
131 | |
132 | } |
133 | |
134 | /*! |
135 | Assigns the value of \a other to a viewfinder settings object. |
136 | */ |
137 | QCameraViewfinderSettings &QCameraViewfinderSettings::operator=(const QCameraViewfinderSettings &other) |
138 | { |
139 | d = other.d; |
140 | return *this; |
141 | } |
142 | |
143 | /*! \fn QCameraViewfinderSettings &QCameraViewfinderSettings::operator=(QCameraViewfinderSettings &&other) |
144 | |
145 | Moves \a other to this viewfinder settings object and returns a reference to this object. |
146 | */ |
147 | |
148 | /*! |
149 | \fn void QCameraViewfinderSettings::swap(QCameraViewfinderSettings &other) |
150 | |
151 | Swaps this viewfinder settings object with \a other. This |
152 | function is very fast and never fails. |
153 | */ |
154 | |
155 | /*! |
156 | \relates QCameraViewfinderSettings |
157 | \since 5.5 |
158 | |
159 | Determines if \a lhs is of equal value to \a rhs. |
160 | |
161 | Returns true if the settings objects are of equal value, and false if they |
162 | are not of equal value. |
163 | */ |
164 | bool operator==(const QCameraViewfinderSettings &lhs, const QCameraViewfinderSettings &rhs) Q_DECL_NOTHROW |
165 | { |
166 | return (lhs.d == rhs.d) || |
167 | (lhs.d->isNull == rhs.d->isNull && |
168 | lhs.d->resolution == rhs.d->resolution && |
169 | lhs.d->minimumFrameRate == rhs.d->minimumFrameRate && |
170 | lhs.d->maximumFrameRate == rhs.d->maximumFrameRate && |
171 | lhs.d->pixelFormat == rhs.d->pixelFormat && |
172 | lhs.d->pixelAspectRatio == rhs.d->pixelAspectRatio); |
173 | } |
174 | |
175 | /*! |
176 | \fn bool operator!=(const QCameraViewfinderSettings &lhs, const QCameraViewfinderSettings &rhs) |
177 | \relates QCameraViewfinderSettings |
178 | \since 5.5 |
179 | |
180 | Determines if \a lhs is of equal value to \a rhs. |
181 | |
182 | Returns true if the settings objects are not of equal value, and false if |
183 | they are of equal value. |
184 | */ |
185 | |
186 | /*! |
187 | Identifies if a viewfinder settings object is uninitalized. |
188 | |
189 | Returns true if the settings are null, and false if they are not. |
190 | */ |
191 | bool QCameraViewfinderSettings::isNull() const |
192 | { |
193 | return d->isNull; |
194 | } |
195 | |
196 | /*! |
197 | Returns the viewfinder resolution. |
198 | */ |
199 | QSize QCameraViewfinderSettings::resolution() const |
200 | { |
201 | return d->resolution; |
202 | } |
203 | |
204 | /*! |
205 | Sets the viewfinder \a resolution. |
206 | |
207 | If the given \a resolution is empty, the backend makes an optimal choice based on the |
208 | supported resolutions and the other viewfinder settings. |
209 | |
210 | If the camera is used to capture videos or images, the viewfinder resolution might be |
211 | ignored if it conflicts with the capture resolution. |
212 | |
213 | \sa QVideoEncoderSettings::setResolution(), QImageEncoderSettings::setResolution(), |
214 | QCamera::supportedViewfinderResolutions() |
215 | */ |
216 | void QCameraViewfinderSettings::setResolution(const QSize &resolution) |
217 | { |
218 | d->isNull = false; |
219 | d->resolution = resolution; |
220 | } |
221 | |
222 | /*! |
223 | \fn QCameraViewfinderSettings::setResolution(int width, int height) |
224 | |
225 | This is an overloaded function. |
226 | |
227 | Sets the \a width and \a height of the viewfinder resolution. |
228 | */ |
229 | |
230 | /*! |
231 | Returns the viewfinder minimum frame rate in frames per second. |
232 | |
233 | \sa maximumFrameRate() |
234 | */ |
235 | qreal QCameraViewfinderSettings::minimumFrameRate() const |
236 | { |
237 | return d->minimumFrameRate; |
238 | } |
239 | |
240 | /*! |
241 | Sets the viewfinder minimum frame \a rate in frames per second. |
242 | |
243 | If the minimum frame \a rate is equal to the maximum frame rate, the frame rate is fixed. |
244 | If not, the actual frame rate fluctuates between the minimum and the maximum. |
245 | |
246 | If the given \a rate equals to \c 0, the backend makes an optimal choice based on the |
247 | supported frame rates and the other viewfinder settings. |
248 | |
249 | \sa setMaximumFrameRate(), QCamera::supportedViewfinderFrameRateRanges() |
250 | */ |
251 | void QCameraViewfinderSettings::setMinimumFrameRate(qreal rate) |
252 | { |
253 | d->isNull = false; |
254 | d->minimumFrameRate = rate; |
255 | } |
256 | |
257 | /*! |
258 | Returns the viewfinder maximum frame rate in frames per second. |
259 | |
260 | \sa minimumFrameRate() |
261 | */ |
262 | qreal QCameraViewfinderSettings::maximumFrameRate() const |
263 | { |
264 | return d->maximumFrameRate; |
265 | } |
266 | |
267 | /*! |
268 | Sets the viewfinder maximum frame \a rate in frames per second. |
269 | |
270 | If the maximum frame \a rate is equal to the minimum frame rate, the frame rate is fixed. |
271 | If not, the actual frame rate fluctuates between the minimum and the maximum. |
272 | |
273 | If the given \a rate equals to \c 0, the backend makes an optimal choice based on the |
274 | supported frame rates and the other viewfinder settings. |
275 | |
276 | \sa setMinimumFrameRate(), QCamera::supportedViewfinderFrameRateRanges() |
277 | */ |
278 | void QCameraViewfinderSettings::setMaximumFrameRate(qreal rate) |
279 | { |
280 | d->isNull = false; |
281 | d->maximumFrameRate = rate; |
282 | } |
283 | |
284 | /*! |
285 | Returns the viewfinder pixel format. |
286 | */ |
287 | QVideoFrame::PixelFormat QCameraViewfinderSettings::pixelFormat() const |
288 | { |
289 | return d->pixelFormat; |
290 | } |
291 | |
292 | /*! |
293 | Sets the viewfinder pixel \a format. |
294 | |
295 | If the given \a format is equal to QVideoFrame::Format_Invalid, the backend uses the |
296 | default format. |
297 | |
298 | \sa QCamera::supportedViewfinderPixelFormats() |
299 | */ |
300 | void QCameraViewfinderSettings::setPixelFormat(QVideoFrame::PixelFormat format) |
301 | { |
302 | d->isNull = false; |
303 | d->pixelFormat = format; |
304 | } |
305 | |
306 | /*! |
307 | Returns the viewfinder pixel aspect ratio. |
308 | */ |
309 | QSize QCameraViewfinderSettings::pixelAspectRatio() const |
310 | { |
311 | return d->pixelAspectRatio; |
312 | } |
313 | |
314 | /*! |
315 | Sets the viewfinder pixel aspect \a ratio. |
316 | */ |
317 | void QCameraViewfinderSettings::setPixelAspectRatio(const QSize &ratio) |
318 | { |
319 | d->isNull = false; |
320 | d->pixelAspectRatio = ratio; |
321 | } |
322 | |
323 | /*! |
324 | \fn QCameraViewfinderSettings::setPixelAspectRatio(int horizontal, int vertical) |
325 | |
326 | This is an overloaded function. |
327 | |
328 | Sets the \a horizontal and \a vertical elements of the viewfinder's pixel aspect ratio. |
329 | */ |
330 | |
331 | QT_END_NAMESPACE |
332 | |