Added AutoFocus QML component
authorMohammed Sameer <msameer@foolab.org>
Wed, 31 Oct 2012 01:15:41 +0000 (03:15 +0200)
committerMohammed Sameer <msameer@foolab.org>
Wed, 31 Oct 2012 01:15:41 +0000 (03:15 +0200)
imports/autofocus.cpp [new file with mode: 0644]
imports/autofocus.h [new file with mode: 0644]
imports/imports.pro
imports/plugin.cpp

diff --git a/imports/autofocus.cpp b/imports/autofocus.cpp
new file mode 100644 (file)
index 0000000..aedfd33
--- /dev/null
@@ -0,0 +1,72 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "autofocus.h"
+#include "camera.h"
+
+AutoFocus::AutoFocus(QObject *parent) :
+  Capability(parent),
+  m_af(0) {
+
+}
+AutoFocus::~AutoFocus() {
+  if (m_af) {
+    delete m_af; m_af = 0;
+  }
+}
+
+void AutoFocus::deviceChanged() {
+  if (m_af) {
+    delete m_af; m_af = 0;
+  }
+
+  if (m_cam->device()) {
+    m_af = new QtCamAutoFocus(m_cam->device(), this);
+    QObject::connect(m_af, SIGNAL(statusChanged()), this, SIGNAL(valueChanged()));
+    QObject::connect(m_af, SIGNAL(cafStatusChanged()), this, SIGNAL(cafValueChanged()));
+  }
+
+  emit valueChanged();
+  emit cafValueChanged();
+}
+
+AutoFocus::Status AutoFocus::status() {
+  return m_af ? (AutoFocus::Status)m_af->status() : AutoFocus::None;
+}
+
+AutoFocus::Status AutoFocus::cafStatus() {
+  return m_af ? (AutoFocus::Status)m_af->cafStatus() : AutoFocus::None;
+}
+
+bool AutoFocus::startAutoFocus() {
+  if (m_af) {
+    return m_af->startAutoFocus();
+  }
+
+  return false;
+}
+
+bool AutoFocus::stopAutoFocus() {
+  if (m_af) {
+    return m_af->stopAutoFocus();
+  }
+
+  return false;
+}
diff --git a/imports/autofocus.h b/imports/autofocus.h
new file mode 100644 (file)
index 0000000..ffa9512
--- /dev/null
@@ -0,0 +1,62 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef AUTO_FOCUS_H
+#define AUTO_FOCUS_H
+
+#include "capability.h"
+#include "qtcamautofocus.h"
+
+class AutoFocus : public Capability {
+  Q_OBJECT
+  Q_PROPERTY(Status status READ status NOTIFY valueChanged);
+  Q_PROPERTY(Status cafStatus READ cafStatus NOTIFY cafValueChanged);
+  Q_ENUMS(Status);
+
+public:
+  typedef enum {
+    None = QtCamAutoFocus::None,
+    Running = QtCamAutoFocus::Running,
+    Fail = QtCamAutoFocus::Fail,
+    Success = QtCamAutoFocus::Success,
+  } Status;
+
+  AutoFocus(QObject *parent = 0);
+  ~AutoFocus();
+
+  Q_INVOKABLE bool startAutoFocus();
+  Q_INVOKABLE bool stopAutoFocus();
+
+  Status status();
+  Status cafStatus();
+
+signals:
+  void valueChanged();
+  void cafValueChanged();
+
+private:
+  virtual void deviceChanged();
+
+  QtCamAutoFocus *m_af;
+};
+
+#endif /* AUTO_FOCUS_H */
index 65b67ab..7c186b8 100644 (file)
@@ -15,11 +15,11 @@ HEADERS += plugin.h previewprovider.h camera.h mode.h imagemode.h videomode.h \
            colortone.h exposure.h aperture.h iso.h noisereduction.h \
            flickerreduction.h mute.h metadata.h imagesettings.h imageresolutionmodel.h \
            videosettings.h videoresolutionmodel.h notifications.h \
-           notificationscontainer.h sounds.h focus.h
+           notificationscontainer.h sounds.h focus.h autofocus.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 exposure.cpp aperture.cpp iso.cpp noisereduction.cpp \
            flickerreduction.cpp mute.cpp metadata.cpp imagesettings.cpp imageresolutionmodel.cpp \
            videosettings.cpp videoresolutionmodel.cpp notifications.cpp \
-           notificationscontainer.cpp sounds.cpp focus.cpp
+           notificationscontainer.cpp sounds.cpp focus.cpp autofocus.cpp
index 3585312..b58c065 100644 (file)
@@ -37,6 +37,7 @@
 #include "noisereduction.h"
 #include "flickerreduction.h"
 #include "focus.h"
+#include "autofocus.h"
 #include "mute.h"
 #include "metadata.h"
 #include "imagesettings.h"
@@ -69,6 +70,7 @@ void Plugin::registerTypes(QDeclarativeEngine *engine) {
   qmlRegisterType<NoiseReduction>(URI, MAJOR, MINOR, "NoiseReduction");
   qmlRegisterType<FlickerReduction>(URI, MAJOR, MINOR, "FlickerReduction");
   qmlRegisterType<Focus>(URI, MAJOR, MINOR, "Focus");
+  qmlRegisterType<AutoFocus>(URI, MAJOR, MINOR, "AutoFocus");
   qmlRegisterType<Mute>(URI, MAJOR, MINOR, "Mute");
   qmlRegisterType<MetaData>(URI, MAJOR, MINOR, "MetaData");
   qmlRegisterType<ImageSettings>(URI, MAJOR, MINOR, "ImageSettings");