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 MOCKCAMERALOCKCONTROL_H |
30 | #define MOCKCAMERALOCKCONTROL_H |
31 | |
32 | #include <QTimer> |
33 | #include "qcameralockscontrol.h" |
34 | |
35 | class MockCameraLocksControl : public QCameraLocksControl |
36 | { |
37 | Q_OBJECT |
38 | public: |
39 | MockCameraLocksControl(QObject *parent = 0): |
40 | QCameraLocksControl(parent), |
41 | m_focusLock(QCamera::Unlocked), |
42 | m_exposureLock(QCamera::Unlocked) |
43 | { |
44 | } |
45 | |
46 | ~MockCameraLocksControl() {} |
47 | |
48 | QCamera::LockTypes supportedLocks() const |
49 | { |
50 | return QCamera::LockExposure | QCamera::LockFocus; |
51 | } |
52 | |
53 | QCamera::LockStatus lockStatus(QCamera::LockType lock) const |
54 | { |
55 | switch (lock) { |
56 | case QCamera::LockExposure: |
57 | return m_exposureLock; |
58 | case QCamera::LockFocus: |
59 | return m_focusLock; |
60 | default: |
61 | return QCamera::Unlocked; |
62 | } |
63 | } |
64 | |
65 | void searchAndLock(QCamera::LockTypes locks) |
66 | { |
67 | if (locks & QCamera::LockExposure) { |
68 | QCamera::LockStatus newStatus = locks & QCamera::LockFocus ? QCamera::Searching : QCamera::Locked; |
69 | |
70 | if (newStatus != m_exposureLock) |
71 | emit lockStatusChanged(type: QCamera::LockExposure, |
72 | status: m_exposureLock = newStatus, |
73 | reason: QCamera::UserRequest); |
74 | } |
75 | |
76 | if (locks & QCamera::LockFocus) { |
77 | emit lockStatusChanged(type: QCamera::LockFocus, |
78 | status: m_focusLock = QCamera::Searching, |
79 | reason: QCamera::UserRequest); |
80 | |
81 | QTimer::singleShot(msec: 5, receiver: this, SLOT(focused())); |
82 | } |
83 | } |
84 | |
85 | void unlock(QCamera::LockTypes locks) { |
86 | if (locks & QCamera::LockFocus && m_focusLock != QCamera::Unlocked) { |
87 | emit lockStatusChanged(type: QCamera::LockFocus, |
88 | status: m_focusLock = QCamera::Unlocked, |
89 | reason: QCamera::UserRequest); |
90 | } |
91 | |
92 | if (locks & QCamera::LockExposure && m_exposureLock != QCamera::Unlocked) { |
93 | emit lockStatusChanged(type: QCamera::LockExposure, |
94 | status: m_exposureLock = QCamera::Unlocked, |
95 | reason: QCamera::UserRequest); |
96 | } |
97 | } |
98 | |
99 | /* helper method to emit the signal with LockChangeReason */ |
100 | void setLockChangeReason (QCamera::LockChangeReason lockChangeReason) |
101 | { |
102 | emit lockStatusChanged(type: QCamera::NoLock, |
103 | status: QCamera::Unlocked, |
104 | reason: lockChangeReason); |
105 | |
106 | } |
107 | |
108 | private slots: |
109 | void focused() |
110 | { |
111 | if (m_focusLock == QCamera::Searching) { |
112 | emit lockStatusChanged(type: QCamera::LockFocus, |
113 | status: m_focusLock = QCamera::Locked, |
114 | reason: QCamera::UserRequest); |
115 | } |
116 | |
117 | if (m_exposureLock == QCamera::Searching) { |
118 | emit lockStatusChanged(type: QCamera::LockExposure, |
119 | status: m_exposureLock = QCamera::Locked, |
120 | reason: QCamera::UserRequest); |
121 | } |
122 | } |
123 | |
124 | |
125 | private: |
126 | QCamera::LockStatus m_focusLock; |
127 | QCamera::LockStatus m_exposureLock; |
128 | }; |
129 | |
130 | |
131 | #endif // MOCKCAMERALOCKCONTROL_H |
132 | |