4 #include "qtcamdevice.h"
5 #include "previewprovider.h"
7 Mode::Mode(QObject *parent) :
20 Camera *Mode::camera() {
24 void Mode::setCamera(Camera *camera) {
25 if (camera == m_cam) {
30 QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
31 QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SIGNAL(isReadyChanged()));
37 QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
38 QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SIGNAL(isReadyChanged()));
45 emit isReadyChanged();
48 bool Mode::isActive() {
49 return m_mode ? m_mode->isActive() : false;
52 bool Mode::canCapture() {
53 return m_mode ? m_mode->canCapture() : false;
56 void Mode::deviceChanged() {
58 QObject::disconnect(m_mode, SIGNAL(canCaptureChanged()), this, SIGNAL(canCaptureChanged()));
59 QObject::disconnect(m_mode, SIGNAL(saved(const QString&)),
60 this, SIGNAL(saved(const QString&)));
61 QObject::disconnect(m_mode, SIGNAL(previewAvailable(const QImage&, const QString&)),
62 this, SLOT(gotPreview(const QImage&, const QString&)));
63 QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(activeChanged()));
64 QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(canCaptureChanged()));
65 QObject::disconnect(m_cam->device(), SIGNAL(idleStateChanged(bool)),
66 this, SIGNAL(canCaptureChanged()));
67 QObject::disconnect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
68 this, SIGNAL(canCaptureChanged()));
73 if (!m_cam || !m_cam->device()) {
80 QObject::connect(m_mode, SIGNAL(canCaptureChanged()), this, SIGNAL(canCaptureChanged()));
81 QObject::connect(m_mode, SIGNAL(saved(const QString&)), this, SIGNAL(saved(const QString&)));
82 QObject::connect(m_mode, SIGNAL(previewAvailable(const QImage&, const QString&)),
83 this, SLOT(gotPreview(const QImage&, const QString&)));
84 QObject::connect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(activeChanged()));
85 QObject::connect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(canCaptureChanged()));
86 QObject::connect(m_cam->device(), SIGNAL(idleStateChanged(bool)),
87 this, SIGNAL(canCaptureChanged()));
88 QObject::connect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
89 this, SIGNAL(canCaptureChanged()));
94 emit canCaptureChanged();
98 void Mode::gotPreview(const QImage& image, const QString& fileName) {
99 PreviewProvider::instance()->setPreview(image);
101 // HACK: QML insists on caching the images.
102 QString url = QString("image://preview/%1").arg(m_seq);
105 emit previewAvailable(url, fileName);
108 bool Mode::isReady() const {