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()));
90 delete m_whiteBalance;
95 delete m_noiseReduction;
96 delete m_flickerReduction;
104 void Camera::componentComplete() {
105 QDeclarativeItem::componentComplete();
107 emit deviceCountChanged();
110 int Camera::deviceCount() const {
111 return m_cam ? m_cam->devices().size() : 0;
114 QString Camera::deviceName(int index) const {
115 return m_cam->devices().at(index).first;
118 QVariant Camera::deviceId(int index) const {
119 return m_cam->devices().at(index).second;
122 bool Camera::reset(const QVariant& deviceId, const CameraMode& mode) {
123 if (mode == Camera::UnknownMode) {
124 qmlInfo(this) << "Cannot set mode to unknown";
128 if (!isComponentComplete()) {
129 qmlInfo(this) << "Component is still not ready";
133 QVariant oldId = m_id;
134 Camera::CameraMode oldMode = m_mode;
136 if (setDeviceId(deviceId) && setMode(mode)) {
138 emit deviceIdChanged();
139 emit deviceChanged();
144 if (oldMode != m_mode) {
154 bool Camera::setDeviceId(const QVariant& deviceId) {
155 if (deviceId == m_id) {
159 if (m_dev && m_dev->stop(false)) {
163 qmlInfo(this) << "Failed to stop device";
167 m_dev = m_cam->device(deviceId, this);
171 m_vf->setDevice(m_dev);
173 QObject::connect(m_dev, SIGNAL(runningStateChanged(bool)),
174 this, SIGNAL(runningStateChanged()));
175 QObject::connect(m_dev, SIGNAL(idleStateChanged(bool)), this, SIGNAL(idleStateChanged()));
176 QObject::connect(m_dev, SIGNAL(error(const QString&, int, const QString&)),
177 this, SIGNAL(error(const QString&, int, const QString&)));
179 m_notifications->setDevice(m_dev);
184 QVariant Camera::deviceId() const {
188 void Camera::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
189 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
191 m_vf->setGeometry(newGeometry);
194 QtCamDevice *Camera::device() const {
198 bool Camera::setMode(const Camera::CameraMode& mode) {
199 if (m_mode == mode) {
209 if (m_dev->isRunning()) {
216 Camera::CameraMode Camera::mode() {
220 bool Camera::start() {
229 return m_dev->start();
232 bool Camera::stop(bool force) {
234 return m_dev->stop(force);
240 bool Camera::isIdle() {
241 return m_dev ? m_dev->isIdle() : true;
244 bool Camera::isRunning() {
245 return m_dev ? m_dev->isRunning() : false;
248 bool Camera::applyMode() {
249 if (m_mode == Camera::UnknownMode) {
253 if (m_mode == Camera::VideoMode && m_dev->activeMode() != m_dev->videoMode()) {
254 m_dev->videoMode()->activate();
256 else if (m_mode == Camera::ImageMode && m_dev->activeMode() != m_dev->imageMode()) {
257 m_dev->imageMode()->activate();
263 QString Camera::imageSuffix() const {
264 return m_cam->config()->imageSuffix();
267 QString Camera::videoSuffix() const {
268 return m_cam->config()->videoSuffix();
271 Notifications *Camera::notifications() const {
272 return m_notifications->notifications();
275 void Camera::setNotifications(Notifications *notifications) {
276 if (m_notifications->setNotifications(notifications)) {
278 if (Sounds *s = dynamic_cast<Sounds *>(notifications)) {
279 s->setConfig(m_cam->config());
283 emit notificationsChanged();
287 QRectF Camera::renderArea() const {
288 return m_vf->renderArea();
291 QSizeF Camera::videoResolution() const {
292 return m_vf->videoResolution();
295 void Camera::resetCapabilities() {
296 QtCamDevice *dev = device();
299 m_zoom = new Zoom(dev, this);
303 m_flash = new Flash(dev, this);
307 m_scene = new Scene(dev, this);
311 m_evComp = new EvComp(dev, this);
312 emit evCompChanged();
314 delete m_whiteBalance;
315 m_whiteBalance = new WhiteBalance(dev, this);
316 emit whiteBalanceChanged();
319 m_colorTone = new ColorTone(dev, this);
320 emit colorToneChanged();
323 m_iso = new Iso(dev, this);
327 m_exposure = new Exposure(dev, this);
328 emit exposureChanged();
331 m_aperture = new Aperture(dev, this);
332 emit apertureChanged();
334 delete m_noiseReduction;
335 m_noiseReduction = new NoiseReduction(dev, this);
336 emit noiseReductionChanged();
338 delete m_flickerReduction;
339 m_flickerReduction = new FlickerReduction(dev, this);
340 emit flickerReductionChanged();
343 m_focus = new Focus(dev, this);
347 m_autoFocus = new AutoFocus(dev, this);
348 emit autoFocusChanged();
351 m_videoMute = new VideoMute(dev, this);
352 emit videoMuteChanged();
355 m_videoTorch = new VideoTorch(dev, this);
356 emit videoTorchChanged();
359 Zoom *Camera::zoom() const {
363 Flash *Camera::flash() const {
367 Scene *Camera::scene() const {
371 EvComp *Camera::evComp() const {
375 WhiteBalance *Camera::whiteBalance() const {
376 return m_whiteBalance;
379 ColorTone *Camera::colorTone() const {
383 Iso *Camera::iso() const {
387 Exposure *Camera::exposure() const {
391 Aperture *Camera::aperture() const {
395 NoiseReduction *Camera::noiseReduction() const {
396 return m_noiseReduction;
399 FlickerReduction *Camera::flickerReduction() const {
400 return m_flickerReduction;
403 Focus *Camera::focus() const {
407 AutoFocus *Camera::autoFocus() const {
411 VideoMute *Camera::videoMute() const {
415 VideoTorch *Camera::videoTorch() const {
419 bool Camera::isRenderingEnabled() const {
420 return m_vf->isRenderingEnabled();
423 void Camera::setRenderingEnabled(bool enabled) {
424 m_vf->setRenderingEnabled(enabled);