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()));
76 QObject::connect(m_vf, SIGNAL(renderingEnabledChanged()), this, SIGNAL(renderingEnabledChanged()));
81 if (m_dev->activeMode()) {
82 m_dev->activeMode()->deactivate();
94 delete m_whiteBalance;
99 delete m_noiseReduction;
100 delete m_flickerReduction;
108 void Camera::componentComplete() {
109 QDeclarativeItem::componentComplete();
111 emit deviceCountChanged();
114 int Camera::deviceCount() const {
115 return m_cam ? m_cam->devices().size() : 0;
118 QString Camera::deviceName(int index) const {
119 return m_cam->devices().at(index).first;
122 QVariant Camera::deviceId(int index) const {
123 return m_cam->devices().at(index).second;
126 bool Camera::reset(const QVariant& deviceId, const CameraMode& mode) {
127 if (mode == Camera::UnknownMode) {
128 qmlInfo(this) << "Cannot set mode to unknown";
132 if (!isComponentComplete()) {
133 qmlInfo(this) << "Component is still not ready";
137 QVariant oldId = m_id;
138 Camera::CameraMode oldMode = m_mode;
140 if (setDeviceId(deviceId) && setMode(mode)) {
142 emit deviceIdChanged();
143 emit deviceChanged();
148 if (oldMode != m_mode) {
158 bool Camera::setDeviceId(const QVariant& deviceId) {
159 if (deviceId == m_id) {
163 if (m_dev && m_dev->stop(false)) {
167 qmlInfo(this) << "Failed to stop device";
171 m_dev = m_cam->device(deviceId, this);
175 m_vf->setDevice(m_dev);
177 QObject::connect(m_dev, SIGNAL(runningStateChanged(bool)),
178 this, SIGNAL(runningStateChanged()));
179 QObject::connect(m_dev, SIGNAL(idleStateChanged(bool)), this, SIGNAL(idleStateChanged()));
180 QObject::connect(m_dev, SIGNAL(error(const QString&, int, const QString&)),
181 this, SIGNAL(error(const QString&, int, const QString&)));
183 m_notifications->setDevice(m_dev);
188 QVariant Camera::deviceId() const {
192 void Camera::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
193 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
195 m_vf->setGeometry(newGeometry);
198 QtCamDevice *Camera::device() const {
202 bool Camera::setMode(const Camera::CameraMode& mode) {
203 if (m_mode == mode) {
213 if (m_dev->isRunning()) {
220 Camera::CameraMode Camera::mode() {
224 bool Camera::start() {
233 return m_dev->start();
236 bool Camera::stop(bool force) {
238 return m_dev->stop(force);
244 bool Camera::isIdle() {
245 return m_dev ? m_dev->isIdle() : true;
248 bool Camera::isRunning() {
249 return m_dev ? m_dev->isRunning() : false;
252 bool Camera::applyMode() {
253 if (m_mode == Camera::UnknownMode) {
257 if (m_mode == Camera::VideoMode && m_dev->activeMode() != m_dev->videoMode()) {
258 m_dev->videoMode()->activate();
260 else if (m_mode == Camera::ImageMode && m_dev->activeMode() != m_dev->imageMode()) {
261 m_dev->imageMode()->activate();
267 QString Camera::imageSuffix() const {
268 return m_cam->config()->imageSuffix();
271 QString Camera::videoSuffix() const {
272 return m_cam->config()->videoSuffix();
275 Notifications *Camera::notifications() const {
276 return m_notifications->notifications();
279 void Camera::setNotifications(Notifications *notifications) {
280 if (m_notifications->setNotifications(notifications)) {
282 if (Sounds *s = dynamic_cast<Sounds *>(notifications)) {
283 s->setConfig(m_cam->config());
287 emit notificationsChanged();
291 QRectF Camera::renderArea() const {
292 return m_vf->renderArea();
295 QSizeF Camera::videoResolution() const {
296 return m_vf->videoResolution();
299 void Camera::resetCapabilities() {
300 QtCamDevice *dev = device();
303 m_zoom = new Zoom(dev, this);
307 m_flash = new Flash(dev, this);
311 m_scene = new Scene(dev, this);
315 m_evComp = new EvComp(dev, this);
316 emit evCompChanged();
318 delete m_whiteBalance;
319 m_whiteBalance = new WhiteBalance(dev, this);
320 emit whiteBalanceChanged();
323 m_colorTone = new ColorTone(dev, this);
324 emit colorToneChanged();
327 m_iso = new Iso(dev, this);
331 m_exposure = new Exposure(dev, this);
332 emit exposureChanged();
335 m_aperture = new Aperture(dev, this);
336 emit apertureChanged();
338 delete m_noiseReduction;
339 m_noiseReduction = new NoiseReduction(dev, this);
340 emit noiseReductionChanged();
342 delete m_flickerReduction;
343 m_flickerReduction = new FlickerReduction(dev, this);
344 emit flickerReductionChanged();
347 m_focus = new Focus(dev, this);
351 m_autoFocus = new AutoFocus(dev, this);
352 emit autoFocusChanged();
355 m_videoMute = new VideoMute(dev, this);
356 emit videoMuteChanged();
359 m_videoTorch = new VideoTorch(dev, this);
360 emit videoTorchChanged();
363 Zoom *Camera::zoom() const {
367 Flash *Camera::flash() const {
371 Scene *Camera::scene() const {
375 EvComp *Camera::evComp() const {
379 WhiteBalance *Camera::whiteBalance() const {
380 return m_whiteBalance;
383 ColorTone *Camera::colorTone() const {
387 Iso *Camera::iso() const {
391 Exposure *Camera::exposure() const {
395 Aperture *Camera::aperture() const {
399 NoiseReduction *Camera::noiseReduction() const {
400 return m_noiseReduction;
403 FlickerReduction *Camera::flickerReduction() const {
404 return m_flickerReduction;
407 Focus *Camera::focus() const {
411 AutoFocus *Camera::autoFocus() const {
415 VideoMute *Camera::videoMute() const {
419 VideoTorch *Camera::videoTorch() const {
423 bool Camera::isRenderingEnabled() const {
424 return m_vf->isRenderingEnabled();
427 void Camera::setRenderingEnabled(bool enabled) {
428 m_vf->setRenderingEnabled(enabled);