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