| 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 plugins 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 | #ifndef QDECLARATIVECAMERA_H |
| 41 | #define QDECLARATIVECAMERA_H |
| 42 | |
| 43 | // |
| 44 | // W A R N I N G |
| 45 | // ------------- |
| 46 | // |
| 47 | // This file is not part of the Qt API. It exists for the convenience |
| 48 | // of other Qt classes. This header file may change from version to |
| 49 | // version without notice, or even be removed. |
| 50 | // |
| 51 | // We mean it. |
| 52 | // |
| 53 | |
| 54 | #include "qdeclarativecameracapture_p.h" |
| 55 | #include "qdeclarativecamerarecorder_p.h" |
| 56 | |
| 57 | #include <qcamera.h> |
| 58 | #include <qcamerainfo.h> |
| 59 | #include <qcameraimageprocessing.h> |
| 60 | #include <qcameraimagecapture.h> |
| 61 | |
| 62 | #include <QtCore/qbasictimer.h> |
| 63 | #include <QtCore/qdatetime.h> |
| 64 | #include <QtQml/qqmlparserstatus.h> |
| 65 | #include <QtQml/qqml.h> |
| 66 | #include <QtQml/qjsvalue.h> |
| 67 | |
| 68 | QT_BEGIN_NAMESPACE |
| 69 | |
| 70 | class QDeclarativeCameraExposure; |
| 71 | class QDeclarativeCameraFocus; |
| 72 | class QDeclarativeCameraFlash; |
| 73 | class QDeclarativeCameraImageProcessing; |
| 74 | class QDeclarativeMediaMetaData; |
| 75 | class QDeclarativeCameraViewfinder; |
| 76 | |
| 77 | class QDeclarativeCamera : public QObject, public QQmlParserStatus |
| 78 | { |
| 79 | Q_OBJECT |
| 80 | Q_INTERFACES(QQmlParserStatus) |
| 81 | |
| 82 | Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged REVISION 1) |
| 83 | Q_PROPERTY(Position position READ position WRITE setPosition NOTIFY positionChanged REVISION 1) |
| 84 | Q_PROPERTY(QString displayName READ displayName NOTIFY displayNameChanged REVISION 1) |
| 85 | Q_PROPERTY(int orientation READ orientation NOTIFY orientationChanged REVISION 1) |
| 86 | |
| 87 | Q_PROPERTY(CaptureMode captureMode READ captureMode WRITE setCaptureMode NOTIFY captureModeChanged) |
| 88 | Q_PROPERTY(State cameraState READ cameraState WRITE setCameraState NOTIFY cameraStateChanged) |
| 89 | Q_PROPERTY(Status cameraStatus READ cameraStatus NOTIFY cameraStatusChanged) |
| 90 | Q_PROPERTY(LockStatus lockStatus READ lockStatus NOTIFY lockStatusChanged) |
| 91 | Q_PROPERTY(Error errorCode READ errorCode NOTIFY errorChanged) |
| 92 | Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) |
| 93 | |
| 94 | Q_PROPERTY(Availability availability READ availability NOTIFY availabilityChanged) |
| 95 | |
| 96 | Q_PROPERTY(qreal opticalZoom READ opticalZoom WRITE setOpticalZoom NOTIFY opticalZoomChanged) |
| 97 | Q_PROPERTY(qreal maximumOpticalZoom READ maximumOpticalZoom NOTIFY maximumOpticalZoomChanged) |
| 98 | Q_PROPERTY(qreal digitalZoom READ digitalZoom WRITE setDigitalZoom NOTIFY digitalZoomChanged) |
| 99 | Q_PROPERTY(qreal maximumDigitalZoom READ maximumDigitalZoom NOTIFY maximumDigitalZoomChanged) |
| 100 | |
| 101 | Q_PROPERTY(QObject *mediaObject READ mediaObject NOTIFY mediaObjectChanged SCRIPTABLE false DESIGNABLE false) |
| 102 | Q_PROPERTY(QDeclarativeCameraCapture* imageCapture READ imageCapture CONSTANT) |
| 103 | Q_PROPERTY(QDeclarativeCameraRecorder* videoRecorder READ videoRecorder CONSTANT) |
| 104 | Q_PROPERTY(QDeclarativeCameraExposure* exposure READ exposure CONSTANT) |
| 105 | Q_PROPERTY(QDeclarativeCameraFlash* flash READ flash CONSTANT) |
| 106 | Q_PROPERTY(QDeclarativeCameraFocus* focus READ focus CONSTANT) |
| 107 | Q_PROPERTY(QDeclarativeCameraImageProcessing* imageProcessing READ imageProcessing CONSTANT) |
| 108 | Q_PROPERTY(QDeclarativeMediaMetaData *metaData READ metaData CONSTANT REVISION 1) |
| 109 | Q_PROPERTY(QDeclarativeCameraViewfinder *viewfinder READ viewfinder CONSTANT REVISION 1) |
| 110 | |
| 111 | Q_ENUMS(Position) |
| 112 | Q_ENUMS(CaptureMode) |
| 113 | Q_ENUMS(State) |
| 114 | Q_ENUMS(Status) |
| 115 | Q_ENUMS(LockStatus) |
| 116 | Q_ENUMS(Error) |
| 117 | |
| 118 | Q_ENUMS(FlashMode) |
| 119 | Q_ENUMS(ExposureMode) |
| 120 | Q_ENUMS(MeteringMode) |
| 121 | |
| 122 | Q_ENUMS(FocusMode) |
| 123 | Q_ENUMS(FocusPointMode) |
| 124 | Q_ENUMS(FocusAreaStatus) |
| 125 | Q_ENUMS(Availability) |
| 126 | |
| 127 | public: |
| 128 | enum Position { |
| 129 | UnspecifiedPosition = QCamera::UnspecifiedPosition, |
| 130 | BackFace = QCamera::BackFace, |
| 131 | FrontFace = QCamera::FrontFace |
| 132 | }; |
| 133 | |
| 134 | enum CaptureMode { |
| 135 | CaptureViewfinder = QCamera::CaptureViewfinder, |
| 136 | CaptureStillImage = QCamera::CaptureStillImage, |
| 137 | CaptureVideo = QCamera::CaptureVideo |
| 138 | }; |
| 139 | |
| 140 | enum State |
| 141 | { |
| 142 | ActiveState = QCamera::ActiveState, |
| 143 | LoadedState = QCamera::LoadedState, |
| 144 | UnloadedState = QCamera::UnloadedState |
| 145 | }; |
| 146 | |
| 147 | enum Status |
| 148 | { |
| 149 | UnavailableStatus = QCamera::UnavailableStatus, |
| 150 | UnloadedStatus = QCamera::UnloadedStatus, |
| 151 | LoadingStatus = QCamera::LoadingStatus, |
| 152 | UnloadingStatus = QCamera::UnloadingStatus, |
| 153 | LoadedStatus = QCamera::LoadedStatus, |
| 154 | StandbyStatus = QCamera::StandbyStatus, |
| 155 | StartingStatus = QCamera::StartingStatus, |
| 156 | StoppingStatus = QCamera::StoppingStatus, |
| 157 | ActiveStatus = QCamera::ActiveStatus |
| 158 | }; |
| 159 | |
| 160 | enum LockStatus |
| 161 | { |
| 162 | Unlocked = QCamera::Unlocked, |
| 163 | Searching = QCamera::Searching, |
| 164 | Locked = QCamera::Locked |
| 165 | }; |
| 166 | |
| 167 | enum Error |
| 168 | { |
| 169 | NoError = QCamera::NoError, |
| 170 | CameraError = QCamera::CameraError, |
| 171 | InvalidRequestError = QCamera::InvalidRequestError, |
| 172 | ServiceMissingError = QCamera::ServiceMissingError, |
| 173 | NotSupportedFeatureError = QCamera::NotSupportedFeatureError |
| 174 | }; |
| 175 | |
| 176 | enum FlashMode { |
| 177 | FlashAuto = QCameraExposure::FlashAuto, |
| 178 | FlashOff = QCameraExposure::FlashOff, |
| 179 | FlashOn = QCameraExposure::FlashOn, |
| 180 | FlashRedEyeReduction = QCameraExposure::FlashRedEyeReduction, |
| 181 | FlashFill = QCameraExposure::FlashFill, |
| 182 | FlashTorch = QCameraExposure::FlashTorch, |
| 183 | FlashVideoLight = QCameraExposure::FlashVideoLight, |
| 184 | FlashSlowSyncFrontCurtain = QCameraExposure::FlashSlowSyncFrontCurtain, |
| 185 | FlashSlowSyncRearCurtain = QCameraExposure::FlashSlowSyncRearCurtain, |
| 186 | FlashManual = QCameraExposure::FlashManual |
| 187 | }; |
| 188 | |
| 189 | enum ExposureMode { |
| 190 | ExposureAuto = QCameraExposure::ExposureAuto, |
| 191 | ExposureManual = QCameraExposure::ExposureManual, |
| 192 | ExposurePortrait = QCameraExposure::ExposurePortrait, |
| 193 | ExposureNight = QCameraExposure::ExposureNight, |
| 194 | ExposureBacklight = QCameraExposure::ExposureBacklight, |
| 195 | ExposureSpotlight = QCameraExposure::ExposureSpotlight, |
| 196 | ExposureSports = QCameraExposure::ExposureSports, |
| 197 | ExposureSnow = QCameraExposure::ExposureSnow, |
| 198 | ExposureBeach = QCameraExposure::ExposureBeach, |
| 199 | ExposureLargeAperture = QCameraExposure::ExposureLargeAperture, |
| 200 | ExposureSmallAperture = QCameraExposure::ExposureSmallAperture, |
| 201 | ExposureAction = QCameraExposure::ExposureAction, |
| 202 | ExposureLandscape = QCameraExposure::ExposureLandscape, |
| 203 | ExposureNightPortrait = QCameraExposure::ExposureNightPortrait, |
| 204 | ExposureTheatre = QCameraExposure::ExposureTheatre, |
| 205 | ExposureSunset = QCameraExposure::ExposureSunset, |
| 206 | ExposureSteadyPhoto = QCameraExposure::ExposureSteadyPhoto, |
| 207 | ExposureFireworks = QCameraExposure::ExposureFireworks, |
| 208 | ExposureParty = QCameraExposure::ExposureParty, |
| 209 | ExposureCandlelight = QCameraExposure::ExposureCandlelight, |
| 210 | ExposureBarcode = QCameraExposure::ExposureBarcode, |
| 211 | ExposureModeVendor = QCameraExposure::ExposureModeVendor |
| 212 | }; |
| 213 | |
| 214 | enum MeteringMode { |
| 215 | MeteringMatrix = QCameraExposure::MeteringMatrix, |
| 216 | MeteringAverage = QCameraExposure::MeteringAverage, |
| 217 | MeteringSpot = QCameraExposure::MeteringSpot |
| 218 | }; |
| 219 | |
| 220 | enum FocusMode { |
| 221 | FocusManual = QCameraFocus::ManualFocus, |
| 222 | FocusHyperfocal = QCameraFocus::HyperfocalFocus, |
| 223 | FocusInfinity = QCameraFocus::InfinityFocus, |
| 224 | FocusAuto = QCameraFocus::AutoFocus, |
| 225 | FocusContinuous = QCameraFocus::ContinuousFocus, |
| 226 | FocusMacro = QCameraFocus::MacroFocus |
| 227 | }; |
| 228 | |
| 229 | enum FocusPointMode { |
| 230 | FocusPointAuto = QCameraFocus::FocusPointAuto, |
| 231 | FocusPointCenter = QCameraFocus::FocusPointCenter, |
| 232 | FocusPointFaceDetection = QCameraFocus::FocusPointFaceDetection, |
| 233 | FocusPointCustom = QCameraFocus::FocusPointCustom |
| 234 | }; |
| 235 | |
| 236 | enum FocusAreaStatus { |
| 237 | FocusAreaUnused = QCameraFocusZone::Unused, |
| 238 | FocusAreaSelected = QCameraFocusZone::Selected, |
| 239 | FocusAreaFocused = QCameraFocusZone::Focused |
| 240 | }; |
| 241 | |
| 242 | enum Availability { |
| 243 | Available = QMultimedia::Available, |
| 244 | Busy = QMultimedia::Busy, |
| 245 | Unavailable = QMultimedia::ServiceMissing, |
| 246 | ResourceMissing = QMultimedia::ResourceError |
| 247 | }; |
| 248 | |
| 249 | QDeclarativeCamera(QObject *parent = 0); |
| 250 | ~QDeclarativeCamera(); |
| 251 | |
| 252 | QObject *mediaObject() { return m_camera; } |
| 253 | |
| 254 | QDeclarativeCameraCapture *imageCapture() { return m_imageCapture; } |
| 255 | QDeclarativeCameraRecorder *videoRecorder() { return m_videoRecorder; } |
| 256 | QDeclarativeCameraExposure *exposure() { return m_exposure; } |
| 257 | QDeclarativeCameraFlash *flash() { return m_flash; } |
| 258 | QDeclarativeCameraFocus *focus() { return m_focus; } |
| 259 | QDeclarativeCameraImageProcessing *imageProcessing() { return m_imageProcessing; } |
| 260 | QDeclarativeCameraViewfinder *viewfinder(); |
| 261 | |
| 262 | QDeclarativeMediaMetaData *metaData(); |
| 263 | |
| 264 | QString deviceId() const; |
| 265 | void setDeviceId(const QString &name); |
| 266 | |
| 267 | Position position() const; |
| 268 | void setPosition(Position position); |
| 269 | |
| 270 | QString displayName() const; |
| 271 | int orientation() const; |
| 272 | |
| 273 | CaptureMode captureMode() const; |
| 274 | State cameraState() const; |
| 275 | Status cameraStatus() const; |
| 276 | |
| 277 | Error errorCode() const; |
| 278 | QString errorString() const; |
| 279 | |
| 280 | LockStatus lockStatus() const; |
| 281 | |
| 282 | qreal maximumOpticalZoom() const; |
| 283 | qreal maximumDigitalZoom() const; |
| 284 | |
| 285 | qreal opticalZoom() const; |
| 286 | qreal digitalZoom() const; |
| 287 | |
| 288 | Availability availability() const; |
| 289 | |
| 290 | public Q_SLOTS: |
| 291 | void setCaptureMode(CaptureMode mode); |
| 292 | |
| 293 | void start(); |
| 294 | void stop(); |
| 295 | |
| 296 | void setCameraState(State state); |
| 297 | |
| 298 | void searchAndLock(); |
| 299 | void unlock(); |
| 300 | |
| 301 | void setOpticalZoom(qreal); |
| 302 | void setDigitalZoom(qreal); |
| 303 | |
| 304 | Q_REVISION(2) QJSValue supportedViewfinderResolutions(qreal minimumFrameRate = 0.0, |
| 305 | qreal maximumFrameRate = 0.0); |
| 306 | |
| 307 | Q_REVISION(2) QJSValue supportedViewfinderFrameRateRanges(const QJSValue &resolution = QJSValue()); |
| 308 | |
| 309 | Q_SIGNALS: |
| 310 | void errorChanged(); |
| 311 | #if QT_DEPRECATED_SINCE(5,15) |
| 312 | void error(QDeclarativeCamera::Error errorCode, const QString &errorString); |
| 313 | #endif |
| 314 | Q_REVISION(15) void errorOccurred(QDeclarativeCamera::Error errorCode, const QString &errorString); |
| 315 | |
| 316 | Q_REVISION(1) void deviceIdChanged(); |
| 317 | Q_REVISION(1) void positionChanged(); |
| 318 | Q_REVISION(1) void displayNameChanged(); |
| 319 | Q_REVISION(1) void orientationChanged(); |
| 320 | |
| 321 | void captureModeChanged(); |
| 322 | void cameraStateChanged(QDeclarativeCamera::State); |
| 323 | void cameraStatusChanged(); |
| 324 | |
| 325 | void lockStatusChanged(); |
| 326 | |
| 327 | void opticalZoomChanged(qreal); |
| 328 | void digitalZoomChanged(qreal); |
| 329 | void maximumOpticalZoomChanged(qreal); |
| 330 | void maximumDigitalZoomChanged(qreal); |
| 331 | |
| 332 | void mediaObjectChanged(); |
| 333 | |
| 334 | void availabilityChanged(Availability availability); |
| 335 | |
| 336 | private Q_SLOTS: |
| 337 | void _q_updateState(QCamera::State); |
| 338 | void _q_errorOccurred(QCamera::Error); |
| 339 | void _q_availabilityChanged(QMultimedia::AvailabilityStatus); |
| 340 | |
| 341 | protected: |
| 342 | void classBegin() override; |
| 343 | void componentComplete() override; |
| 344 | |
| 345 | private: |
| 346 | Q_DISABLE_COPY(QDeclarativeCamera) |
| 347 | void setupDevice(const QString &deviceName); |
| 348 | |
| 349 | QCamera *m_camera; |
| 350 | QCameraInfo m_currentCameraInfo; |
| 351 | |
| 352 | QDeclarativeCameraCapture *m_imageCapture; |
| 353 | QDeclarativeCameraRecorder *m_videoRecorder; |
| 354 | QDeclarativeCameraExposure *m_exposure; |
| 355 | QDeclarativeCameraFlash *m_flash; |
| 356 | QDeclarativeCameraFocus *m_focus; |
| 357 | QDeclarativeCameraImageProcessing *m_imageProcessing; |
| 358 | QDeclarativeMediaMetaData *m_metaData; |
| 359 | QDeclarativeCameraViewfinder *m_viewfinder; |
| 360 | |
| 361 | State m_pendingState; |
| 362 | bool m_componentComplete; |
| 363 | }; |
| 364 | |
| 365 | QT_END_NAMESPACE |
| 366 | |
| 367 | QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeCamera)) |
| 368 | |
| 369 | #endif |
| 370 | |