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 MOCKCAMERACONTROL_H
30#define MOCKCAMERACONTROL_H
31
32#include "qcameracontrol.h"
33
34class MockCameraControl : public QCameraControl
35{
36 friend class MockCaptureControl;
37 Q_OBJECT
38public:
39 MockCameraControl(QObject *parent = 0):
40 QCameraControl(parent),
41 m_state(QCamera::UnloadedState),
42 m_captureMode(QCamera::CaptureStillImage),
43 m_status(QCamera::UnloadedStatus),
44 m_propertyChangesSupported(false)
45 {
46 }
47
48 ~MockCameraControl() {}
49
50 void start() { m_state = QCamera::ActiveState; }
51 virtual void stop() { m_state = QCamera::UnloadedState; }
52 QCamera::State state() const { return m_state; }
53 void setState(QCamera::State state) {
54 if (m_state != state) {
55 m_state = state;
56
57 switch (state) {
58 case QCamera::UnloadedState:
59 m_status = QCamera::UnloadedStatus;
60 break;
61 case QCamera::LoadedState:
62 m_status = QCamera::LoadedStatus;
63 break;
64 case QCamera::ActiveState:
65 m_status = QCamera::ActiveStatus;
66 break;
67 default:
68 emit error(error: QCamera::NotSupportedFeatureError, errorString: "State not supported.");
69 return;
70 }
71
72 emit stateChanged(m_state);
73 emit statusChanged(m_status);
74 }
75 }
76
77 QCamera::Status status() const { return m_status; }
78
79 QCamera::CaptureModes captureMode() const { return m_captureMode; }
80 void setCaptureMode(QCamera::CaptureModes mode)
81 {
82 if (m_captureMode != mode) {
83 if (m_state == QCamera::ActiveState && !m_propertyChangesSupported)
84 return;
85 m_captureMode = mode;
86 emit captureModeChanged(mode);
87 }
88 }
89
90 bool isCaptureModeSupported(QCamera::CaptureModes mode) const
91 {
92 return mode == QCamera::CaptureStillImage || mode == QCamera::CaptureVideo;
93 }
94
95 QCamera::LockTypes supportedLocks() const
96 {
97 return QCamera::LockExposure | QCamera::LockFocus | QCamera::LockWhiteBalance;
98 }
99
100 bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const
101 {
102 Q_UNUSED(status);
103 if (changeType == QCameraControl::ImageEncodingSettings && m_captureMode == QCamera::CaptureVideo)
104 return true;
105 else if (changeType== QCameraControl::VideoEncodingSettings)
106 return true;
107 else
108 return m_propertyChangesSupported;
109 }
110
111 /* helper method to emit the signal error */
112 void setError(QCamera::Error err, QString errorString)
113 {
114 emit error(error: err, errorString);
115 }
116
117 /* helper method to emit the signal statusChaged */
118 void setStatus(QCamera::Status newStatus)
119 {
120 m_status = newStatus;
121 emit statusChanged(newStatus);
122 }
123
124 QCamera::State m_state;
125 QCamera::CaptureModes m_captureMode;
126 QCamera::Status m_status;
127 bool m_propertyChangesSupported;
128};
129
130
131
132#endif // MOCKCAMERACONTROL_H
133

source code of qtmultimedia/tests/auto/unit/qmultimedia_common/mockcameracontrol.h