Adding the declarative imports
authorMohammed Sameer <msameer@foolab.org>
Thu, 6 Sep 2012 15:09:52 +0000 (18:09 +0300)
committerMohammed Sameer <msameer@foolab.org>
Thu, 6 Sep 2012 16:10:10 +0000 (19:10 +0300)
29 files changed:
imports/camera.cpp [new file with mode: 0644]
imports/camera.h [new file with mode: 0644]
imports/capability.cpp [new file with mode: 0644]
imports/capability.h [new file with mode: 0644]
imports/colortone.cpp [new file with mode: 0644]
imports/colortone.h [new file with mode: 0644]
imports/evcomp.cpp [new file with mode: 0644]
imports/evcomp.h [new file with mode: 0644]
imports/flash.cpp [new file with mode: 0644]
imports/flash.h [new file with mode: 0644]
imports/imagemode.cpp [new file with mode: 0644]
imports/imagemode.h [new file with mode: 0644]
imports/imports.pro [new file with mode: 0644]
imports/mode.cpp [new file with mode: 0644]
imports/mode.h [new file with mode: 0644]
imports/plugin.cpp [new file with mode: 0644]
imports/plugin.h [new file with mode: 0644]
imports/previewprovider.cpp [new file with mode: 0644]
imports/previewprovider.h [new file with mode: 0644]
imports/scene.cpp [new file with mode: 0644]
imports/scene.h [new file with mode: 0644]
imports/videomode.cpp [new file with mode: 0644]
imports/videomode.h [new file with mode: 0644]
imports/videotorch.cpp [new file with mode: 0644]
imports/videotorch.h [new file with mode: 0644]
imports/whitebalance.cpp [new file with mode: 0644]
imports/whitebalance.h [new file with mode: 0644]
imports/zoom.cpp [new file with mode: 0644]
imports/zoom.h [new file with mode: 0644]

