uvccameracontrol.cpp 2.07 KB
Newer Older
Thiago Santini's avatar
Thiago Santini committed
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
#include "uvccameracontrol.h"

#include "uvccameracontrol.h"
#include "uvccameraservice.h"
#include "uvccamerasession.h"

QT_BEGIN_NAMESPACE

UVCCameraControl::UVCCameraControl(QObject *parent)
    : QCameraControl(parent)
    , m_state(QCamera::UnloadedState)
    , m_captureMode(QCamera::CaptureStillImage)
{
    m_session = qobject_cast<UVCCameraSession*>(parent);
    //connect(m_session, SIGNAL(statusChanged(QCamera::Status)),
    //        this, SIGNAL(statusChanged(QCamera::Status)));
}

UVCCameraControl::~UVCCameraControl()
{
}

void UVCCameraControl::setState(QCamera::State state)
{
    if (m_state == state)
        return;

    bool succeeded = false;
    switch (state) {
        case QCamera::UnloadedState:
            succeeded = m_session->unload();
            break;

        case QCamera::LoadedState:
35
            if (m_state == QCamera::UnloadedState && !(succeeded=m_session->load()))
Thiago Santini's avatar
Thiago Santini committed
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
                return;
            break;

        case QCamera::ActiveState:
            if (m_state == QCamera::UnloadedState) {
                if (!m_session->load())
                    break;
                m_state = QCamera::LoadedState;
            }

            if (state == QCamera::ActiveState)
                succeeded = m_session->startPreview();
            else
                succeeded = m_session->stopPreview();

            break;
    }

    if (succeeded) {
        m_state = state;
        emit stateChanged(m_state);
    }
}

bool UVCCameraControl::isCaptureModeSupported(QCamera::CaptureModes mode) const
{
    bool bCaptureSupported = false;
    switch (mode) {
    case QCamera::CaptureStillImage:
        bCaptureSupported = false;
        break;
    case QCamera::CaptureVideo:
        bCaptureSupported = false;
        break;
    }
    return bCaptureSupported;
}

void UVCCameraControl::setCaptureMode(QCamera::CaptureModes mode)
{
    if (m_captureMode != mode && isCaptureModeSupported(mode)) {
        m_captureMode = mode;
        emit captureModeChanged(mode);
    }
}

QCamera::Status UVCCameraControl::status() const
{
    return m_session->status();
}

QT_END_NAMESPACE