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 "qtcamconfig.h"
29 #include "notificationscontainer.h"
32 #include <QDeclarativeInfo>
40 #include "whitebalance.h"
41 #include "colortone.h"
45 #include "noisereduction.h"
46 #include "flickerreduction.h"
48 #include "autofocus.h"
51 #include "videomute.h"
52 #include "videotorch.h"
53 #include "cameraconfig.h"
55 Camera::Camera(QObject *parent) :
57 m_cam(new QtCamera(this)),
59 m_mode(Camera::UnknownMode),
60 m_notifications(new NotificationsContainer(this)),
71 m_flickerReduction(0),
77 m_config(new CameraConfig(this)) {
79 m_config->componentComplete();
84 if (m_dev->activeMode()) {
85 m_dev->activeMode()->deactivate();
97 delete m_whiteBalance;
102 delete m_noiseReduction;
103 delete m_flickerReduction;
111 int Camera::deviceCount() const {
112 return m_cam ? m_cam->devices().size() : 0;
115 QString Camera::deviceName(int index) const {
116 return m_cam->devices().at(index).first;
119 QVariant Camera::deviceId(int index) const {
120 return m_cam->devices().at(index).second;
123 bool Camera::reset(const QVariant& deviceId, const CameraMode& mode) {
124 if (mode == Camera::UnknownMode) {
125 qmlInfo(this) << "Cannot set mode to unknown";
129 QVariant oldId = m_id;
130 Camera::CameraMode oldMode = m_mode;
132 if (setDeviceId(deviceId) && setMode(mode)) {
134 emit deviceIdChanged();
135 emit deviceChanged();
140 if (oldMode != m_mode) {
150 bool Camera::setDeviceId(const QVariant& deviceId) {
151 if (deviceId == m_id) {
155 if (m_dev && m_dev->stop(false)) {
159 qmlInfo(this) << "Failed to stop device";
163 m_dev = m_cam->device(deviceId, this);
167 QObject::connect(m_dev, SIGNAL(runningStateChanged(bool)),
168 this, SIGNAL(runningStateChanged()));
169 QObject::connect(m_dev, SIGNAL(idleStateChanged(bool)), this, SIGNAL(idleStateChanged()));
170 QObject::connect(m_dev, SIGNAL(error(const QString&, int, const QString&)),
171 this, SIGNAL(error(const QString&, int, const QString&)));
173 m_notifications->setDevice(m_dev);
178 QVariant Camera::deviceId() const {
182 QtCamDevice *Camera::device() const {
186 bool Camera::setMode(const Camera::CameraMode& mode) {
187 if (m_mode == mode) {
197 if (m_dev->isRunning()) {
204 Camera::CameraMode Camera::mode() {
208 bool Camera::start() {
217 return m_dev->start();
220 bool Camera::stop(bool force) {
222 return m_dev->stop(force);
228 bool Camera::isIdle() {
229 return m_dev ? m_dev->isIdle() : true;
232 bool Camera::isRunning() {
233 return m_dev ? m_dev->isRunning() : false;
236 bool Camera::applyMode() {
237 if (m_mode == Camera::UnknownMode) {
241 if (m_mode == Camera::VideoMode && m_dev->activeMode() != m_dev->videoMode()) {
242 m_dev->videoMode()->activate();
244 else if (m_mode == Camera::ImageMode && m_dev->activeMode() != m_dev->imageMode()) {
245 m_dev->imageMode()->activate();
251 QString Camera::imageSuffix() const {
252 return m_cam->config()->imageSuffix();
255 QString Camera::videoSuffix() const {
256 return m_cam->config()->videoSuffix();
259 Sounds *Camera::sounds() const {
260 return m_notifications->sounds();
262 void Camera::setSounds(Sounds *sounds) {
263 if (m_notifications->setSounds(sounds)) {
265 emit soundsChanged();
269 void Camera::resetCapabilities() {
270 QtCamDevice *dev = device();
273 m_zoom = new Zoom(dev, this);
277 m_flash = new Flash(dev, this);
281 m_scene = new Scene(dev, this);
285 m_evComp = new EvComp(dev, this);
286 emit evCompChanged();
288 delete m_whiteBalance;
289 m_whiteBalance = new WhiteBalance(dev, this);
290 emit whiteBalanceChanged();
293 m_colorTone = new ColorTone(dev, this);
294 emit colorToneChanged();
297 m_iso = new Iso(dev, this);
301 m_exposure = new Exposure(dev, this);
302 emit exposureChanged();
305 m_aperture = new Aperture(dev, this);
306 emit apertureChanged();
308 delete m_noiseReduction;
309 m_noiseReduction = new NoiseReduction(dev, this);
310 emit noiseReductionChanged();
312 delete m_flickerReduction;
313 m_flickerReduction = new FlickerReduction(dev, this);
314 emit flickerReductionChanged();
317 m_focus = new Focus(dev, this);
321 m_autoFocus = new AutoFocus(dev, this);
322 emit autoFocusChanged();
325 m_roi = new Roi(dev, this);
329 m_videoMute = new VideoMute(dev, this);
330 emit videoMuteChanged();
333 m_videoTorch = new VideoTorch(dev, this);
334 emit videoTorchChanged();
337 Zoom *Camera::zoom() const {
341 Flash *Camera::flash() const {
345 Scene *Camera::scene() const {
349 EvComp *Camera::evComp() const {
353 WhiteBalance *Camera::whiteBalance() const {
354 return m_whiteBalance;
357 ColorTone *Camera::colorTone() const {
361 Iso *Camera::iso() const {
365 Exposure *Camera::exposure() const {
369 Aperture *Camera::aperture() const {
373 NoiseReduction *Camera::noiseReduction() const {
374 return m_noiseReduction;
377 FlickerReduction *Camera::flickerReduction() const {
378 return m_flickerReduction;
381 Focus *Camera::focus() const {
385 AutoFocus *Camera::autoFocus() const {
389 Roi *Camera::roi() const {
393 VideoMute *Camera::videoMute() const {
397 VideoTorch *Camera::videoTorch() const {
401 CameraConfig *Camera::cameraConfig() const {