1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QCAMERA_H |
5 | #define QCAMERA_H |
6 | |
7 | #include <QtCore/qstringlist.h> |
8 | #include <QtCore/qpair.h> |
9 | #include <QtCore/qsize.h> |
10 | #include <QtCore/qpoint.h> |
11 | #include <QtCore/qrect.h> |
12 | |
13 | #include <QtCore/qobject.h> |
14 | |
15 | #include <QtMultimedia/qcameradevice.h> |
16 | |
17 | #include <QtMultimedia/qmediaenumdebug.h> |
18 | |
19 | QT_BEGIN_NAMESPACE |
20 | |
21 | |
22 | class QCameraDevice; |
23 | class QPlatformMediaCaptureSession; |
24 | class QMediaCaptureSession; |
25 | |
26 | class QCameraPrivate; |
27 | class Q_MULTIMEDIA_EXPORT QCamera : public QObject |
28 | { |
29 | Q_OBJECT |
30 | Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) |
31 | // Qt 7: rename to device |
32 | Q_PROPERTY(QCameraDevice cameraDevice READ cameraDevice WRITE setCameraDevice NOTIFY cameraDeviceChanged) |
33 | Q_PROPERTY(Error error READ error NOTIFY errorChanged) |
34 | Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) |
35 | Q_PROPERTY(QCameraFormat cameraFormat READ cameraFormat WRITE setCameraFormat NOTIFY cameraFormatChanged) |
36 | |
37 | Q_PROPERTY(FocusMode focusMode READ focusMode WRITE setFocusMode) |
38 | Q_PROPERTY(QPointF focusPoint READ focusPoint NOTIFY focusPointChanged) |
39 | Q_PROPERTY(QPointF customFocusPoint READ customFocusPoint WRITE setCustomFocusPoint NOTIFY customFocusPointChanged) |
40 | Q_PROPERTY(float focusDistance READ focusDistance WRITE setFocusDistance NOTIFY focusDistanceChanged) |
41 | |
42 | Q_PROPERTY(float minimumZoomFactor READ minimumZoomFactor NOTIFY minimumZoomFactorChanged) |
43 | Q_PROPERTY(float maximumZoomFactor READ maximumZoomFactor NOTIFY maximumZoomFactorChanged) |
44 | Q_PROPERTY(float zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) |
45 | Q_PROPERTY(float exposureTime READ exposureTime NOTIFY exposureTimeChanged) |
46 | Q_PROPERTY(int manualExposureTime READ manualExposureTime WRITE setManualExposureTime NOTIFY manualExposureTimeChanged) |
47 | Q_PROPERTY(int isoSensitivity READ isoSensitivity NOTIFY isoSensitivityChanged) |
48 | Q_PROPERTY(int manualIsoSensitivity READ manualIsoSensitivity WRITE setManualIsoSensitivity NOTIFY manualIsoSensitivityChanged) |
49 | Q_PROPERTY(float exposureCompensation READ exposureCompensation WRITE setExposureCompensation NOTIFY exposureCompensationChanged) |
50 | Q_PROPERTY(QCamera::ExposureMode exposureMode READ exposureMode WRITE setExposureMode NOTIFY exposureModeChanged) |
51 | Q_PROPERTY(bool flashReady READ isFlashReady NOTIFY flashReady) |
52 | Q_PROPERTY(QCamera::FlashMode flashMode READ flashMode WRITE setFlashMode NOTIFY flashModeChanged) |
53 | Q_PROPERTY(QCamera::TorchMode torchMode READ torchMode WRITE setTorchMode NOTIFY torchModeChanged) |
54 | |
55 | Q_PROPERTY(WhiteBalanceMode whiteBalanceMode READ whiteBalanceMode WRITE setWhiteBalanceMode NOTIFY whiteBalanceModeChanged) |
56 | Q_PROPERTY(int colorTemperature READ colorTemperature WRITE setColorTemperature NOTIFY colorTemperatureChanged) |
57 | Q_PROPERTY(Features supportedFeatures READ supportedFeatures NOTIFY supportedFeaturesChanged) |
58 | |
59 | public: |
60 | enum Error |
61 | { |
62 | NoError, |
63 | CameraError |
64 | }; |
65 | Q_ENUM(Error) |
66 | |
67 | enum FocusMode { |
68 | FocusModeAuto, |
69 | FocusModeAutoNear, |
70 | FocusModeAutoFar, |
71 | FocusModeHyperfocal, |
72 | FocusModeInfinity, |
73 | FocusModeManual |
74 | }; |
75 | Q_ENUM(FocusMode) |
76 | |
77 | enum FlashMode { |
78 | FlashOff, |
79 | FlashOn, |
80 | FlashAuto |
81 | }; |
82 | Q_ENUM(FlashMode) |
83 | |
84 | enum TorchMode { |
85 | TorchOff, |
86 | TorchOn, |
87 | TorchAuto |
88 | }; |
89 | Q_ENUM(TorchMode) |
90 | |
91 | enum ExposureMode { |
92 | ExposureAuto, |
93 | ExposureManual, |
94 | ExposurePortrait, |
95 | ExposureNight, |
96 | ExposureSports, |
97 | ExposureSnow, |
98 | ExposureBeach, |
99 | ExposureAction, |
100 | ExposureLandscape, |
101 | ExposureNightPortrait, |
102 | ExposureTheatre, |
103 | ExposureSunset, |
104 | ExposureSteadyPhoto, |
105 | ExposureFireworks, |
106 | ExposureParty, |
107 | ExposureCandlelight, |
108 | ExposureBarcode |
109 | }; |
110 | Q_ENUM(ExposureMode) |
111 | |
112 | enum WhiteBalanceMode { |
113 | WhiteBalanceAuto = 0, |
114 | WhiteBalanceManual = 1, |
115 | WhiteBalanceSunlight = 2, |
116 | WhiteBalanceCloudy = 3, |
117 | WhiteBalanceShade = 4, |
118 | WhiteBalanceTungsten = 5, |
119 | WhiteBalanceFluorescent = 6, |
120 | WhiteBalanceFlash = 7, |
121 | WhiteBalanceSunset = 8 |
122 | }; |
123 | Q_ENUM(WhiteBalanceMode) |
124 | |
125 | enum class Feature { |
126 | ColorTemperature = 0x1, |
127 | ExposureCompensation = 0x2, |
128 | IsoSensitivity = 0x4, |
129 | ManualExposureTime = 0x8, |
130 | CustomFocusPoint = 0x10, |
131 | FocusDistance = 0x20 |
132 | }; |
133 | Q_DECLARE_FLAGS(Features, Feature) |
134 | |
135 | explicit QCamera(QObject *parent = nullptr); |
136 | explicit QCamera(const QCameraDevice& cameraDevice, QObject *parent = nullptr); |
137 | explicit QCamera(QCameraDevice::Position position, QObject *parent = nullptr); |
138 | ~QCamera(); |
139 | |
140 | bool isAvailable() const; |
141 | bool isActive() const; |
142 | |
143 | QMediaCaptureSession *captureSession() const; |
144 | |
145 | QCameraDevice cameraDevice() const; |
146 | void setCameraDevice(const QCameraDevice &cameraDevice); |
147 | |
148 | QCameraFormat cameraFormat() const; |
149 | void setCameraFormat(const QCameraFormat &format); |
150 | |
151 | Error error() const; |
152 | QString errorString() const; |
153 | |
154 | Features supportedFeatures() const; |
155 | |
156 | FocusMode focusMode() const; |
157 | void setFocusMode(FocusMode mode); |
158 | Q_INVOKABLE bool isFocusModeSupported(FocusMode mode) const; |
159 | |
160 | QPointF focusPoint() const; |
161 | |
162 | QPointF customFocusPoint() const; |
163 | void setCustomFocusPoint(const QPointF &point); |
164 | |
165 | void setFocusDistance(float d); |
166 | float focusDistance() const; |
167 | |
168 | float minimumZoomFactor() const; |
169 | float maximumZoomFactor() const; |
170 | float zoomFactor() const; |
171 | void setZoomFactor(float factor); |
172 | |
173 | FlashMode flashMode() const; |
174 | Q_INVOKABLE bool isFlashModeSupported(FlashMode mode) const; |
175 | Q_INVOKABLE bool isFlashReady() const; |
176 | |
177 | TorchMode torchMode() const; |
178 | Q_INVOKABLE bool isTorchModeSupported(TorchMode mode) const; |
179 | |
180 | ExposureMode exposureMode() const; |
181 | Q_INVOKABLE bool isExposureModeSupported(ExposureMode mode) const; |
182 | |
183 | float exposureCompensation() const; |
184 | |
185 | int isoSensitivity() const; |
186 | int manualIsoSensitivity() const; |
187 | |
188 | float exposureTime() const; |
189 | float manualExposureTime() const; |
190 | |
191 | int minimumIsoSensitivity() const; |
192 | int maximumIsoSensitivity() const; |
193 | |
194 | float minimumExposureTime() const; |
195 | float maximumExposureTime() const; |
196 | |
197 | WhiteBalanceMode whiteBalanceMode() const; |
198 | Q_INVOKABLE bool isWhiteBalanceModeSupported(WhiteBalanceMode mode) const; |
199 | |
200 | int colorTemperature() const; |
201 | |
202 | public Q_SLOTS: |
203 | void setActive(bool active); |
204 | void start() { setActive(true); } |
205 | void stop() { setActive(false); } |
206 | |
207 | void zoomTo(float zoom, float rate); |
208 | |
209 | void setFlashMode(FlashMode mode); |
210 | void setTorchMode(TorchMode mode); |
211 | void setExposureMode(ExposureMode mode); |
212 | |
213 | void setExposureCompensation(float ev); |
214 | |
215 | void setManualIsoSensitivity(int iso); |
216 | void setAutoIsoSensitivity(); |
217 | |
218 | void setManualExposureTime(float seconds); |
219 | void setAutoExposureTime(); |
220 | |
221 | void setWhiteBalanceMode(WhiteBalanceMode mode); |
222 | void setColorTemperature(int colorTemperature); |
223 | |
224 | Q_SIGNALS: |
225 | void activeChanged(bool); |
226 | void errorChanged(); |
227 | void errorOccurred(QCamera::Error error, const QString &errorString); |
228 | void cameraDeviceChanged(); |
229 | void cameraFormatChanged(); |
230 | void supportedFeaturesChanged(); |
231 | |
232 | void focusModeChanged(); |
233 | void zoomFactorChanged(float); |
234 | void minimumZoomFactorChanged(float); |
235 | void maximumZoomFactorChanged(float); |
236 | void focusDistanceChanged(float); |
237 | void focusPointChanged(); |
238 | void customFocusPointChanged(); |
239 | |
240 | void flashReady(bool); |
241 | void flashModeChanged(); |
242 | void torchModeChanged(); |
243 | |
244 | void exposureTimeChanged(float speed); |
245 | void manualExposureTimeChanged(float speed); |
246 | void isoSensitivityChanged(int); |
247 | void manualIsoSensitivityChanged(int); |
248 | void exposureCompensationChanged(float); |
249 | void exposureModeChanged(); |
250 | |
251 | void whiteBalanceModeChanged() QT6_ONLY(const); |
252 | void colorTemperatureChanged() QT6_ONLY(const); |
253 | void brightnessChanged(); |
254 | void contrastChanged(); |
255 | void saturationChanged(); |
256 | void hueChanged(); |
257 | |
258 | private: |
259 | class QPlatformCamera *platformCamera(); |
260 | void setCaptureSession(QMediaCaptureSession *session); |
261 | friend class QMediaCaptureSession; |
262 | Q_DISABLE_COPY(QCamera) |
263 | Q_DECLARE_PRIVATE(QCamera) |
264 | Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &)) |
265 | friend class QCameraDevice; |
266 | }; |
267 | |
268 | Q_DECLARE_OPERATORS_FOR_FLAGS(QCamera::Features) |
269 | |
270 | QT_END_NAMESPACE |
271 | |
272 | Q_MEDIA_ENUM_DEBUG(QCamera, Error) |
273 | |
274 | #endif // QCAMERA_H |
275 | |