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 "notifications.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"
48 #include "videomute.h"
49 #include "videotorch.h"
51 Camera::Camera(QDeclarativeItem *parent) :
52 QDeclarativeItem(parent),
53 m_cam(new QtCamera(this)),
55 m_vf(new QtCamGraphicsViewfinder(m_cam->config(), this)),
56 m_mode(Camera::UnknownMode),
57 m_notifications(new NotificationsContainer(this)),
68 m_flickerReduction(0),
74 QObject::connect(m_vf, SIGNAL(renderAreaChanged()), this, SIGNAL(renderAreaChanged()));
75 QObject::connect(m_vf, SIGNAL(videoResolutionChanged()), this, SIGNAL(videoResolutionChanged()));
89 delete m_whiteBalance;
94 delete m_noiseReduction;
95 delete m_flickerReduction;
103 void Camera::componentComplete() {
104 QDeclarativeItem::componentComplete();
106 emit deviceCountChanged();
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 if (!isComponentComplete()) {
128 qmlInfo(this) << "Component is still not ready";
132 QVariant oldId = m_id;
133 Camera::CameraMode oldMode = m_mode;
135 if (setDeviceId(deviceId) && setMode(mode)) {
137 emit deviceIdChanged();
138 emit deviceChanged();
143 if (oldMode != m_mode) {
153 bool Camera::setDeviceId(const QVariant& deviceId) {
154 if (deviceId == m_id) {
158 if (m_dev && m_dev->stop(false)) {
162 qmlInfo(this) << "Failed to stop device";
166 m_dev = m_cam->device(deviceId, this);
170 m_vf->setDevice(m_dev);
172 QObject::connect(m_dev, SIGNAL(runningStateChanged(bool)),
173 this, SIGNAL(runningStateChanged()));
174 QObject::connect(m_dev, SIGNAL(idleStateChanged(bool)), this, SIGNAL(idleStateChanged()));
175 QObject::connect(m_dev, SIGNAL(error(const QString&, int, const QString&)),
176 this, SIGNAL(error(const QString&, int, const QString&)));
178 m_notifications->setDevice(m_dev);
183 QVariant Camera::deviceId() const {
187 void Camera::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
188 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
190 m_vf->setGeometry(newGeometry);
193 QtCamDevice *Camera::device() const {
197 bool Camera::setMode(const Camera::CameraMode& mode) {
198 if (m_mode == mode) {
208 if (m_dev->isRunning()) {
215 Camera::CameraMode Camera::mode() {
219 bool Camera::start() {
228 return m_dev->start();
231 bool Camera::stop(bool force) {
233 return m_dev->stop(force);
239 bool Camera::isIdle() {
240 return m_dev ? m_dev->isIdle() : true;
243 bool Camera::isRunning() {
244 return m_dev ? m_dev->isRunning() : false;
247 bool Camera::applyMode() {
248 if (m_mode == Camera::UnknownMode) {
252 if (m_mode == Camera::VideoMode && m_dev->activeMode() != m_dev->videoMode()) {
253 m_dev->videoMode()->activate();
255 else if (m_mode == Camera::ImageMode && m_dev->activeMode() != m_dev->imageMode()) {
256 m_dev->imageMode()->activate();
262 QString Camera::imageSuffix() const {
263 return m_cam->config()->imageSuffix();
266 QString Camera::videoSuffix() const {
267 return m_cam->config()->videoSuffix();
270 Notifications *Camera::notifications() const {
271 return m_notifications->notifications();
274 void Camera::setNotifications(Notifications *notifications) {
275 if (m_notifications->setNotifications(notifications)) {
277 if (Sounds *s = dynamic_cast<Sounds *>(notifications)) {
278 s->setConfig(m_cam->config());
282 emit notificationsChanged();
286 QRectF Camera::renderArea() const {
287 return m_vf->renderArea();
290 QSizeF Camera::videoResolution() const {
291 return m_vf->videoResolution();
294 void Camera::resetCapabilities() {
295 QtCamDevice *dev = device();
298 m_zoom = new Zoom(dev, this);
302 m_flash = new Flash(dev, this);
306 m_scene = new Scene(dev, this);
310 m_evComp = new EvComp(dev, this);
311 emit evCompChanged();
313 delete m_whiteBalance;
314 m_whiteBalance = new WhiteBalance(dev, this);
315 emit whiteBalanceChanged();
318 m_colorTone = new ColorTone(dev, this);
319 emit colorToneChanged();
322 m_iso = new Iso(dev, this);
326 m_exposure = new Exposure(dev, this);
327 emit exposureChanged();
330 m_aperture = new Aperture(dev, this);
331 emit apertureChanged();
333 delete m_noiseReduction;
334 m_noiseReduction = new NoiseReduction(dev, this);
335 emit noiseReductionChanged();
337 delete m_flickerReduction;
338 m_flickerReduction = new FlickerReduction(dev, this);
339 emit flickerReductionChanged();
342 m_focus = new Focus(dev, this);
346 m_autoFocus = new AutoFocus(dev, this);
347 emit autoFocusChanged();
350 m_videoMute = new VideoMute(dev, this);
351 emit videoMuteChanged();
354 m_videoTorch = new VideoTorch(dev, this);
355 emit videoTorchChanged();
358 Zoom *Camera::zoom() const {
362 Flash *Camera::flash() const {
366 Scene *Camera::scene() const {
370 EvComp *Camera::evComp() const {
374 WhiteBalance *Camera::whiteBalance() const {
375 return m_whiteBalance;
378 ColorTone *Camera::colorTone() const {
382 Iso *Camera::iso() const {
386 Exposure *Camera::exposure() const {
390 Aperture *Camera::aperture() const {
394 NoiseReduction *Camera::noiseReduction() const {
395 return m_noiseReduction;
398 FlickerReduction *Camera::flickerReduction() const {
399 return m_flickerReduction;
402 Focus *Camera::focus() const {
406 AutoFocus *Camera::autoFocus() const {
410 VideoMute *Camera::videoMute() const {
414 VideoTorch *Camera::videoTorch() const {