diff --git a/imports/camera.cpp b/imports/camera.cpp
new file mode 100644 (file)
index 0000000..d1578e9
--- /dev/null
@@ -0,0 +1,151 @@
+#include "camera.h"
+#include "qtcamera.h"
+#include "qtcamdevice.h"
+#include "qtcammode.h"
+#include "qtcamimagemode.h"
+#include "qtcamvideomode.h"
+#include "qtcamgraphicsviewfinder.h"
+
+Camera::Camera(QDeclarativeItem *parent) :
+  QDeclarativeItem(parent),
+  m_cam(new QtCamera(this)),
+  m_dev(0),
+  m_vf(new QtCamGraphicsViewfinder(m_cam->config(), this)),
+  m_mode(Camera::ImageMode) {
+
+  // TODO:
+}
+
+Camera::~Camera() {
+  // TODO:
+}
+
+void Camera::componentComplete() {
+  QDeclarativeItem::componentComplete();
+
+  if (m_id.isValid()) {
+    QVariant oldId = m_id;
+    m_id = QVariant();
+    setDeviceId(oldId);
+  }
+
+  emit deviceCountChanged();
+}
+
+int Camera::deviceCount() const {
+  return m_cam ? m_cam->devices().size() : 0;
+}
+
+QString Camera::deviceName(int index) const {
+  return m_cam->devices().at(index).first;
+}
+
+QVariant Camera::deviceId(int index) const {
+  return m_cam->devices().at(index).second;
+}
+
+void Camera::setDeviceId(const QVariant& id) {
+  if (id == m_id) {
+    return;
+  }
+
+  if (!isComponentComplete()) {
+    m_id = id;
+    emit deviceIdChanged();
+    return;
+  }
+
+  if (m_dev) {
+    QObject::disconnect(m_dev, SIGNAL(runningStateChanged(bool)),
+                       this, SIGNAL(runningStateChanged()));
+    QObject::disconnect(m_dev, SIGNAL(idleStateChanged(bool)), this, SIGNAL(idleStateChanged()));
+  }
+
+  if (m_dev && m_dev->stop()) {
+    delete m_dev;
+  }
+  else if (m_dev) {
+    qWarning() << "Failed to stop device";
+    return;
+  }
+
+  m_dev = m_cam->device(id, this);
+
+  m_id = id;
+
+  m_vf->setDevice(m_dev);
+
+  if (m_mode == Camera::VideoMode) {
+    m_dev->videoMode()->activate();
+  }
+  else {
+    m_dev->imageMode()->activate();
+  }
+
+  QObject::connect(m_dev, SIGNAL(runningStateChanged(bool)),
+                     this, SIGNAL(runningStateChanged()));
+  QObject::connect(m_dev, SIGNAL(idleStateChanged(bool)), this, SIGNAL(idleStateChanged()));
+
+  emit deviceIdChanged();
+  emit deviceChanged();
+}
+
+QVariant Camera::deviceId() const {
+  return m_id;
+}
+
+void Camera::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
+  QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
+
+  m_vf->setGeometry(newGeometry);
+}
+
+QtCamDevice *Camera::device() const {
+  return m_dev;
+}
+
+void Camera::setMode(const Camera::CameraMode& mode) {
+  m_mode = mode;
+
+  if (!m_dev) {
+    return;
+  }
+
+  Camera::CameraMode current = m_dev->activeMode() == m_dev->videoMode() ?
+    Camera::VideoMode : Camera::ImageMode;
+
+  if (current == mode) {
+    return;
+  }
+
+  if (mode == Camera::VideoMode) {
+    m_dev->videoMode()->activate();
+  }
+  else {
+    m_dev->imageMode()->activate();
+  }
+
+  emit modeChanged();
+}
+
+Camera::CameraMode Camera::mode() {
+  return m_mode;
+}
+
+bool Camera::start() {
+  return m_dev ? m_dev->start() : false;
+}
+
+void Camera::stop() {
+  if (m_dev) {
+    m_dev->stop();
+  }
+}
+
+bool Camera::isIdle() {
+  return m_dev ? m_dev->isIdle() : true;
+}
+
+bool Camera::isRunning() {
+  return m_dev ? m_dev->isRunning() : false;
+}
diff --git a/imports/camera.h b/imports/camera.h
new file mode 100644 (file)
index 0000000..0267a6a
--- /dev/null
@@ -0,0 +1,73 @@
+// -*- c++ -*-
+
+#ifndef CAMERA_H
+#define CAMERA_H
+
+#include <QDeclarativeItem>
+#include <QVariant>
+
+class QtCamera;
+class QtCamDevice;
+class QtCamGraphicsViewfinder;
+
+class Camera : public QDeclarativeItem {
+  Q_OBJECT
+
+  Q_PROPERTY(int deviceCount READ deviceCount NOTIFY deviceCountChanged)
+  Q_PROPERTY(QVariant deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged);
+  Q_PROPERTY(CameraMode mode READ mode WRITE setMode NOTIFY modeChanged);
+  Q_PROPERTY(bool idle READ isIdle NOTIFY idleStateChanged);
+  Q_PROPERTY(bool running READ isRunning NOTIFY runningStateChanged);
+  Q_ENUMS(CameraMode);
+
+public:
+  typedef enum {
+    ImageMode,
+    VideoMode
+  } CameraMode;
+
+  Camera(QDeclarativeItem *parent = 0);
+  ~Camera();
+
+  virtual void componentComplete();
+
+  int deviceCount() const;
+  Q_INVOKABLE QString deviceName(int index) const;
+  Q_INVOKABLE QVariant deviceId(int index) const;
+
+  void setDeviceId(const QVariant& id);
+  QVariant deviceId() const;
+
+  void setMode(const CameraMode& mode);
+  CameraMode mode();
+
+  QtCamDevice *device() const;
+
+  Q_INVOKABLE bool start();
+
+  bool isIdle();
+  bool isRunning();
+
+public slots:
+  void stop();
+
+signals:
+  void deviceCountChanged();
+  void deviceIdChanged();
+  void deviceChanged();
+  void modeChanged();
+  void idleStateChanged();
+  void runningStateChanged();
+
+protected:
+  void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry);
+
+private:
+  QtCamera *m_cam;
+  QtCamDevice *m_dev;
+  QVariant m_id;
+  QtCamGraphicsViewfinder *m_vf;
+  CameraMode m_mode;
+};
+
+#endif /* CAMERA_H */
diff --git a/imports/capability.cpp b/imports/capability.cpp
new file mode 100644 (file)
index 0000000..6f3e8e7
--- /dev/null
@@ -0,0 +1,36 @@
+#include "capability.h"
+#include "camera.h"
+
+Capability::Capability(QObject *parent) :
+  QObject(parent),
+  m_cam(0) {
+
+}
+
+Capability::~Capability() {
+
+}
+
+Camera *Capability::camera() {
+  return m_cam;
+}
+
+void Capability::setCamera(Camera *cam) {
+  if (cam == m_cam) {
+    return;
+  }
+
+  if (m_cam) {
+    QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
+  }
+
+  m_cam = cam;
+
+  if (m_cam) {
+    QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
+  }
+
+  emit cameraChanged();
+
+  deviceChanged();
+}
diff --git a/imports/capability.h b/imports/capability.h
new file mode 100644 (file)
index 0000000..d2d0f62
--- /dev/null
@@ -0,0 +1,31 @@
+// -*- c++ -*-
+
+#ifndef CAPABILITY_H
+#define CAPABILITY_H
+
+#include <QObject>
+
+class Camera;
+
+class Capability : public QObject {
+  Q_OBJECT
+  Q_PROPERTY(Camera* camera READ camera WRITE setCamera NOTIFY cameraChanged);
+
+public:
+  Capability(QObject *parent = 0);
+  virtual ~Capability();
+
+  Camera *camera();
+  void setCamera(Camera *cam);
+
+signals:
+  void cameraChanged();
+
+private slots:
+  virtual void deviceChanged() = 0;
+
+protected:
+  Camera *m_cam;
+};
+
+#endif /* CAPABILITY_H */
diff --git a/imports/colortone.cpp b/imports/colortone.cpp
new file mode 100644 (file)
index 0000000..9c714f3
--- /dev/null
@@ -0,0 +1,37 @@
+#include "colortone.h"
+#include "camera.h"
+
+ColorTone::ColorTone(QObject *parent) :
+  Capability(parent),
+  m_color(0) {
+
+}
+
+ColorTone::~ColorTone() {
+  if (m_color) {
+    delete m_color; m_color = 0;
+  }
+}
+
+void ColorTone::deviceChanged() {
+  if (m_color) {
+    delete m_color; m_color = 0;
+  }
+
+  if (m_cam->device()) {
+    m_color = new QtCamColorTone(m_cam->device(), this);
+    QObject::connect(m_color, SIGNAL(valueChanged()), this, SIGNAL(valueChanged()));
+  }
+
+  emit valueChanged();
+}
+
+ColorTone::ColorToneMode ColorTone::value() {
+  return m_color ? (ColorToneMode)m_color->value() : ColorTone::Normal;
+}
+
+void ColorTone::setValue(const ColorTone::ColorToneMode& mode) {
+  if (m_color) {
+    m_color->setValue((QtCamColorTone::ColorToneMode)mode);
+  }
+}
diff --git a/imports/colortone.h b/imports/colortone.h
new file mode 100644 (file)
index 0000000..403391d
--- /dev/null
@@ -0,0 +1,46 @@
+// -*- c++ -*-
+
+#ifndef COLOR_TONE_H
+#define COLOR_TONE_H
+
+#include "capability.h"
+#include "qtcamcolortone.h"
+
+class ColorTone : public Capability {
+  Q_OBJECT
+
+  Q_PROPERTY(ColorToneMode value READ value WRITE setValue NOTIFY valueChanged);
+  Q_ENUMS(ColorToneMode);
+
+public:
+  typedef enum {
+    Normal = QtCamColorTone::Normal,
+    Sepia = QtCamColorTone::Sepia,
+    Negative = QtCamColorTone::Negative,
+    GrayScale = QtCamColorTone::GrayScale,
+    Natural = QtCamColorTone::Natural,
+    Vivid = QtCamColorTone::Vivid,
+    ColorSwap = QtCamColorTone::ColorSwap,
+    Solarize = QtCamColorTone::Solarize,
+    OutOfFocus = QtCamColorTone::OutOfFocus,
+    SkyBlue = QtCamColorTone::SkyBlue,
+    GrassGreen = QtCamColorTone::GrassGreen,
+    SkinWhite = QtCamColorTone::SkinWhite,
+  } ColorToneMode;
+
+  ColorTone(QObject *parent = 0);
+  ~ColorTone();
+
+  ColorToneMode value();
+  void setValue(const ColorToneMode& mode);
+
+signals:
+  void valueChanged();
+
+private:
+  virtual void deviceChanged();
+
+  QtCamColorTone *m_color;
+};
+
+#endif /* COLOR_TONE_H */
diff --git a/imports/evcomp.cpp b/imports/evcomp.cpp
new file mode 100644 (file)
index 0000000..08d9029
--- /dev/null
@@ -0,0 +1,50 @@
+#include "evcomp.h"
+#include "camera.h"
+#include "qtcamevcomp.h"
+
+EvComp::EvComp(QObject *parent) :
+  Capability(parent),
+  m_evComp(0) {
+
+}
+
+EvComp::~EvComp() {
+  if (m_evComp) {
+    delete m_evComp; m_evComp = 0;
+  }
+}
+
+void EvComp::deviceChanged() {
+  if (m_evComp) {
+    delete m_evComp; m_evComp = 0;
+  }
+
+  if (m_cam->device()) {
+    m_evComp = new QtCamEvComp(m_cam->device(), this);
+    QObject::connect(m_evComp, SIGNAL(valueChanged()), this, SIGNAL(valueChanged()));
+    QObject::connect(m_evComp, SIGNAL(minimumValueChanged()), this, SIGNAL(minimumChanged()));
+    QObject::connect(m_evComp, SIGNAL(maximumValueChanged()), this, SIGNAL(maximunmChanged()));
+  }
+
+  emit valueChanged();
+  emit minimumChanged();
+  emit maximunmChanged();
+}
+
+qreal EvComp::value() {
+  return m_evComp ? m_evComp->value() : 0.0;
+}
+
+void EvComp::setValue(qreal val) {
+  if (m_evComp) {
+    m_evComp->setValue(val);
+  }
+}
+
+qreal EvComp::minimum() {
+  return m_evComp ? m_evComp->minimumValue() : 0.0;
+}
+
+qreal EvComp::maximum() {
+  return m_evComp ? m_evComp->maximumValue() : 0.0;
+}
diff --git a/imports/evcomp.h b/imports/evcomp.h
new file mode 100644 (file)
index 0000000..24142c9
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef EV_COMP_H
+#define EV_COMP_H
+
+#include "capability.h"
+
+class QtCamEvComp;
+
+class EvComp : public Capability {
+  Q_OBJECT
+
+  Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged);
+  Q_PROPERTY(qreal minimum READ minimum NOTIFY minimumChanged);
+  Q_PROPERTY(qreal maximum READ maximum NOTIFY maximunmChanged);
+
+public:
+  EvComp(QObject *parent = 0);
+  ~EvComp();
+
+  qreal value();
+  void setValue(qreal val);
+
+  qreal minimum();
+  qreal maximum();
+
+signals:
+  void valueChanged();
+  void minimumChanged();
+  void maximunmChanged();
+
+private:
+  virtual void deviceChanged();
+
+  QtCamEvComp *m_evComp;
+};
+
+#endif /* EV_COMP_H */
diff --git a/imports/flash.cpp b/imports/flash.cpp
new file mode 100644 (file)
index 0000000..e410a9a
--- /dev/null
@@ -0,0 +1,37 @@
+#include "flash.h"
+#include "camera.h"
+
+Flash::Flash(QObject *parent) :
+  Capability(parent),
+  m_flash(0) {
+
+}
+
+Flash::~Flash() {
+  if (m_flash) {
+    delete m_flash; m_flash = 0;
+  }
+}
+
+void Flash::deviceChanged() {
+  if (m_flash) {
+    delete m_flash; m_flash = 0;
+  }
+
+  if (m_cam->device()) {
+    m_flash = new QtCamFlash(m_cam->device(), this);
+    QObject::connect(m_flash, SIGNAL(valueChanged()), this, SIGNAL(valueChanged()));
+  }
+
+  emit valueChanged();
+}
+
+Flash::FlashMode Flash::value() {
+  return m_flash ? (FlashMode)m_flash->value() : Flash::Auto;
+}
+
+void Flash::setValue(const Flash::FlashMode& mode) {
+  if (m_flash) {
+    m_flash->setValue((QtCamFlash::FlashMode)mode);
+  }
+}
diff --git a/imports/flash.h b/imports/flash.h
new file mode 100644 (file)
index 0000000..63336a6
--- /dev/null
@@ -0,0 +1,39 @@
+// -*- c++ -*-
+
+#ifndef FLASH_H
+#define FLASH_H
+
+#include "capability.h"
+#include "qtcamflash.h"
+
+class Flash : public Capability {
+  Q_OBJECT
+
+  Q_PROPERTY(FlashMode value READ value WRITE setValue NOTIFY valueChanged);
+  Q_ENUMS(FlashMode);
+
+public:
+  typedef enum {
+    Auto = QtCamFlash::Auto,
+    On = QtCamFlash::On,
+    Off = QtCamFlash::Off,
+    FillIn = QtCamFlash::FillIn,
+    RedEye = QtCamFlash::RedEye
+  } FlashMode;
+
+  Flash(QObject *parent = 0);
+  ~Flash();
+
+  FlashMode value();
+  void setValue(const FlashMode& mode);
+
+signals:
+  void valueChanged();
+
+private:
+  virtual void deviceChanged();
+
+  QtCamFlash *m_flash;
+};
+
+#endif /* FLASH_H */
diff --git a/imports/imagemode.cpp b/imports/imagemode.cpp
new file mode 100644 (file)
index 0000000..cf1f839
--- /dev/null
@@ -0,0 +1,31 @@
+#include "imagemode.h"
+#include "qtcamimagemode.h"
+#include "qtcamdevice.h"
+#include "camera.h"
+
+ImageMode::ImageMode(QObject *parent) :
+  Mode(parent),
+  m_image(0) {
+
+}
+
+ImageMode::~ImageMode() {
+  m_image = 0;
+}
+
+
+bool ImageMode::capture(const QString& fileName) {
+  return m_image ? m_image->capture(fileName) : false;
+}
+
+void ImageMode::preChangeMode() {
+  m_image = 0;
+}
+
+void ImageMode::postChangeMode() {
+  m_image = m_cam->device()->imageMode();
+}
+
+void ImageMode::changeMode() {
+  m_mode = m_cam->device()->imageMode();
+}
diff --git a/imports/imagemode.h b/imports/imagemode.h
new file mode 100644 (file)
index 0000000..2e9e75e
--- /dev/null
@@ -0,0 +1,28 @@
+// -*- c++ -*-
+
+#ifndef IMAGE_MODE_H
+#define IMAGE_MODE_H
+
+#include "mode.h"
+
+class QtCamImageMode;
+
+class ImageMode : public Mode {
+  Q_OBJECT
+
+public:
+  ImageMode(QObject *parent = 0);
+  ~ImageMode();
+
+  Q_INVOKABLE bool capture(const QString& fileName);
+
+protected:
+  virtual void preChangeMode();
+  virtual void postChangeMode();
+  virtual void changeMode();
+
+private:
+  QtCamImageMode *m_image;
+};
+
+#endif /* IMAGE_MODE_H */
diff --git a/imports/imports.pro b/imports/imports.pro
new file mode 100644 (file)
index 0000000..fd2b631
--- /dev/null
@@ -0,0 +1,19 @@
+TEMPLATE = lib
+TARGET = imports
+DEPENDPATH += . ../lib/
+INCLUDEPATH += . ../lib/
+
+CONFIG += link_pkgconfig debug
+
+PKGCONFIG = gstreamer-0.10 gstreamer-interfaces-0.10 gstreamer-video-0.10 gstreamer-tag-0.10 \
+            gstreamer-pbutils-0.10 meego-gstreamer-interfaces-0.10
+
+QT += declarative
+
+HEADERS += plugin.h previewprovider.h camera.h mode.h imagemode.h videomode.h \
+           capability.h zoom.h flash.h scene.h evcomp.h videotorch.h whitebalance.h \
+           colortone.h
+
+SOURCES += plugin.cpp previewprovider.cpp camera.cpp mode.cpp imagemode.cpp videomode.cpp \
+           capability.cpp zoom.cpp flash.cpp scene.cpp evcomp.cpp videotorch.cpp whitebalance.cpp \
+           colortone.cpp
diff --git a/imports/mode.cpp b/imports/mode.cpp
new file mode 100644 (file)
index 0000000..0f80fd3
--- /dev/null
@@ -0,0 +1,114 @@
+#include "mode.h"
+#include "qtcammode.h"
+#include "camera.h"
+#include "qtcamdevice.h"
+#include "previewprovider.h"
+
+Mode::Mode(QObject *parent) :
+  QObject(parent),
+  m_cam(0),
+  m_mode(0),
+  m_seq(0) {
+
+}
+
+Mode::~Mode() {
+  m_cam = 0;
+  m_mode = 0;
+}
+
+Camera *Mode::camera() {
+  return m_cam;
+}
+
+void Mode::setCamera(Camera *camera) {
+  if (camera == m_cam) {
+    return;
+  }
+
+  if (m_cam) {
+    QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
+  }
+
+  m_cam = camera;
+
+  if (m_cam) {
+    QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
+  }
+
+  emit cameraChanged();
+
+  deviceChanged();
+}
+
+bool Mode::isActive() {
+  return m_mode ? m_mode->isActive() : false;
+}
+
+bool Mode::canCapture() {
+  return m_mode ? m_mode->canCapture() : false;
+}
+
+void Mode::deviceChanged() {
+  if (m_mode) {
+    QObject::disconnect(m_mode, SIGNAL(canCaptureChanged()), this, SIGNAL(canCaptureChanged()));
+    QObject::disconnect(m_mode, SIGNAL(saved(const QString&)),
+                       this, SIGNAL(saved(const QString&)));
+    QObject::disconnect(m_mode, SIGNAL(previewAvailable(const QImage&, const QString&)),
+                       this, SLOT(gotPreview(const QImage&, const QString&)));
+    QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(activeChanged()));
+    QObject::disconnect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(canCaptureChanged()));
+    QObject::disconnect(m_cam->device(), SIGNAL(idleStateChanged(bool)),
+                       this, SIGNAL(canCaptureChanged()));
+    QObject::disconnect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
+                       this, SIGNAL(canCaptureChanged()));
+    QObject::disconnect(m_mode, SIGNAL(nightModeChanged()), this, SIGNAL(nightModeChanged()));
+
+    preChangeMode();
+  }
+
+  if (!m_cam || !m_cam->device()) {
+    return;
+  }
+
+  changeMode();
+
+  if (m_mode) {
+    QObject::connect(m_mode, SIGNAL(canCaptureChanged()), this, SIGNAL(canCaptureChanged()));
+    QObject::connect(m_mode, SIGNAL(saved(const QString&)), this, SIGNAL(saved(const QString&)));
+    QObject::connect(m_mode, SIGNAL(previewAvailable(const QImage&, const QString&)),
+                    this, SLOT(gotPreview(const QImage&, const QString&)));
+    QObject::connect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(activeChanged()));
+    QObject::connect(m_mode, SIGNAL(activeChanged()), this, SIGNAL(canCaptureChanged()));
+    QObject::connect(m_cam->device(), SIGNAL(idleStateChanged(bool)),
+                    this, SIGNAL(canCaptureChanged()));
+    QObject::connect(m_cam->device(), SIGNAL(runningStateChanged(bool)),
+                    this, SIGNAL(canCaptureChanged()));
+    QObject::connect(m_mode, SIGNAL(nightModeChanged()), this, SIGNAL(nightModeChanged()));
+
+    postChangeMode();
+  }
+
+  emit canCaptureChanged();
+  emit activeChanged();
+}
+
+void Mode::gotPreview(const QImage& image, const QString& fileName) {
+  PreviewProvider::instance()->setPreview(image);
+
+  // HACK: QML insists on caching the images.
+  QString url = QString("image://preview/%1").arg(m_seq);
+  ++m_seq;
+
+  emit previewAvailable(url, fileName);
+}
+
+void Mode::setNightMode(bool night) {
+  if (m_mode) {
+    m_mode->setNightMode(night);
+  }
+}
+
+bool Mode::inNightMode() const {
+  return m_mode ? m_mode->inNightMode() : false;
+}
diff --git a/imports/mode.h b/imports/mode.h
new file mode 100644 (file)
index 0000000..8c0b673
--- /dev/null
@@ -0,0 +1,60 @@
+// -*- c++ -*-
+
+#ifndef MODE_H
+#define MODE_H
+
+#include <QObject>
+
+class Camera;
+class QImage;
+class QtCamMode;
+
+class Mode : public QObject {
+  Q_OBJECT
+
+  Q_PROPERTY(Camera* camera READ camera WRITE setCamera NOTIFY cameraChanged);
+  Q_PROPERTY(bool canCapture READ canCapture NOTIFY canCaptureChanged);
+  Q_PROPERTY(bool active READ isActive NOTIFY activeChanged);
+  Q_PROPERTY(bool nightMode READ inNightMode WRITE setNightMode NOTIFY nightModeChanged);
+
+public:
+  Mode(QObject *parent = 0);
+  virtual ~Mode();
+
+  Camera *camera();
+  virtual void setCamera(Camera *camera);
+
+  bool isActive();
+
+  bool canCapture();
+
+  void setNightMode(bool night);
+  bool inNightMode() const;
+
+signals:
+  void cameraChanged();
+  void canCaptureChanged();
+  void activeChanged();
+  void previewAvailable(const QString& preview, const QString& fileName);
+  void saved(const QString& fileName);
+  void nightModeChanged();
+
+private slots:
+  void gotPreview(const QImage& image, const QString& fileName);
+
+protected:
+  virtual void preChangeMode() = 0;
+  virtual void postChangeMode() = 0;
+  virtual void changeMode() = 0;
+
+  Camera *m_cam;
+  QtCamMode *m_mode;
+
+private slots:
+  void deviceChanged();
+
+private:
+  unsigned long long m_seq;
+};
+
+#endif /* MODE_H */
diff --git a/imports/plugin.cpp b/imports/plugin.cpp
new file mode 100644 (file)
index 0000000..dccd96b
--- /dev/null
@@ -0,0 +1,36 @@
+#include "plugin.h"
+#include "imagemode.h"
+#include "videomode.h"
+#include "camera.h"
+#include "previewprovider.h"
+#include "capability.h"
+#include "zoom.h"
+#include "flash.h"
+#include "scene.h"
+#include "evcomp.h"
+#include "videotorch.h"
+#include "whitebalance.h"
+#include "colortone.h"
+
+#include <QtDeclarative>
+
+#define URI "QtCamera"
+#define MAJOR 1
+#define MINOR 0
+
+void Plugin::registerTypes(QDeclarativeEngine *engine) {
+  qmlRegisterType<Camera>(URI, MAJOR, MINOR, "Camera");
+  qmlRegisterType<ImageMode>(URI, MAJOR, MINOR, "ImageMode");
+  qmlRegisterType<VideoMode>(URI, MAJOR, MINOR, "VideoMode");
+  qmlRegisterType<Zoom>(URI, MAJOR, MINOR, "Zoom");
+  qmlRegisterType<Flash>(URI, MAJOR, MINOR, "Flash");
+  qmlRegisterType<Scene>(URI, MAJOR, MINOR, "Scene");
+  qmlRegisterType<EvComp>(URI, MAJOR, MINOR, "EvComp");
+  qmlRegisterType<VideoTorch>(URI, MAJOR, MINOR, "VideoTorch");
+  qmlRegisterType<WhiteBalance>(URI, MAJOR, MINOR, "WhiteBalance");
+  qmlRegisterType<ColorTone>(URI, MAJOR, MINOR, "ColorTone");
+  qmlRegisterType<Mode>();
+  qmlRegisterType<Capability>();
+
+  engine->addImageProvider("preview", new PreviewProvider);
+}
diff --git a/imports/plugin.h b/imports/plugin.h
new file mode 100644 (file)
index 0000000..a2dc6b6
--- /dev/null
@@ -0,0 +1,13 @@
+// -*- c++ -*-
+
+#ifndef PLUGIN_H
+#define PLUGIN_H
+
+class QDeclarativeEngine;
+
+class Plugin {
+public:
+  static void registerTypes(QDeclarativeEngine *engine);
+};
+
+#endif /* PLUGIN_H */
diff --git a/imports/previewprovider.cpp b/imports/previewprovider.cpp
new file mode 100644 (file)
index 0000000..7b9c8d2
--- /dev/null
@@ -0,0 +1,40 @@
+#include "previewprovider.h"
+
+PreviewProvider *PreviewProvider::m_instance = 0;
+
+PreviewProvider::PreviewProvider() :
+  QDeclarativeImageProvider(QDeclarativeImageProvider::Image) {
+
+  m_instance = this;
+}
+
+PreviewProvider::~PreviewProvider() {
+  m_instance = 0;
+}
+
+QImage PreviewProvider::requestImage(const QString& id, QSize *size, const QSize& requestedSize) {
+  QMutexLocker lock(&m_mutex);
+
+  QImage res = m_image;
+
+  if (!requestedSize.isEmpty()) {
+    res = res.scaled(requestedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+  }
+
+  if (size) {
+    *size = res.size();
+  }
+
+  return res;
+
+}
+
+void PreviewProvider::setPreview(const QImage& preview) {
+  QMutexLocker lock(&m_mutex);
+
+  m_image = preview;
+}
+
+PreviewProvider *PreviewProvider::instance() {
+  return m_instance;
+}
diff --git a/imports/previewprovider.h b/imports/previewprovider.h
new file mode 100644 (file)
index 0000000..7fe1889
--- /dev/null
@@ -0,0 +1,25 @@
+// -*- c++ -*-
+
+#ifndef PREVIEW_PROVIDER_H
+#define PREVIEW_PROVIDER_H
+
+#include <QDeclarativeImageProvider>
+#include <QMutex>
+
+class PreviewProvider : public QDeclarativeImageProvider {
+public:
+  PreviewProvider();
+  ~PreviewProvider();
+
+  static PreviewProvider *instance();
+
+  virtual QImage requestImage(const QString& id, QSize *size, const QSize& requestedSize);
+  void setPreview(const QImage& preview);
+
+private:
+  static PreviewProvider *m_instance;
+  QImage m_image;
+  QMutex m_mutex;
+};
+
+#endif /* PREVIEW_PROVIDER_H */
diff --git a/imports/scene.cpp b/imports/scene.cpp
new file mode 100644 (file)
index 0000000..c787f51
--- /dev/null
@@ -0,0 +1,38 @@
+#include "scene.h"
+#include "camera.h"
+#include <QDebug>
+
+Scene::Scene(QObject *parent) :
+  Capability(parent),
+  m_scene(0) {
+
+}
+
+Scene::~Scene() {
+  if (m_scene) {
+    delete m_scene; m_scene = 0;
+  }
+}
+
+void Scene::deviceChanged() {
+  if (m_scene) {
+    delete m_scene; m_scene = 0;
+  }
+
+  if (m_cam->device()) {
+    m_scene = new QtCamScene(m_cam->device(), this);
+    QObject::connect(m_scene, SIGNAL(valueChanged()), this, SIGNAL(valueChanged()));
+  }
+
+  emit valueChanged();
+}
+
+Scene::SceneMode Scene::value() {
+  return m_scene ? (SceneMode)m_scene->value() : Scene::Auto;
+}
+
+void Scene::setValue(const Scene::SceneMode& mode) {
+  if (m_scene) {
+    m_scene->setValue((QtCamScene::SceneMode)mode);
+  }
+}
diff --git a/imports/scene.h b/imports/scene.h
new file mode 100644 (file)
index 0000000..2e2d9c4
--- /dev/null
@@ -0,0 +1,41 @@
+// -*- c++ -*-
+
+#ifndef SCENE_H
+#define SCENE_H
+
+#include "capability.h"
+#include "qtcamscene.h"
+
+class Scene : public Capability {
+  Q_OBJECT
+
+  Q_PROPERTY(SceneMode value READ value WRITE setValue NOTIFY valueChanged);
+  Q_ENUMS(SceneMode);
+
+public:
+  typedef enum {
+    Manual = QtCamScene::Manual,
+    Closeup = QtCamScene::Closeup,
+    Portrait = QtCamScene::Portrait,
+    Landscape = QtCamScene::Landscape,
+    Sport = QtCamScene::Sport,
+    Night = QtCamScene::Night,
+    Auto = QtCamScene::Auto
+  } SceneMode;
+
+  Scene(QObject *parent = 0);
+  ~Scene();
+
+  SceneMode value();
+  void setValue(const SceneMode& mode);
+
+signals:
+  void valueChanged();
+
+private:
+  virtual void deviceChanged();
+
+  QtCamScene *m_scene;
+};
+
+#endif /* SCENE_H */
diff --git a/imports/videomode.cpp b/imports/videomode.cpp
new file mode 100644 (file)
index 0000000..0129984
--- /dev/null
@@ -0,0 +1,51 @@
+#include "videomode.h"
+#include "qtcamvideomode.h"
+#include "qtcamdevice.h"
+#include "camera.h"
+
+VideoMode::VideoMode(QObject *parent) :
+  Mode(parent),
+  m_video(0) {
+
+}
+
+VideoMode::~VideoMode() {
+  m_video = 0;
+}
+
+
+bool VideoMode::startRecording(const QString& fileName) {
+  return m_video ? m_video->startRecording(fileName) : false;
+}
+
+void VideoMode::stopRecording() {
+  if (m_video) {
+    m_video->stopRecording();
+  }
+}
+
+void VideoMode::preChangeMode() {
+  if (m_video) {
+    QObject::disconnect(m_video, SIGNAL(recordingStateChanged()),
+                       this, SIGNAL(recordingStateChanged()));
+  }
+
+  m_video = 0;
+}
+
+void VideoMode::postChangeMode() {
+  m_video = m_cam->device()->videoMode();
+
+  if (m_video) {
+    QObject::connect(m_video, SIGNAL(recordingStateChanged()),
+                       this, SIGNAL(recordingStateChanged()));
+  }
+}
+
+bool VideoMode::isRecording() {
+  return m_video ? m_video->isRecording() : false;
+}
+
+void VideoMode::changeMode() {
+  m_mode = m_cam->device()->videoMode();
+}
diff --git a/imports/videomode.h b/imports/videomode.h
new file mode 100644 (file)
index 0000000..4225172
--- /dev/null
@@ -0,0 +1,37 @@
+// -*- c++ -*-
+
+#ifndef VIDEO_MODE_H
+#define VIDEO_MODE_H
+
+#include "mode.h"
+
+class QtCamVideoMode;
+
+class VideoMode : public Mode {
+  Q_OBJECT
+  Q_PROPERTY(bool recording READ isRecording NOTIFY recordingStateChanged);
+
+public:
+  VideoMode(QObject *parent = 0);
+  ~VideoMode();
+
+  Q_INVOKABLE bool startRecording(const QString& fileName);
+
+  bool isRecording();
+
+public slots:
+  void stopRecording();
+
+signals:
+  void recordingStateChanged();
+
+protected:
+  virtual void preChangeMode();
+  virtual void postChangeMode();
+  virtual void changeMode();
+
+private:
+  QtCamVideoMode *m_video;
+};
+
+#endif /* VIDEO_MODE_H */
diff --git a/imports/videotorch.cpp b/imports/videotorch.cpp
new file mode 100644 (file)
index 0000000..290a30a
--- /dev/null
@@ -0,0 +1,61 @@
+#include "videotorch.h"
+#include "qtcamvideotorch.h"
+#include "camera.h"
+#include "qtcamdevice.h"
+#include "qtcamvideomode.h"
+
+VideoTorch::VideoTorch(QObject *parent) :
+  QObject(parent), m_cam(0), m_torch(0) {
+
+}
+
+VideoTorch::~VideoTorch() {
+  m_cam = 0;
+}
+
+Camera *VideoTorch::camera() {
+  return m_cam;
+}
+
+void VideoTorch::setCamera(Camera *camera) {
+  if (camera == m_cam) {
+    return;
+  }
+
+  if (m_cam) {
+    QObject::disconnect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
+  }
+
+  m_cam = camera;
+
+  if (m_cam) {
+    QObject::connect(m_cam, SIGNAL(deviceChanged()), this, SLOT(deviceChanged()));
+  }
+
+  emit cameraChanged();
+
+  deviceChanged();
+}
+
+bool VideoTorch::isOn() const {
+  return m_torch ? m_torch->isOn() : false;
+}
+
+void VideoTorch::setOn(bool on) {
+  if (m_torch) {
+    m_torch->setOn(on);
+  }
+}
+
+void VideoTorch::deviceChanged() {
+  if (m_torch) {
+    delete m_torch; m_torch = 0;
+  }
+
+  if (m_cam->device()) {
+    m_torch = new QtCamVideoTorch(m_cam->device(), this);
+    QObject::connect(m_torch, SIGNAL(stateChanged()), this, SIGNAL(stateChanged()));
+
+    emit stateChanged();
+  }
+}
diff --git a/imports/videotorch.h b/imports/videotorch.h
new file mode 100644 (file)
index 0000000..776cd21
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef VIDEO_TORCH_H
+#define VIDEO_TORCH_H
+
+#include <QObject>
+
+class Camera;
+class QtCamVideoTorch;
+
+class VideoTorch : public QObject {
+  Q_OBJECT
+  Q_PROPERTY(Camera* camera READ camera WRITE setCamera NOTIFY cameraChanged);
+  Q_PROPERTY(bool on READ isOn WRITE setOn NOTIFY stateChanged);
+
+public:
+  VideoTorch(QObject *parent = 0);
+  ~VideoTorch();
+
+  Camera *camera();
+  void setCamera(Camera *camera);
+
+  bool isOn() const;
+  void setOn(bool on);
+
+signals:
+  void stateChanged();
+  void cameraChanged();
+
+private slots:
+  void deviceChanged();
+
+private:
+  Camera *m_cam;
+  QtCamVideoTorch *m_torch;
+};
+
+#endif /* VIDEO_TORCH_H */
diff --git a/imports/whitebalance.cpp b/imports/whitebalance.cpp
new file mode 100644 (file)
index 0000000..dfb5236
--- /dev/null
@@ -0,0 +1,38 @@
+#include "whitebalance.h"
+#include "camera.h"
+#include <QDebug>
+
+WhiteBalance::WhiteBalance(QObject *parent) :
+  Capability(parent),
+  m_wb(0) {
+
+}
+
+WhiteBalance::~WhiteBalance() {
+  if (m_wb) {
+    delete m_wb; m_wb = 0;
+  }
+}
+
+void WhiteBalance::deviceChanged() {
+  if (m_wb) {
+    delete m_wb; m_wb = 0;
+  }
+
+  if (m_cam->device()) {
+    m_wb = new QtCamWhiteBalance(m_cam->device(), this);
+    QObject::connect(m_wb, SIGNAL(valueChanged()), this, SIGNAL(valueChanged()));
+  }
+
+  emit valueChanged();
+}
+
+WhiteBalance::WhiteBalanceMode WhiteBalance::value() {
+  return m_wb ? (WhiteBalanceMode)m_wb->value() : WhiteBalance::Auto;
+}
+
+void WhiteBalance::setValue(const WhiteBalance::WhiteBalanceMode& mode) {
+  if (m_wb) {
+    m_wb->setValue((QtCamWhiteBalance::WhiteBalanceMode)mode);
+  }
+}
diff --git a/imports/whitebalance.h b/imports/whitebalance.h
new file mode 100644 (file)
index 0000000..c16bcda
--- /dev/null
@@ -0,0 +1,40 @@
+// -*- c++ -*-
+
+#ifndef WHITE_BALANCE_H
+#define WHITE_BALANCE_H
+
+#include "capability.h"
+#include "qtcamwhitebalance.h"
+
+class WhiteBalance : public Capability {
+  Q_OBJECT
+
+  Q_PROPERTY(WhiteBalanceMode value READ value WRITE setValue NOTIFY valueChanged);
+  Q_ENUMS(WhiteBalanceMode);
+
+public:
+  typedef enum {
+    Auto = QtCamWhiteBalance::Auto,
+    Daylight = QtCamWhiteBalance::Daylight,
+    Cloudy = QtCamWhiteBalance::Cloudy,
+    Sunset = QtCamWhiteBalance::Sunset,
+    Tungsten = QtCamWhiteBalance::Tungsten,
+    Flourescent = QtCamWhiteBalance::Flourescent
+  } WhiteBalanceMode;
+
+  WhiteBalance(QObject *parent = 0);
+  ~WhiteBalance();
+
+  WhiteBalanceMode value();
+  void setValue(const WhiteBalanceMode& mode);
+
+signals:
+  void valueChanged();
+
+private:
+  virtual void deviceChanged();
+
+  QtCamWhiteBalance *m_wb;
+};
+
+#endif /* WHITE_BALANCE_H */
diff --git a/imports/zoom.cpp b/imports/zoom.cpp
new file mode 100644 (file)
index 0000000..30882fd
--- /dev/null
@@ -0,0 +1,52 @@
+#include "zoom.h"
+#include "camera.h"
+#include "qtcamzoom.h"
+
+Zoom::Zoom(QObject *parent) :
+  Capability(parent),
+  m_zoom(0) {
+
+}
+
+Zoom::~Zoom() {
+  if (m_zoom) {
+    delete m_zoom; m_zoom = 0;
+  }
+}
+
+void Zoom::deviceChanged() {
+  if (m_zoom) {
+    delete m_zoom; m_zoom = 0;
+  }
+
+  if (m_cam->device()) {
+    m_zoom = new QtCamZoom(m_cam->device(), this);
+    QObject::connect(m_zoom, SIGNAL(valueChanged()), this, SIGNAL(valueChanged()));
+    QObject::connect(m_zoom, SIGNAL(minimumValueChanged()), this, SIGNAL(minimumChanged()));
+    QObject::connect(m_zoom, SIGNAL(maximumValueChanged()), this, SIGNAL(maximunmChanged()));
+  }
+
+  emit valueChanged();
+  emit minimumChanged();
+  emit maximunmChanged();
+}
+
+qreal Zoom::value() {
+  return m_zoom ? m_zoom->value() : 1.0;
+}
+
+void Zoom::setValue(qreal val) {
+  if (m_zoom) {
+    m_zoom->setValue(val);
+  }
+}
+
+qreal Zoom::minimum() {
+  return m_zoom ? m_zoom->minimumValue() : 1.0;
+}
+
+qreal Zoom::maximum() {
+  return m_zoom ? m_zoom->maximumValue() : 1.0;
+}
+
+
diff --git a/imports/zoom.h b/imports/zoom.h
new file mode 100644 (file)
index 0000000..a365884
--- /dev/null
@@ -0,0 +1,38 @@
+// -*- c++ -*-
+
+#ifndef ZOOM_H
+#define ZOOM_H
+
+#include "capability.h"
+
+class QtCamZoom;
+
+class Zoom : public Capability {
+  Q_OBJECT
+
+  Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged);
+  Q_PROPERTY(qreal minimum READ minimum NOTIFY minimumChanged);
+  Q_PROPERTY(qreal maximum READ maximum NOTIFY maximunmChanged);
+
+public:
+  Zoom(QObject *parent = 0);
+  ~Zoom();
+
+  qreal value();
+  void setValue(qreal val);
+
+  qreal minimum();
+  qreal maximum();
+
+signals:
+  void valueChanged();
+  void minimumChanged();
+  void maximunmChanged();
+
+private:
+  virtual void deviceChanged();
+
+  QtCamZoom *m_zoom;
+};
+
+#endif /* ZOOM_H */