#include "qtcamconfig.h"
#include "notifications.h"
#include "notificationscontainer.h"
+#include "sounds.h"
+#include <QDeclarativeInfo>
+
+#include "zoom.h"
+#include "flash.h"
+#include "scene.h"
+#include "evcomp.h"
+#include "whitebalance.h"
+#include "colortone.h"
+#include "iso.h"
+#include "exposure.h"
+#include "aperture.h"
+#include "noisereduction.h"
+#include "flickerreduction.h"
+#include "focus.h"
+#include "autofocus.h"
// TODO: a viewfinder class that inherits QDeclarativeItem
m_cam(new QtCamera(this)),
m_dev(0),
m_vf(new QtCamGraphicsViewfinder(m_cam->config(), this)),
- m_mode(Camera::ImageMode),
- m_notifications(new NotificationsContainer(this)) {
+ m_mode(Camera::UnknownMode),
+ m_notifications(new NotificationsContainer(this)),
+ m_zoom(0),
+ m_flash(0),
+ m_scene(0),
+ m_evComp(0),
+ m_whiteBalance(0),
+ m_colorTone(0),
+ m_iso(0),
+ m_exposure(0),
+ m_aperture(0),
+ m_noiseReduction(0),
+ m_flickerReduction(0),
+ m_focus(0),
+ m_autoFocus(0) {
+
// TODO:
}
Camera::~Camera() {
- // TODO:
+ if (m_dev) {
+ m_dev->stop(true);
+ m_dev->deleteLater();
+ m_dev = 0;
+ }
+
+ delete m_zoom;
+ delete m_flash;
+ delete m_scene;
+ delete m_evComp;
+ delete m_whiteBalance;
+ delete m_colorTone;
+ delete m_iso;
+ delete m_exposure;
+ delete m_aperture;
+ delete m_noiseReduction;
+ delete m_flickerReduction;
+ delete m_focus;
+ delete m_autoFocus;
+
+ // TODO: cleanup
}
void Camera::componentComplete() {
QDeclarativeItem::componentComplete();
- if (m_id.isValid()) {
- QVariant oldId = m_id;
- m_id = QVariant();
- setDeviceId(oldId);
- }
-
emit deviceCountChanged();
}
return m_cam->devices().at(index).second;
}
-void Camera::setDeviceId(const QVariant& id) {
- if (id == m_id) {
- return;
+bool Camera::reset(const QVariant& deviceId, const CameraMode& mode) {
+ if (mode == Camera::UnknownMode) {
+ qmlInfo(this) << "Cannot set mode to unknown";
+ return false;
}
if (!isComponentComplete()) {
- m_id = id;
- emit deviceIdChanged();
- return;
+ qmlInfo(this) << "Component is still not ready";
+ return false;
+ }
+
+ QVariant oldId = m_id;
+ Camera::CameraMode oldMode = m_mode;
+
+ if (setDeviceId(deviceId) && setMode(mode)) {
+ if (oldId != m_id) {
+ emit deviceIdChanged();
+ emit deviceChanged();
+
+ resetCapabilities();
+ }
+
+ if (oldMode != m_mode) {
+ emit modeChanged();
+ }
+
+ return true;
}
- if (m_dev && m_dev->stop()) {
+ return false;
+}
+
+bool Camera::setDeviceId(const QVariant& deviceId) {
+ if (deviceId == m_id) {
+ return true;
+ }
+
+ if (m_dev && m_dev->stop(false)) {
delete m_dev;
}
else if (m_dev) {
- qWarning() << "Failed to stop device";
- return;
+ qmlInfo(this) << "Failed to stop device";
+ return false;
}
- m_dev = m_cam->device(id, this);
+ m_dev = m_cam->device(deviceId, this);
- m_id = id;
+ m_id = deviceId;
m_vf->setDevice(m_dev);
m_notifications->setDevice(m_dev);
- emit deviceIdChanged();
- emit deviceChanged();
+ return true;
}
QVariant Camera::deviceId() const {
return m_dev;
}
-void Camera::setMode(const Camera::CameraMode& mode) {
+bool Camera::setMode(const Camera::CameraMode& mode) {
if (m_mode == mode) {
- return;
+ return true;
}
- m_mode = mode;
-
if (!m_dev) {
- return;
+ return false;
}
+ m_mode = mode;
+
if (m_dev->isRunning()) {
applyMode();
}
- emit modeChanged();
+ return true;
}
Camera::CameraMode Camera::mode() {
return false;
}
- applyMode();
+ if (!applyMode()) {
+ return false;
+ }
return m_dev->start();
}
-bool Camera::stop() {
+bool Camera::stop(bool force) {
if (m_dev) {
- return m_dev->stop();
+ return m_dev->stop(force);
}
return true;
return m_dev ? m_dev->isRunning() : false;
}
-void Camera::applyMode() {
+bool Camera::applyMode() {
+ if (m_mode == Camera::UnknownMode) {
+ return false;
+ }
+
if (m_mode == Camera::VideoMode && m_dev->activeMode() != m_dev->videoMode()) {
m_dev->videoMode()->activate();
}
else if (m_mode == Camera::ImageMode && m_dev->activeMode() != m_dev->imageMode()) {
m_dev->imageMode()->activate();
}
+
+ return true;
}
QString Camera::imageSuffix() const {
void Camera::setNotifications(Notifications *notifications) {
if (m_notifications->setNotifications(notifications)) {
+
+ if (Sounds *s = dynamic_cast<Sounds *>(notifications)) {
+ s->setConfig(m_cam->config());
+ s->reload();
+ }
+
emit notificationsChanged();
}
}
+
+void Camera::resetCapabilities() {
+ QtCamDevice *dev = device();
+
+ delete m_zoom;
+ m_zoom = new Zoom(dev, this);
+ emit zoomChanged();
+
+ delete m_flash;
+ m_flash = new Flash(dev, this);
+ emit flashChanged();
+
+ delete m_scene;
+ m_scene = new Scene(dev, this);
+ emit sceneChanged();
+
+ delete m_evComp;
+ m_evComp = new EvComp(dev, this);
+ emit evCompChanged();
+
+ delete m_whiteBalance;
+ m_whiteBalance = new WhiteBalance(dev, this);
+ emit whiteBalanceChanged();
+
+ delete m_colorTone;
+ m_colorTone = new ColorTone(dev, this);
+ emit colorToneChanged();
+
+ delete m_iso;
+ m_iso = new Iso(dev, this);
+ emit isoChanged();
+
+ delete m_exposure;
+ m_exposure = new Exposure(dev, this);
+ emit exposureChanged();
+
+ delete m_aperture;
+ m_aperture = new Aperture(dev, this);
+ emit apertureChanged();
+
+ delete m_noiseReduction;
+ m_noiseReduction = new NoiseReduction(dev, this);
+ emit noiseReductionChanged();
+
+ delete m_flickerReduction;
+ m_flickerReduction = new FlickerReduction(dev, this);
+ emit flickerReductionChanged();
+
+ delete m_focus;
+ m_focus = new Focus(dev, this);
+ emit focusChanged();
+
+ delete m_autoFocus;
+ m_autoFocus = new AutoFocus(dev, this);
+ emit autoFocusChanged();
+}
+
+Zoom *Camera::zoom() const {
+ return m_zoom;
+}
+
+Flash *Camera::flash() const {
+ return m_flash;
+}
+
+Scene *Camera::scene() const {
+ return m_scene;
+}
+
+EvComp *Camera::evComp() const {
+ return m_evComp;
+}
+
+WhiteBalance *Camera::whiteBalance() const {
+ return m_whiteBalance;
+}
+
+ColorTone *Camera::colorTone() const {
+ return m_colorTone;
+}
+
+Iso *Camera::iso() const {
+ return m_iso;
+}
+
+Exposure *Camera::exposure() const {
+ return m_exposure;
+}
+
+Aperture *Camera::aperture() const {
+ return m_aperture;
+}
+
+NoiseReduction *Camera::noiseReduction() const {
+ return m_noiseReduction;
+}
+
+FlickerReduction *Camera::flickerReduction() const {
+ return m_flickerReduction;
+}
+
+Focus *Camera::focus() const {
+ return m_focus;
+}
+
+AutoFocus *Camera::autoFocus() const {
+ return m_autoFocus;
+}