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 MOCKCAMERAFOCUSCONTROL_H
30#define MOCKCAMERAFOCUSCONTROL_H
31
32#include "qcamerafocuscontrol.h"
33#include "qcamerafocus.h"
34
35class MockCameraFocusControl : public QCameraFocusControl
36{
37 Q_OBJECT
38public:
39 MockCameraFocusControl(QObject *parent = 0):
40 QCameraFocusControl(parent),
41 m_focusMode(QCameraFocus::AutoFocus),
42 m_focusPointMode(QCameraFocus::FocusPointAuto),
43 m_focusPoint(0.5, 0.5)
44 {
45 m_zones << QCameraFocusZone(QRectF(0.45, 0.45, 0.1, 0.1));
46 }
47
48 ~MockCameraFocusControl() {}
49
50 QCameraFocus::FocusModes focusMode() const
51 {
52 return m_focusMode;
53 }
54
55 void setFocusMode(QCameraFocus::FocusModes mode)
56 {
57 if (isFocusModeSupported(mode))
58 m_focusMode = mode;
59 }
60
61 bool isFocusModeSupported(QCameraFocus::FocusModes mode) const
62 {
63 return mode == QCameraFocus::AutoFocus || mode == QCameraFocus::ContinuousFocus;
64 }
65
66 QCameraFocus::FocusPointMode focusPointMode() const
67 {
68 return m_focusPointMode;
69 }
70
71 void setFocusPointMode(QCameraFocus::FocusPointMode mode)
72 {
73 if (isFocusPointModeSupported(mode))
74 m_focusPointMode = mode;
75 }
76
77 bool isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const
78 {
79 switch (mode) {
80 case QCameraFocus::FocusPointAuto:
81 case QCameraFocus::FocusPointCenter:
82 case QCameraFocus::FocusPointCustom:
83 return true;
84 default:
85 return false;
86 }
87 }
88
89 QPointF customFocusPoint() const
90 {
91 return m_focusPoint;
92 }
93
94 void setCustomFocusPoint(const QPointF &point)
95 {
96 m_focusPoint = point;
97 focusZonesChange(left: 0.50, top: 0.50, width: 0.3, height: 0.3);
98 }
99
100 QCameraFocusZoneList focusZones() const
101 {
102 return m_zones;
103 }
104
105 // helper function to emit Focus Zones Changed signals
106 void focusZonesChange(qreal left, qreal top, qreal width, qreal height)
107 {
108 QCameraFocusZone myZone(QRectF(left, top, width, height));
109 if (m_zones.last().area() != myZone.area()) {
110 m_zones.clear();
111 m_zones << myZone;
112 emit focusZonesChanged();
113 }
114 }
115
116private:
117 QCameraFocus::FocusModes m_focusMode;
118 QCameraFocus::FocusPointMode m_focusPointMode;
119 QPointF m_focusPoint;
120 // to emit focus zone changed signal
121 QCameraFocusZoneList m_zones;
122};
123
124#endif // MOCKCAMERAFOCUSCONTROL_H
125

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