1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part 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 #include <QCameraFocusControl>
40 
41 #include "qwinrtcameralockscontrol.h"
42 #include "qwinrtcameracontrol.h"
43 
44 QT_BEGIN_NAMESPACE
45 
QWinRTCameraLocksControl(QObject * parent)46 QWinRTCameraLocksControl::QWinRTCameraLocksControl(QObject *parent)
47     : QCameraLocksControl(parent)
48     , m_supportedLocks(QCamera::NoLock)
49     , m_focusLockStatus(QCamera::Unlocked)
50 {
51 }
52 
supportedLocks() const53 QCamera::LockTypes QWinRTCameraLocksControl::supportedLocks() const
54 {
55     return m_supportedLocks;
56 }
57 
lockStatus(QCamera::LockType lock) const58 QCamera::LockStatus QWinRTCameraLocksControl::lockStatus(QCamera::LockType lock) const
59 {
60     switch (lock) {
61     case QCamera::LockFocus:
62         return m_focusLockStatus;
63     case QCamera::LockExposure:
64     case QCamera::LockWhiteBalance:
65     default:
66         return QCamera::Unlocked;
67     }
68 }
69 
searchAndLock(QCamera::LockTypes locks)70 void QWinRTCameraLocksControl::searchAndLock(QCamera::LockTypes locks)
71 {
72     QWinRTCameraControl *cameraControl = qobject_cast<QWinRTCameraControl *>(parent());
73     Q_ASSERT(cameraControl);
74     if (cameraControl->state() != QCamera::ActiveState)
75         return;
76     else if (locks.testFlag(QCamera::LockFocus))
77         QMetaObject::invokeMethod(this, "searchAndLockFocus", Qt::QueuedConnection);
78     else
79         cameraControl->emitError(QCamera::InvalidRequestError, QStringLiteral("Unsupported camera lock type."));
80 }
81 
unlock(QCamera::LockTypes locks)82 void QWinRTCameraLocksControl::unlock(QCamera::LockTypes locks)
83 {
84     if (locks.testFlag(QCamera::LockFocus))
85         QMetaObject::invokeMethod(this, "unlockFocus", Qt::QueuedConnection);
86 }
87 
initialize()88 void QWinRTCameraLocksControl::initialize()
89 {
90     QWinRTCameraControl *cameraControl = qobject_cast<QWinRTCameraControl *>(parent());
91     Q_ASSERT(cameraControl);
92     QCameraFocusControl *focusControl = cameraControl->cameraFocusControl();
93     Q_ASSERT(focusControl);
94     if (focusControl->isFocusModeSupported(QCameraFocus::AutoFocus))
95         m_supportedLocks |= QCamera::LockFocus;
96 }
97 
searchAndLockFocus()98 void QWinRTCameraLocksControl::searchAndLockFocus()
99 {
100     if (QCamera::Locked == m_focusLockStatus)
101         unlockFocus();
102     QWinRTCameraControl *cameraControl = qobject_cast<QWinRTCameraControl *>(parent());
103     Q_ASSERT(cameraControl);
104     QCameraFocusControl *focusControl = cameraControl->cameraFocusControl();
105     Q_ASSERT(focusControl);
106     if (focusControl->focusMode().testFlag(QCameraFocus::ContinuousFocus)) {
107         cameraControl->emitError(QCamera::NotSupportedFeatureError, QStringLiteral("Camera can't lock focus in continuous focus mode."));
108     } else {
109         m_focusLockStatus = QCamera::Searching;
110         emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::LockAcquired);
111         if (cameraControl->focus()) {
112             m_focusLockStatus = cameraControl->lockFocus() ? QCamera::Locked : QCamera::Unlocked;
113             emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::LockAcquired);
114         }
115     }
116 }
117 
unlockFocus()118 void QWinRTCameraLocksControl::unlockFocus()
119 {
120     if (QCamera::Unlocked == m_focusLockStatus)
121         return;
122     QWinRTCameraControl *cameraControl = qobject_cast<QWinRTCameraControl *>(parent());
123     Q_ASSERT(cameraControl);
124     m_focusLockStatus = cameraControl->unlockFocus() ? QCamera::Unlocked : QCamera::Locked;
125     emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::UserRequest);
126 }
127 
128 QT_END_NAMESPACE
129