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 // TODO: a viewfinder class that inherits QDeclarativeItem
53 Camera::Camera(QDeclarativeItem *parent) :
54 QDeclarativeItem(parent),
55 m_cam(new QtCamera(this)),
57 m_vf(new QtCamGraphicsViewfinder(m_cam->config(), this)),
58 m_mode(Camera::UnknownMode),
59 m_notifications(new NotificationsContainer(this)),
70 m_flickerReduction(0),
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 void Camera::resetCapabilities() {
288 QtCamDevice *dev = device();
291 m_zoom = new Zoom(dev, this);
295 m_flash = new Flash(dev, this);
299 m_scene = new Scene(dev, this);
303 m_evComp = new EvComp(dev, this);
304 emit evCompChanged();
306 delete m_whiteBalance;
307 m_whiteBalance = new WhiteBalance(dev, this);
308 emit whiteBalanceChanged();
311 m_colorTone = new ColorTone(dev, this);
312 emit colorToneChanged();
315 m_iso = new Iso(dev, this);
319 m_exposure = new Exposure(dev, this);
320 emit exposureChanged();
323 m_aperture = new Aperture(dev, this);
324 emit apertureChanged();
326 delete m_noiseReduction;
327 m_noiseReduction = new NoiseReduction(dev, this);
328 emit noiseReductionChanged();
330 delete m_flickerReduction;
331 m_flickerReduction = new FlickerReduction(dev, this);
332 emit flickerReductionChanged();
335 m_focus = new Focus(dev, this);
339 m_autoFocus = new AutoFocus(dev, this);
340 emit autoFocusChanged();
343 m_videoMute = new VideoMute(dev, this);
344 emit videoMuteChanged();
347 m_videoTorch = new VideoTorch(dev, this);
348 emit videoTorchChanged();
351 Zoom *Camera::zoom() const {
355 Flash *Camera::flash() const {
359 Scene *Camera::scene() const {
363 EvComp *Camera::evComp() const {
367 WhiteBalance *Camera::whiteBalance() const {
368 return m_whiteBalance;
371 ColorTone *Camera::colorTone() const {
375 Iso *Camera::iso() const {
379 Exposure *Camera::exposure() const {
383 Aperture *Camera::aperture() const {
387 NoiseReduction *Camera::noiseReduction() const {
388 return m_noiseReduction;
391 FlickerReduction *Camera::flickerReduction() const {
392 return m_flickerReduction;
395 Focus *Camera::focus() const {
399 AutoFocus *Camera::autoFocus() const {
403 VideoMute *Camera::videoMute() const {
407 VideoTorch *Camera::videoTorch() const {