2 * This file is part of CameraPlus.
4 * Copyright (C) 2012-2013 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
23 #include "qtcamdevice.h"
24 #include "qtcammode.h"
25 #include "qtcamimagemode.h"
26 #include "qtcamvideomode.h"
27 #include "qtcamgraphicsviewfinder.h"
28 #include "qtcamconfig.h"
30 #include "notificationscontainer.h"
32 #include <QDeclarativeInfo>
38 #include "whitebalance.h"
39 #include "colortone.h"
43 #include "noisereduction.h"
44 #include "flickerreduction.h"
46 #include "autofocus.h"
49 #include "videomute.h"
50 #include "videotorch.h"
51 #include "cameraconfig.h"
53 Camera::Camera(QObject *parent) :
55 m_cam(new QtCamera(this)),
57 m_mode(Camera::UnknownMode),
58 m_notifications(new NotificationsContainer(this)),
69 m_flickerReduction(0),
75 m_config(new CameraConfig(this)) {
77 m_config->componentComplete();
82 if (m_dev->activeMode()) {
83 m_dev->activeMode()->deactivate();
95 delete m_whiteBalance;
100 delete m_noiseReduction;
101 delete m_flickerReduction;
109 int Camera::deviceCount() const {
110 return m_cam ? m_cam->devices().size() : 0;
113 QString Camera::deviceName(int index) const {
114 return m_cam->devices().at(index).first;
117 QVariant Camera::deviceId(int index) const {
118 return m_cam->devices().at(index).second;
121 bool Camera::reset(const QVariant& deviceId, const CameraMode& mode) {
122 if (mode == Camera::UnknownMode) {
123 qmlInfo(this) << "Cannot set mode to unknown";
127 QVariant oldId = m_id;
128 Camera::CameraMode oldMode = m_mode;
130 if (setDeviceId(deviceId) && setMode(mode)) {
132 emit deviceIdChanged();
133 emit deviceChanged();
138 if (oldMode != m_mode) {
148 bool Camera::setDeviceId(const QVariant& deviceId) {
149 if (deviceId == m_id) {
153 if (m_dev && m_dev->stop(false)) {
157 qmlInfo(this) << "Failed to stop device";
161 m_dev = m_cam->device(deviceId, this);
165 QObject::connect(m_dev, SIGNAL(runningStateChanged(bool)),
166 this, SIGNAL(runningStateChanged()));
167 QObject::connect(m_dev, SIGNAL(idleStateChanged(bool)), this, SIGNAL(idleStateChanged()));
168 QObject::connect(m_dev, SIGNAL(error(const QString&, int, const QString&)),
169 this, SIGNAL(error(const QString&, int, const QString&)));
171 m_notifications->setDevice(m_dev);
176 QVariant Camera::deviceId() const {
180 QtCamDevice *Camera::device() const {
184 bool Camera::setMode(const Camera::CameraMode& mode) {
185 if (m_mode == mode) {
195 if (m_dev->isRunning()) {
202 Camera::CameraMode Camera::mode() {
206 bool Camera::start() {
215 return m_dev->start();
218 bool Camera::stop(bool force) {
220 return m_dev->stop(force);
226 bool Camera::isIdle() {
227 return m_dev ? m_dev->isIdle() : true;
230 bool Camera::isRunning() {
231 return m_dev ? m_dev->isRunning() : false;
234 bool Camera::applyMode() {
235 if (m_mode == Camera::UnknownMode) {
239 if (m_mode == Camera::VideoMode && m_dev->activeMode() != m_dev->videoMode()) {
240 m_dev->videoMode()->activate();
242 else if (m_mode == Camera::ImageMode && m_dev->activeMode() != m_dev->imageMode()) {
243 m_dev->imageMode()->activate();
249 QString Camera::imageSuffix() const {
250 return m_cam->config()->imageSuffix();
253 QString Camera::videoSuffix() const {
254 return m_cam->config()->videoSuffix();
257 Sounds *Camera::sounds() const {
258 return m_notifications->sounds();
260 void Camera::setSounds(Sounds *sounds) {
261 if (m_notifications->setSounds(sounds)) {
263 emit soundsChanged();
267 void Camera::resetCapabilities() {
268 QtCamDevice *dev = device();
271 m_zoom = new Zoom(dev, this);
275 m_flash = new Flash(dev, this);
279 m_scene = new Scene(dev, this);
283 m_evComp = new EvComp(dev, this);
284 emit evCompChanged();
286 delete m_whiteBalance;
287 m_whiteBalance = new WhiteBalance(dev, this);
288 emit whiteBalanceChanged();
291 m_colorTone = new ColorTone(dev, this);
292 emit colorToneChanged();
295 m_iso = new Iso(dev, this);
299 m_exposure = new Exposure(dev, this);
300 emit exposureChanged();
303 m_aperture = new Aperture(dev, this);
304 emit apertureChanged();
306 delete m_noiseReduction;
307 m_noiseReduction = new NoiseReduction(dev, this);
308 emit noiseReductionChanged();
310 delete m_flickerReduction;
311 m_flickerReduction = new FlickerReduction(dev, this);
312 emit flickerReductionChanged();
315 m_focus = new Focus(dev, this);
319 m_autoFocus = new AutoFocus(dev, this);
320 emit autoFocusChanged();
323 m_roi = new Roi(dev, this);
327 m_videoMute = new VideoMute(dev, this);
328 emit videoMuteChanged();
331 m_videoTorch = new VideoTorch(dev, this);
332 emit videoTorchChanged();
335 Zoom *Camera::zoom() const {
339 Flash *Camera::flash() const {
343 Scene *Camera::scene() const {
347 EvComp *Camera::evComp() const {
351 WhiteBalance *Camera::whiteBalance() const {
352 return m_whiteBalance;
355 ColorTone *Camera::colorTone() const {
359 Iso *Camera::iso() const {
363 Exposure *Camera::exposure() const {
367 Aperture *Camera::aperture() const {
371 NoiseReduction *Camera::noiseReduction() const {
372 return m_noiseReduction;
375 FlickerReduction *Camera::flickerReduction() const {
376 return m_flickerReduction;
379 Focus *Camera::focus() const {
383 AutoFocus *Camera::autoFocus() const {
387 Roi *Camera::roi() const {
391 VideoMute *Camera::videoMute() const {
395 VideoTorch *Camera::videoTorch() const {
399 CameraConfig *Camera::cameraConfig() const {