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
23 #include "qtcamdevice.h"
24 #include "qtcammode.h"
25 #include "qtcamimagemode.h"
26 #include "qtcamvideomode.h"
27 #include "qtcamgraphicsviewfinder.h"
28 #include "qtcamconfig.h"
29 #include "declarativeqtcameranotifications.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"
52 Camera::Camera(QDeclarativeItem *parent) :
53 QDeclarativeItem(parent),
54 m_cam(new QtCamera(this)),
56 m_vf(new QtCamGraphicsViewfinder(m_cam->config(), this)),
57 m_mode(Camera::UnknownMode),
58 m_notifications(new NotificationsContainer(this)),
69 m_flickerReduction(0),
76 QObject::connect(m_vf, SIGNAL(renderAreaChanged()), this, SIGNAL(renderAreaChanged()));
77 QObject::connect(m_vf, SIGNAL(videoResolutionChanged()), this, SIGNAL(videoResolutionChanged()));
78 QObject::connect(m_vf, SIGNAL(renderingEnabledChanged()), this, SIGNAL(renderingEnabledChanged()));
83 if (m_dev->activeMode()) {
84 m_dev->activeMode()->deactivate();
96 delete m_whiteBalance;
101 delete m_noiseReduction;
102 delete m_flickerReduction;
110 void Camera::componentComplete() {
111 QDeclarativeItem::componentComplete();
113 emit deviceCountChanged();
116 int Camera::deviceCount() const {
117 return m_cam ? m_cam->devices().size() : 0;
120 QString Camera::deviceName(int index) const {
121 return m_cam->devices().at(index).first;
124 QVariant Camera::deviceId(int index) const {
125 return m_cam->devices().at(index).second;
128 bool Camera::reset(const QVariant& deviceId, const CameraMode& mode) {
129 if (mode == Camera::UnknownMode) {
130 qmlInfo(this) << "Cannot set mode to unknown";
134 if (!isComponentComplete()) {
135 qmlInfo(this) << "Component is still not ready";
139 QVariant oldId = m_id;
140 Camera::CameraMode oldMode = m_mode;
142 if (setDeviceId(deviceId) && setMode(mode)) {
144 emit deviceIdChanged();
145 emit deviceChanged();
150 if (oldMode != m_mode) {
160 bool Camera::setDeviceId(const QVariant& deviceId) {
161 if (deviceId == m_id) {
165 if (m_dev && m_dev->stop(false)) {
169 qmlInfo(this) << "Failed to stop device";
173 m_dev = m_cam->device(deviceId, this);
177 m_vf->setDevice(m_dev);
179 QObject::connect(m_dev, SIGNAL(runningStateChanged(bool)),
180 this, SIGNAL(runningStateChanged()));
181 QObject::connect(m_dev, SIGNAL(idleStateChanged(bool)), this, SIGNAL(idleStateChanged()));
182 QObject::connect(m_dev, SIGNAL(error(const QString&, int, const QString&)),
183 this, SIGNAL(error(const QString&, int, const QString&)));
185 m_notifications->setDevice(m_dev);
190 QVariant Camera::deviceId() const {
194 void Camera::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
195 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
197 m_vf->setGeometry(newGeometry);
200 QtCamDevice *Camera::device() const {
204 bool Camera::setMode(const Camera::CameraMode& mode) {
205 if (m_mode == mode) {
215 if (m_dev->isRunning()) {
222 Camera::CameraMode Camera::mode() {
226 bool Camera::start() {
235 return m_dev->start();
238 bool Camera::stop(bool force) {
240 return m_dev->stop(force);
246 bool Camera::isIdle() {
247 return m_dev ? m_dev->isIdle() : true;
250 bool Camera::isRunning() {
251 return m_dev ? m_dev->isRunning() : false;
254 bool Camera::applyMode() {
255 if (m_mode == Camera::UnknownMode) {
259 if (m_mode == Camera::VideoMode && m_dev->activeMode() != m_dev->videoMode()) {
260 m_dev->videoMode()->activate();
262 else if (m_mode == Camera::ImageMode && m_dev->activeMode() != m_dev->imageMode()) {
263 m_dev->imageMode()->activate();
269 QString Camera::imageSuffix() const {
270 return m_cam->config()->imageSuffix();
273 QString Camera::videoSuffix() const {
274 return m_cam->config()->videoSuffix();
277 DeclarativeQtCameraNotifications *Camera::notifications() const {
278 return m_notifications->notifications();
281 void Camera::setNotifications(DeclarativeQtCameraNotifications *notifications) {
282 if (m_notifications->setNotifications(notifications)) {
284 if (Sounds *s = dynamic_cast<Sounds *>(notifications)) {
285 s->setConfig(m_cam->config());
289 emit notificationsChanged();
293 QRectF Camera::renderArea() const {
294 return m_vf->renderArea();
297 QSizeF Camera::videoResolution() const {
298 return m_vf->videoResolution();
301 void Camera::resetCapabilities() {
302 QtCamDevice *dev = device();
305 m_zoom = new Zoom(dev, this);
309 m_flash = new Flash(dev, this);
313 m_scene = new Scene(dev, this);
317 m_evComp = new EvComp(dev, this);
318 emit evCompChanged();
320 delete m_whiteBalance;
321 m_whiteBalance = new WhiteBalance(dev, this);
322 emit whiteBalanceChanged();
325 m_colorTone = new ColorTone(dev, this);
326 emit colorToneChanged();
329 m_iso = new Iso(dev, this);
333 m_exposure = new Exposure(dev, this);
334 emit exposureChanged();
337 m_aperture = new Aperture(dev, this);
338 emit apertureChanged();
340 delete m_noiseReduction;
341 m_noiseReduction = new NoiseReduction(dev, this);
342 emit noiseReductionChanged();
344 delete m_flickerReduction;
345 m_flickerReduction = new FlickerReduction(dev, this);
346 emit flickerReductionChanged();
349 m_focus = new Focus(dev, this);
353 m_autoFocus = new AutoFocus(dev, this);
354 emit autoFocusChanged();
357 m_roi = new Roi(dev, this);
361 m_videoMute = new VideoMute(dev, this);
362 emit videoMuteChanged();
365 m_videoTorch = new VideoTorch(dev, this);
366 emit videoTorchChanged();
369 Zoom *Camera::zoom() const {
373 Flash *Camera::flash() const {
377 Scene *Camera::scene() const {
381 EvComp *Camera::evComp() const {
385 WhiteBalance *Camera::whiteBalance() const {
386 return m_whiteBalance;
389 ColorTone *Camera::colorTone() const {
393 Iso *Camera::iso() const {
397 Exposure *Camera::exposure() const {
401 Aperture *Camera::aperture() const {
405 NoiseReduction *Camera::noiseReduction() const {
406 return m_noiseReduction;
409 FlickerReduction *Camera::flickerReduction() const {
410 return m_flickerReduction;
413 Focus *Camera::focus() const {
417 AutoFocus *Camera::autoFocus() const {
421 Roi *Camera::roi() const {
425 VideoMute *Camera::videoMute() const {
429 VideoTorch *Camera::videoTorch() const {
433 bool Camera::isRenderingEnabled() const {
434 return m_vf->isRenderingEnabled();
437 void Camera::setRenderingEnabled(bool enabled) {
438 m_vf->setRenderingEnabled(enabled);