Volume up and down keys should now work and change zoom
authorMohammed Sameer <msameer@foolab.org>
Wed, 2 Jan 2013 00:39:49 +0000 (02:39 +0200)
committerMohammed Sameer <msameer@foolab.org>
Wed, 2 Jan 2013 00:39:49 +0000 (02:39 +0200)
qml/PipelineManager.qml
qml/VideoPlayerPage.qml
qml/ZoomSlider.qml
qml/main.qml
src/cameraresources.cpp
src/cameraresources.h
src/devicekeys.cpp [new file with mode: 0644]
src/devicekeys.h [new file with mode: 0644]
src/main.cpp
src/src.pro

index eb51bad..8e5d5eb 100644 (file)
@@ -33,6 +33,7 @@ Item {
 
         property alias acquired: policy.acquired
         property alias hijacked: policy.hijacked
+        property alias scaleAcquired: policy.scaleAcquired
 
         property Camera camera: null
         property Item currentPage: pageStack.currentPage
index 4e1e10e..6e7eaae 100644 (file)
@@ -80,6 +80,7 @@ CameraPage {
                 }
         }
 
+        // TODO: auto-hide this
         CameraToolBar {
                 id: toolBar
 
index 38debe3..fc0fb40 100644 (file)
@@ -44,6 +44,18 @@ Slider {
                 onModeChanged: slider.value = camera.zoom.minimum;
         }
 
+        Connections {
+                target: keys
+                // TODO: state change for slider to "visible"
+                onVolumeUpPressed: {
+                        slider.value = Math.min(slider.value + slider.stepSize, slider.maximumValue);
+                }
+
+                onVolumeDownPressed: {
+                        slider.value = Math.max(slider.value - slider.stepSize, slider.minimumValue);
+                }
+        }
+
         orientation: Qt.Horizontal
         width: 500
         height: 50
index a9c9c15..f227b91 100644 (file)
@@ -446,4 +446,9 @@ PageStackWindow {
                 policyLost: pipelineManager.state == "policyLost"
                 show: !pageStack.currentPage || (pageStack.currentPage.standbyVisible && pageStack.currentPage.status == PageStatus.Active && pipelineManager.showStandBy)
         }
+
+        DeviceKeys {
+                id: keys
+                active: Qt.application.active && pipelineManager.scaleAcquired
+        }
 }
index b81c736..f464e40 100644 (file)
@@ -35,12 +35,14 @@ CameraResources::CameraResources(QObject *parent) :
   m_thread.start();
 
   qRegisterMetaType<CameraResources::Mode>("CameraResources::Mode");
-  qRegisterMetaType<CameraResources::ResourceType>("CameraResources::ResourceType");
   qRegisterMetaType<bool *>("bool *");
 
   QObject::connect(m_worker, SIGNAL(acquiredChanged()), this, SIGNAL(acquiredChanged()));
   QObject::connect(m_worker, SIGNAL(hijackedChanged()), this, SIGNAL(hijackedChanged()));
   QObject::connect(m_worker, SIGNAL(updated()), this, SIGNAL(updated()));
+  QObject::connect(m_worker, SIGNAL(acquiredChanged()), this, SIGNAL(scaleAcquisitionChanged()));
+  QObject::connect(m_worker, SIGNAL(hijackedChanged()), this, SIGNAL(scaleAcquisitionChanged()));
+  QObject::connect(m_worker, SIGNAL(updated()), this, SIGNAL(scaleAcquisitionChanged()));
 }
 
 CameraResources::~CameraResources() {
@@ -55,11 +57,11 @@ CameraResources::~CameraResources() {
   m_worker = 0;
 }
 
-bool CameraResources::isResourceGranted(const ResourceType& resource) {
+bool CameraResources::isResourceGranted(const ResourcePolicy::ResourceType& resource) const {
   bool ok = false;
 
   QMetaObject::invokeMethod(m_worker, "isResourceGranted", Qt::BlockingQueuedConnection,
-                           Q_ARG(bool *, &ok), Q_ARG(CameraResources::ResourceType, resource));
+                           Q_ARG(bool *, &ok), Q_ARG(int, resource));
 
   return ok;
 }
@@ -91,6 +93,10 @@ bool CameraResources::hijacked() const {
   return ok;
 }
 
+bool CameraResources::isScaleAcquired() const {
+  return isResourceGranted(ResourcePolicy::ScaleButtonType);
+}
+
 CameraResourcesWorker::CameraResourcesWorker(QObject *parent) :
   QObject(parent),
   m_set(0),
@@ -310,8 +316,7 @@ void CameraResourcesWorker::setHijacked(bool hijacked) {
   }
 }
 
