| 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 test suite of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ | 
| 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 General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
| 21 | ** included in the packaging of this file. Please review the following | 
| 22 | ** information to ensure the GNU General Public License requirements will | 
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 24 | ** | 
| 25 | ** $QT_END_LICENSE$ | 
| 26 | ** | 
| 27 | ****************************************************************************/ | 
| 28 |  | 
| 29 | #ifndef MOCKCAMERACAPTURECONTROL_H | 
| 30 | #define MOCKCAMERACAPTURECONTROL_H | 
| 31 |  | 
| 32 | #include <QDateTime> | 
| 33 | #include <QTimer> | 
| 34 | #include <QtMultimedia/qmediametadata.h> | 
| 35 |  | 
| 36 | #include "qcameraimagecapturecontrol.h" | 
| 37 | #include "qcameracontrol.h" | 
| 38 | #include "mockcameracontrol.h" | 
| 39 |  | 
| 40 | class MockCaptureControl : public QCameraImageCaptureControl | 
| 41 | { | 
| 42 |     Q_OBJECT | 
| 43 | public: | 
| 44 |     MockCaptureControl(MockCameraControl *cameraControl, QObject *parent = 0) | 
| 45 |         : QCameraImageCaptureControl(parent), m_cameraControl(cameraControl), m_captureRequest(0), m_ready(true), m_captureCanceled(false) | 
| 46 |     { | 
| 47 |     } | 
| 48 |  | 
| 49 |     ~MockCaptureControl() | 
| 50 |     { | 
| 51 |     } | 
| 52 |  | 
| 53 |     QCameraImageCapture::DriveMode driveMode() const { return QCameraImageCapture::SingleImageCapture; } | 
| 54 |     void setDriveMode(QCameraImageCapture::DriveMode) {} | 
| 55 |  | 
| 56 |     bool isReadyForCapture() const { return m_ready && m_cameraControl->state() == QCamera::ActiveState; } | 
| 57 |  | 
| 58 |     int capture(const QString &fileName) | 
| 59 |     { | 
| 60 |         if (isReadyForCapture()) { | 
| 61 |             m_fileName = fileName; | 
| 62 |             m_captureRequest++; | 
| 63 |             emit readyForCaptureChanged(ready: m_ready = false); | 
| 64 |             QTimer::singleShot(msec: 5, receiver: this, SLOT(captured())); | 
| 65 |             return m_captureRequest; | 
| 66 |         } else { | 
| 67 |             emit error(id: -1, error: QCameraImageCapture::NotReadyError, | 
| 68 |                        errorString: QLatin1String("Could not capture in stopped state" )); | 
| 69 |         } | 
| 70 |  | 
| 71 |         return -1; | 
| 72 |     } | 
| 73 |  | 
| 74 |     void cancelCapture() | 
| 75 |     { | 
| 76 |         m_captureCanceled = true; | 
| 77 |     } | 
| 78 |  | 
| 79 | private Q_SLOTS: | 
| 80 |     void captured() | 
| 81 |     { | 
| 82 |         if (!m_captureCanceled) { | 
| 83 |             emit imageCaptured(requestId: m_captureRequest, preview: QImage()); | 
| 84 |  | 
| 85 |             emit imageMetadataAvailable(id: m_captureRequest, | 
| 86 |                                         key: QMediaMetaData::FocalLengthIn35mmFilm, | 
| 87 |                                         value: QVariant(50)); | 
| 88 |  | 
| 89 |             emit imageMetadataAvailable(id: m_captureRequest, | 
| 90 |                                         key: QMediaMetaData::DateTimeOriginal, | 
| 91 |                                         value: QVariant(QDateTime::currentDateTime())); | 
| 92 |  | 
| 93 |             emit imageMetadataAvailable(id: m_captureRequest, | 
| 94 |                                         key: QLatin1String("Answer to the Ultimate Question of Life, the Universe, and Everything" ), | 
| 95 |                                         value: QVariant(42)); | 
| 96 |         } | 
| 97 |  | 
| 98 |         if (!m_ready) | 
| 99 |         { | 
| 100 |             emit readyForCaptureChanged(ready: m_ready = true); | 
| 101 |             emit imageExposed(requestId: m_captureRequest); | 
| 102 |         } | 
| 103 |  | 
| 104 |         if (!m_captureCanceled) | 
| 105 |             emit imageSaved(requestId: m_captureRequest, fileName: m_fileName); | 
| 106 |  | 
| 107 |         m_captureCanceled = false; | 
| 108 |     } | 
| 109 |  | 
| 110 | private: | 
| 111 |     MockCameraControl *m_cameraControl; | 
| 112 |     QString m_fileName; | 
| 113 |     int m_captureRequest; | 
| 114 |     bool m_ready; | 
| 115 |     bool m_captureCanceled; | 
| 116 | }; | 
| 117 |  | 
| 118 | #endif // MOCKCAMERACAPTURECONTROL_H | 
| 119 |  |