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()));
69 QObject::disconnect(m_mode, SIGNAL(nightModeChanged()), this, SIGNAL(nightModeChanged()));
74 if (!m_cam || !m_cam->device()) {
81 QObject::connect(m_mode, SIGNAL(canCaptureChanged()), this, SIGNAL(canCaptureChanged()));
82 QObject::connect(m_mode, SIGNAL(saved(const QString&)), this, SIGNAL(saved(const QString&)));
83 QObject::connect(m_mode, SIGNAL(previewAvailable(const QImage&, const QString&)),
84 this, SLOT(gotPreview(const QImage&, const QString&)));
85 QObject::connect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(activeChanged()));
86 QObject::connect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(canCaptureChanged()));
87 QObject::connect(m_cam->device(), SIGNAL(idleStateChanged(bool)),
88 this, SIGNAL(canCaptureChanged()));
89 QObject::connect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
90 this, SIGNAL(canCaptureChanged()));
91 QObject::connect(m_mode, SIGNAL(nightModeChanged()), this, SIGNAL(nightModeChanged()));
96 emit canCaptureChanged();
100 void Mode::gotPreview(const QImage& image, const QString& fileName) {
101 PreviewProvider::instance()->setPreview(image);
103 // HACK: QML insists on caching the images.
104 QString url = QString("image://preview/%1").arg(m_seq);
107 emit previewAvailable(url, fileName);
110 void Mode::setNightMode(bool night) {
112 m_mode->setNightMode(night);
116 bool Mode::inNightMode() const {
117 return m_mode ? m_mode->inNightMode() : false;
120 bool Mode::isReady() const {