-
Notifications
You must be signed in to change notification settings - Fork 11
/
gphotocameralockcontrol.cpp
94 lines (80 loc) · 2.86 KB
/
gphotocameralockcontrol.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "gphotocameralockcontrol.h"
#include "gphotocamerasession.h"
#include <QCameraFocusControl>
namespace {
constexpr auto autofocusdriveParameter = "autofocusdrive";
constexpr auto cancelautofocusParameter = "cancelautofocus";
}
GPhotoCameraLockControl::GPhotoCameraLockControl(GPhotoCameraSession *session, QObject *parent)
: QCameraLocksControl(parent)
, m_session(session)
{
connect(session, &GPhotoCameraSession::statusChanged, this, &GPhotoCameraLockControl::onStatusChanged);
}
QCamera::LockTypes GPhotoCameraLockControl::supportedLocks() const
{
return QCamera::LockFocus;
}
QCamera::LockStatus GPhotoCameraLockControl::lockStatus(QCamera::LockType lock) const
{
if (QCamera::LockFocus == lock && m_pendingLocks & QCamera::LockFocus)
return QCamera::Searching;
return m_lockStatus.value(lock);
}
void GPhotoCameraLockControl::searchAndLock(QCamera::LockTypes locks)
{
m_pendingLocks &= ~locks;
if (locks & QCamera::LockFocus) {
auto focusMode = m_session->cameraFocusControl()->focusMode();
if (focusMode & QCameraFocus::AutoFocus) {
if (QCamera::ActiveStatus == m_session->status())
startFocusing();
else
m_pendingLocks |= QCamera::LockFocus;
}
}
}
void GPhotoCameraLockControl::unlock(QCamera::LockTypes locks)
{
m_pendingLocks &= ~locks;
if (locks & QCamera::LockFocus)
stopFocusing();
}
void GPhotoCameraLockControl::onStatusChanged(QCamera::Status status)
{
if (QCamera::ActiveStatus == status && m_pendingLocks & QCamera::LockFocus) {
startFocusing();
}
}
void GPhotoCameraLockControl::setLockStatus(QCamera::LockType lock, QCamera::LockStatus status,
QCamera::LockChangeReason reason)
{
auto oldStatus = m_lockStatus.value(lock, QCamera::Unlocked);
if (oldStatus != status) {
m_lockStatus.insert(lock, status);
emit lockStatusChanged(lock, status, reason);
}
}
void GPhotoCameraLockControl::startFocusing()
{
if (QCamera::ActiveStatus == m_session->status()) {
if (m_session->setParameter(QLatin1String(autofocusdriveParameter), true)) {
m_pendingLocks &= ~QCamera::LockFocus;
setLockStatus(QCamera::LockFocus, QCamera::Locked, QCamera::UserRequest);
} else {
setLockStatus(QCamera::LockFocus, QCamera::Locked, QCamera::LockFailed);
}
}
}
void GPhotoCameraLockControl::stopFocusing()
{
if (m_session->parameter(QLatin1String(cancelautofocusParameter)).isValid()) {
// Canon
if (m_session->setParameter(QLatin1String(cancelautofocusParameter), true)) {
setLockStatus(QCamera::LockFocus, QCamera::Unlocked, QCamera::UserRequest);
}
} else {
// Nikon
setLockStatus(QCamera::LockFocus, QCamera::Unlocked, QCamera::UserRequest);
}
}