2 * This file is part of CameraPlus.
4 * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "qtcammode.h"
24 #include "qtcamdevice.h"
25 #include "previewprovider.h"
27 Mode::Mode(QObject *parent) :
40 Camera *Mode::camera() {
44 void Mode::setCamera(Camera *camera) {
45 if (camera == m_cam) {
50 QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
51 QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SIGNAL(isReadyChanged()));
57 QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
58 QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SIGNAL(isReadyChanged()));
65 emit isReadyChanged();
68 bool Mode::isActive() {
69 return m_mode ? m_mode->isActive() : false;
72 bool Mode::canCapture() {
73 return m_mode ? m_mode->canCapture() : false;
76 void Mode::deviceChanged() {
78 QObject::disconnect(m_mode, SIGNAL(canCaptureChanged()), this, SIGNAL(canCaptureChanged()));
79 QObject::disconnect(m_mode, SIGNAL(saved(const QString&)),
80 this, SIGNAL(saved(const QString&)));
81 QObject::disconnect(m_mode, SIGNAL(previewAvailable(const QImage&, const QString&)),
82 this, SLOT(gotPreview(const QImage&, const QString&)));
83 QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(activeChanged()));
84 QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(canCaptureChanged()));
85 QObject::disconnect(m_cam->device(), SIGNAL(idleStateChanged(bool)),
86 this, SIGNAL(canCaptureChanged()));
87 QObject::disconnect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
88 this, SIGNAL(canCaptureChanged()));
93 if (!m_cam || !m_cam->device()) {
100 QObject::connect(m_mode, SIGNAL(canCaptureChanged()), this, SIGNAL(canCaptureChanged()));
101 QObject::connect(m_mode, SIGNAL(saved(const QString&)), this, SIGNAL(saved(const QString&)));
102 QObject::connect(m_mode, SIGNAL(previewAvailable(const QImage&, const QString&)),
103 this, SLOT(gotPreview(const QImage&, const QString&)));
104 QObject::connect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(activeChanged()));
105 QObject::connect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(canCaptureChanged()));
106 QObject::connect(m_cam->device(), SIGNAL(idleStateChanged(bool)),
107 this, SIGNAL(canCaptureChanged()));
108 QObject::connect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
109 this, SIGNAL(canCaptureChanged()));
114 emit canCaptureChanged();
115 emit activeChanged();
118 void Mode::gotPreview(const QImage& image, const QString& fileName) {
119 PreviewProvider::instance()->setPreview(image);
121 // HACK: QML insists on caching the images.
122 QString url = QString("image://preview/%1").arg(m_seq);
125 emit previewAvailable(url, fileName);
128 bool Mode::isReady() const {