-void CameraResourcesWorker::isResourceGranted(bool *ok,
-                                             const CameraResources::ResourceType& resource) {
+void CameraResourcesWorker::isResourceGranted(bool *ok, int resource) {
 
   ResourcePolicy::ResourceType rt = (ResourcePolicy::ResourceType)resource;
 
index 9dcb67d..ba1e448 100644 (file)
@@ -34,6 +34,7 @@ class CameraResources : public QObject {
 
   Q_PROPERTY(bool acquired READ acquired NOTIFY acquiredChanged);
   Q_PROPERTY(bool hijacked READ hijacked NOTIFY hijackedChanged);
+  Q_PROPERTY(bool scaleAcquired READ isScaleAcquired NOTIFY scaleAcquisitionChanged);
 
   Q_ENUMS(Mode);
   Q_ENUMS(ResourceType);
@@ -47,32 +48,24 @@ public:
     PostCapture,
   } Mode;
 
-  typedef enum {
-    AudioPlaybackType = ResourcePolicy::AudioPlaybackType,
-    VideoPlaybackType = ResourcePolicy::VideoPlaybackType,
-    AudioRecorderType = ResourcePolicy::AudioRecorderType,
-    VideoRecorderType = ResourcePolicy::VideoRecorderType,
-    ScaleButtonType = ResourcePolicy::ScaleButtonType,
-    SnapButtonType = ResourcePolicy::SnapButtonType,
-    LensCoverType = ResourcePolicy::LensCoverType,
-  } ResourceType;
-
   CameraResources(QObject *parent = 0);
   ~CameraResources();
 
   Q_INVOKABLE bool acquire(const Mode& mode);
 
-  Q_INVOKABLE bool isResourceGranted(const ResourceType& resource);
-
   bool acquired() const;
   bool hijacked() const;
+  bool isScaleAcquired() const;
 
 signals:
   void acquiredChanged();
   void hijackedChanged();
   void updated();
+  void scaleAcquisitionChanged();
 
 private:
+  bool isResourceGranted(const ResourcePolicy::ResourceType& resource) const;
+
   CameraResourcesWorker *m_worker;
   QThread m_thread;
 };
@@ -88,7 +81,7 @@ public slots:
   void acquire(bool *ok, const CameraResources::Mode& mode);
   void acquired(bool *ok);
   void hijacked(bool *ok);
-  void isResourceGranted(bool *ok, const CameraResources::ResourceType& resource);
+  void isResourceGranted(bool *ok, int resource);
 
 signals:
   void acquiredChanged();
diff --git a/src/devicekeys.cpp b/src/devicekeys.cpp
new file mode 100644 (file)
index 0000000..8277fe9
--- /dev/null
@@ -0,0 +1,74 @@
+/*!
+ * 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 "devicekeys.h"
+#include <QDebug>
+
+DeviceKeys::DeviceKeys(QObject *parent) :
+  QObject(parent),
+  m_keys(0) {
+
+}
+
+DeviceKeys::~DeviceKeys() {
+  setActive(false);
+}
+
+bool DeviceKeys::isActive() const {
+  return m_keys != 0;
+}
+
+void DeviceKeys::setActive(bool active) {
+  if (active == isActive()) {
+    return;
+  }
+
+  if (!active) {
+    m_keys->deleteLater();
+    m_keys = 0;
+  }
+  else {
+    m_keys = new MeeGo::QmKeys(this);
+    QObject::connect(m_keys, SIGNAL(keyEvent(MeeGo::QmKeys::Key, MeeGo::QmKeys::State)),
+                    this, SLOT(keyEvent(MeeGo::QmKeys::Key, MeeGo::QmKeys::State)));
+  }
+
+  emit activeChanged();
+}
+
+void DeviceKeys::keyEvent(MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state) {
+  if (key == MeeGo::QmKeys::VolumeUp) {
+    if (state == MeeGo::QmKeys::KeyUp) {
+      emit volumeUpReleased();
+    }
+    else if (state == MeeGo::QmKeys::KeyDown) {
+      emit volumeUpPressed();
+    }
+  }
+  else if (key == MeeGo::QmKeys::VolumeDown) {
+    if (state == MeeGo::QmKeys::KeyUp) {
+      emit volumeDownReleased();
+    }
+    else if (state == MeeGo::QmKeys::KeyDown) {
+      emit volumeDownPressed();
+    }
+  }
+}
+
diff --git a/src/devicekeys.h b/src/devicekeys.h
new file mode 100644 (file)
index 0000000..8c740d3
--- /dev/null
@@ -0,0 +1,55 @@
+// -*- 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 DEVICE_KEYS_H
+#define DEVICE_KEYS_H
+
+#include <QObject>
+#include <qmkeys.h>
+
+class DeviceKeys : public QObject {
+  Q_OBJECT
+
+  Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged);
+
+public:
+  DeviceKeys(QObject *parent = 0);
+  ~DeviceKeys();
+
+  bool isActive() const;
+  void setActive(bool active);
+
+signals:
+  void activeChanged();
+  void volumeUpPressed();
+  void volumeUpReleased();
+  void volumeDownPressed();
+  void volumeDownReleased();
+
+private slots:
+  void keyEvent(MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state);
+
+private:
+  MeeGo::QmKeys *m_keys;
+};
+
+#endif /* DEVICE_KEYS_H */
index 45c96bd..64f6a38 100644 (file)
@@ -47,6 +47,7 @@
 #include "batteryinfo.h"
 #include "gridlines.h"
 #include "deviceinfo.h"
+#include "devicekeys.h"
 
 #ifdef QMLJSDEBUGGER
 #include "qt_private/qdeclarativedebughelper_p.h"
@@ -104,6 +105,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) {
   qmlRegisterType<BatteryInfo>("CameraPlus", 1, 0, "BatteryInfo");
   qmlRegisterType<GridLines>("CameraPlus", 1, 0, "GridLines");
   qmlRegisterType<DeviceInfo>("CameraPlus", 1, 0, "DeviceInfo");
+  qmlRegisterType<DeviceKeys>("CameraPlus", 1, 0, "DeviceKeys");
 
   view.setSource(QUrl("qrc:/qml/main.qml"));
 
index aa3db38..3fdcaec 100644 (file)
@@ -18,12 +18,12 @@ LIBS +=  -L../imports/ -limports -L../lib/ -lqtcamera
 SOURCES += main.cpp settings.cpp filenaming.cpp quillitem.cpp displaystate.cpp fsmonitor.cpp \
            cameraresources.cpp compass.cpp orientation.cpp geocode.cpp mountprotector.cpp \
            trackerstore.cpp focusrectangle.cpp sharehelper.cpp deletehelper.cpp galleryhelper.cpp \
-           postcapturemodel.cpp batteryinfo.cpp gridlines.cpp deviceinfo.cpp
+           postcapturemodel.cpp batteryinfo.cpp gridlines.cpp deviceinfo.cpp devicekeys.cpp
 
 HEADERS += settings.h filenaming.h quillitem.h displaystate.h fsmonitor.h \
            cameraresources.h compass.h orientation.h geocode.h mountprotector.h \
            trackerstore.h focusrectangle.h sharehelper.h deletehelper.h galleryhelper.h \
-           postcapturemodel.h batteryinfo.h gridlines.h deviceinfo.h
+           postcapturemodel.h batteryinfo.h gridlines.h deviceinfo.h devicekeys.h
 
 RESOURCES += ../qml/qml.qrc