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)) {
156 emit prepareForDeviceChange();
160 qmlInfo(this) << "Failed to stop device";
164 m_dev = m_cam->device(deviceId, this);
168 QObject::connect(m_dev, SIGNAL(runningStateChanged(bool)),
169 this, SIGNAL(runningStateChanged()));
170 QObject::connect(m_dev, SIGNAL(idleStateChanged(bool)), this, SIGNAL(idleStateChanged()));
171 QObject::connect(m_dev, SIGNAL(error(const QString&, int, const QString&)),
172 this, SIGNAL(error(const QString&, int, const QString&)));
174 m_notifications->setDevice(m_dev);
179 QVariant Camera::deviceId() const {
183 QtCamDevice *Camera::device() const {
187 bool Camera::setMode(const Camera::CameraMode& mode) {
188 if (m_mode == mode) {
198 if (m_dev->isRunning()) {
205 Camera::CameraMode Camera::mode() {
209 bool Camera::start() {
218 return m_dev->start();
221 bool Camera::stop(bool force) {
223 return m_dev->stop(force);
229 bool Camera::isIdle() {
230 return m_dev ? m_dev->isIdle() : true;
233 bool Camera::isRunning() {
234 return m_dev ? m_dev->isRunning() : false;
237 bool Camera::applyMode() {
238 if (m_mode == Camera::UnknownMode) {
242 if (m_mode == Camera::VideoMode && m_dev->activeMode() != m_dev->videoMode()) {
243 m_dev->videoMode()->activate();
245 else if (m_mode == Camera::ImageMode && m_dev->activeMode() != m_dev->imageMode()) {
246 m_dev->imageMode()->activate();
252 QString Camera::imageSuffix() const {
253 return m_cam->config()->imageSuffix();
256 QString Camera::videoSuffix() const {
257 return m_cam->config()->videoSuffix();
260 Sounds *Camera::sounds() const {
261 return m_notifications->sounds();
263 void Camera::setSounds(Sounds *sounds) {
264 if (m_notifications->setSounds(sounds)) {
266 emit soundsChanged();
270 void Camera::resetCapabilities() {
271 QtCamDevice *dev = device();
274 m_zoom = new Zoom(dev, this);
278 m_flash = new Flash(dev, this);
282 m_scene = new Scene(dev, this);
286 m_evComp = new EvComp(dev, this);
287 emit evCompChanged();
289 delete m_whiteBalance;
290 m_whiteBalance = new WhiteBalance(dev, this);
291 emit whiteBalanceChanged();
294 m_colorTone = new ColorTone(dev, this);
295 emit colorToneChanged();
298 m_iso = new Iso(dev, this);
302 m_exposure = new Exposure(dev, this);
303 emit exposureChanged();
306 m_aperture = new Aperture(dev, this);
307 emit apertureChanged();
309 delete m_noiseReduction;
310 m_noiseReduction = new NoiseReduction(dev, this);
311 emit noiseReductionChanged();
313 delete m_flickerReduction;
314 m_flickerReduction = new FlickerReduction(dev, this);
315 emit flickerReductionChanged();
318 m_focus = new Focus(dev, this);
322 m_autoFocus = new AutoFocus(dev, this);
323 emit autoFocusChanged();
326 m_roi = new Roi(dev, this);
330 m_videoMute = new VideoMute(dev, this);
331 emit videoMuteChanged();
334 m_videoTorch = new VideoTorch(dev, this);
335 emit videoTorchChanged();
338 Zoom *Camera::zoom() const {
342 Flash *Camera::flash() const {
346 Scene *Camera::scene() const {
350 EvComp *Camera::evComp() const {
354 WhiteBalance *Camera::whiteBalance() const {
355 return m_whiteBalance;
358 ColorTone *Camera::colorTone() const {
362 Iso *Camera::iso() const {
366 Exposure *Camera::exposure() const {
370 Aperture *Camera::aperture() const {
374 NoiseReduction *Camera::noiseReduction() const {
375 return m_noiseReduction;
378 FlickerReduction *Camera::flickerReduction() const {
379 return m_flickerReduction;
382 Focus *Camera::focus() const {
386 AutoFocus *Camera::autoFocus() const {
390 Roi *Camera::roi() const {
394 VideoMute *Camera::videoMute() const {
398 VideoTorch *Camera::videoTorch() const {
402 CameraConfig *Camera::cameraConfig() const {