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(QDeclarativeItem *parent) :
54 QDeclarativeItem(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 void Camera::componentComplete() {
110 QDeclarativeItem::componentComplete();
112 emit deviceCountChanged();
115 int Camera::deviceCount() const {
116 return m_cam ? m_cam->devices().size() : 0;
119 QString Camera::deviceName(int index) const {
120 return m_cam->devices().at(index).first;
123 QVariant Camera::deviceId(int index) const {
124 return m_cam->devices().at(index).second;
127 bool Camera::reset(const QVariant& deviceId, const CameraMode& mode) {
128 if (mode == Camera::UnknownMode) {
129 qmlInfo(this) << "Cannot set mode to unknown";
133 if (!isComponentComplete()) {
134 qmlInfo(this) << "Component is still not ready";
138 QVariant oldId = m_id;
139 Camera::CameraMode oldMode = m_mode;
141 if (setDeviceId(deviceId) && setMode(mode)) {
143 emit deviceIdChanged();
144 emit deviceChanged();
149 if (oldMode != m_mode) {
159 bool Camera::setDeviceId(const QVariant& deviceId) {
160 if (deviceId == m_id) {
164 if (m_dev && m_dev->stop(false)) {
168 qmlInfo(this) << "Failed to stop device";
172 m_dev = m_cam->device(deviceId, this);
176 QObject::connect(m_dev, SIGNAL(runningStateChanged(bool)),
177 this, SIGNAL(runningStateChanged()));
178 QObject::connect(m_dev, SIGNAL(idleStateChanged(bool)), this, SIGNAL(idleStateChanged()));
179 QObject::connect(m_dev, SIGNAL(error(const QString&, int, const QString&)),
180 this, SIGNAL(error(const QString&, int, const QString&)));
182 m_notifications->setDevice(m_dev);
187 QVariant Camera::deviceId() const {
191 QtCamDevice *Camera::device() const {
195 bool Camera::setMode(const Camera::CameraMode& mode) {
196 if (m_mode == mode) {
206 if (m_dev->isRunning()) {
213 Camera::CameraMode Camera::mode() {
217 bool Camera::start() {
226 return m_dev->start();
229 bool Camera::stop(bool force) {
231 return m_dev->stop(force);
237 bool Camera::isIdle() {
238 return m_dev ? m_dev->isIdle() : true;
241 bool Camera::isRunning() {
242 return m_dev ? m_dev->isRunning() : false;
245 bool Camera::applyMode() {
246 if (m_mode == Camera::UnknownMode) {
250 if (m_mode == Camera::VideoMode && m_dev->activeMode() != m_dev->videoMode()) {
251 m_dev->videoMode()->activate();
253 else if (m_mode == Camera::ImageMode && m_dev->activeMode() != m_dev->imageMode()) {
254 m_dev->imageMode()->activate();
260 QString Camera::imageSuffix() const {
261 return m_cam->config()->imageSuffix();
264 QString Camera::videoSuffix() const {
265 return m_cam->config()->videoSuffix();
268 Sounds *Camera::sounds() const {
269 return m_notifications->sounds();
271 void Camera::setSounds(Sounds *sounds) {
272 if (m_notifications->setSounds(sounds)) {
274 emit soundsChanged();
278 void Camera::resetCapabilities() {
279 QtCamDevice *dev = device();
282 m_zoom = new Zoom(dev, this);
286 m_flash = new Flash(dev, this);
290 m_scene = new Scene(dev, this);
294 m_evComp = new EvComp(dev, this);
295 emit evCompChanged();
297 delete m_whiteBalance;
298 m_whiteBalance = new WhiteBalance(dev, this);
299 emit whiteBalanceChanged();
302 m_colorTone = new ColorTone(dev, this);
303 emit colorToneChanged();
306 m_iso = new Iso(dev, this);
310 m_exposure = new Exposure(dev, this);
311 emit exposureChanged();
314 m_aperture = new Aperture(dev, this);
315 emit apertureChanged();
317 delete m_noiseReduction;
318 m_noiseReduction = new NoiseReduction(dev, this);
319 emit noiseReductionChanged();
321 delete m_flickerReduction;
322 m_flickerReduction = new FlickerReduction(dev, this);
323 emit flickerReductionChanged();
326 m_focus = new Focus(dev, this);
330 m_autoFocus = new AutoFocus(dev, this);
331 emit autoFocusChanged();
334 m_roi = new Roi(dev, this);
338 m_videoMute = new VideoMute(dev, this);
339 emit videoMuteChanged();
342 m_videoTorch = new VideoTorch(dev, this);
343 emit videoTorchChanged();
346 Zoom *Camera::zoom() const {
350 Flash *Camera::flash() const {
354 Scene *Camera::scene() const {
358 EvComp *Camera::evComp() const {
362 WhiteBalance *Camera::whiteBalance() const {
363 return m_whiteBalance;
366 ColorTone *Camera::colorTone() const {
370 Iso *Camera::iso() const {
374 Exposure *Camera::exposure() const {
378 Aperture *Camera::aperture() const {
382 NoiseReduction *Camera::noiseReduction() const {
383 return m_noiseReduction;
386 FlickerReduction *Camera::flickerReduction() const {
387 return m_flickerReduction;
390 Focus *Camera::focus() const {
394 AutoFocus *Camera::autoFocus() const {
398 Roi *Camera::roi() const {
402 VideoMute *Camera::videoMute() const {
406 VideoTorch *Camera::videoTorch() const {
410 CameraConfig *Camera::cameraConfig() const {