Added an option to enable using proximity sensor to capture
authorMohammed Sameer <msameer@foolab.org>
Sat, 24 Aug 2013 09:18:00 +0000 (12:18 +0300)
committerMohammed Sameer <msameer@foolab.org>
Sat, 24 Aug 2013 09:18:00 +0000 (12:18 +0300)
qml/CameraSettings.qml
qml/MainPage.qml
qml/harmattan/CameraProximitySensor.qml [new file with mode: 0644]
qml/harmattan/harmattan.qrc
src/settings.cpp
src/settings.h

index 1a504a3..993c262 100644 (file)
@@ -91,6 +91,15 @@ Column {
         onCheckedChanged: settings.zoomAsShutter = checked
     }
 
+    TextSwitch {
+        text: qsTr("Use proximity sensor for capture")
+
+        // We have to do it that way because QML complains about a binding
+        // loop for checked if we bind the checked property to the settings value.
+        Component.onCompleted: checked = settings.proximityAsShutter
+        onCheckedChanged: settings.proximityAsShutter = checked
+    }
+
     TextSwitch {
         text: qsTr("Enable camera sounds")
 
index 37f80c5..151b55a 100644 (file)
@@ -276,6 +276,12 @@ CameraPage {
         repeat: !settings.zoomAsShutter
     }
 
+    CameraProximitySensor {
+        id: proximitySensor
+        active: Qt.application.active && viewfinder.camera.running && settings.proximityAsShutter
+    }
+
+    // TODO:
     Standby {
         policyLost: pipelineManager.state == "policyLost"
         show: !Qt.application.active || pipelineManager.showStandBy ||
diff --git a/qml/harmattan/CameraProximitySensor.qml b/qml/harmattan/CameraProximitySensor.qml
new file mode 100644 (file)
index 0000000..2f7857c
--- /dev/null
@@ -0,0 +1,31 @@
+// -*- qml -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012-2013 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
+ */
+
+import QtQuick 1.1
+import QtMobility.sensors 1.2
+
+ProximitySensor {
+    property bool close
+    onReadingChanged: close = reading.close
+    Component.onCompleted: close = reading.close
+    onActiveChanged: close = false
+}
index bbe0dfe..be7d401 100644 (file)
@@ -15,5 +15,6 @@
        <file>FullScreenThumbnail.qml</file>
        <file>CameraPositionSource.qml</file>
        <file>CameraPage.qml</file>
+       <file>CameraProximitySensor.qml</file>
     </qresource>
 </RCC>
index 05ae2bc..dff01d0 100644 (file)
@@ -34,6 +34,7 @@
 #define DEFAULT_GRID_ENABLED            false
 #define DEFAULT_FACE_DETECTION_ENABLED  true
 #define DEFAULT_ZOOM_AS_SHUTTER         false
+#define DEFAULT_PROXIMITY_AS_SHUTTER    false
 #define DEFAULT_DEVICE                  0
 
 Settings::Settings(QObject *parent) :
@@ -164,6 +165,18 @@ void Settings::setZoomAsShutterEnabled(bool enabled) {
   }
 }
 
+bool Settings::isProximityAsShutterEnabled() const {
+  return m_settings->value("camera/proximityAsShutter", DEFAULT_PROXIMITY_AS_SHUTTER).toBool();
+}
+
+void Settings::setProximityAsShutterEnabled(bool enabled) {
+  if (isProximityAsShutterEnabled() != enabled) {
+    m_settings->setValue("camera/proximityAsShutter", enabled);
+
+    emit proximityAsShutterChanged();
+  }
+}
+
 int Settings::device() const {
   return m_settings->value("camera/device", DEFAULT_DEVICE).toInt();
 }
index 6b16cdc..b6ccaac 100644 (file)
@@ -64,6 +64,7 @@ class Settings : public QObject {
 
   Q_PROPERTY(bool faceDetectionEnabled READ isFaceDetectionEnabled WRITE setFaceDetectionEnabled NOTIFY faceDetectionEnabledChanged);
   Q_PROPERTY(bool zoomAsShutter READ isZoomAsShutterEnabled WRITE setZoomAsShutterEnabled NOTIFY zoomAsShutterChanged);
+  Q_PROPERTY(bool proximityAsShutter READ isProximityAsShutterEnabled WRITE setProximityAsShutterEnabled NOTIFY proximityAsShutterChanged);
   Q_PROPERTY(int device READ device WRITE setDevice NOTIFY deviceChanged);
 
 public:
@@ -145,6 +146,9 @@ public:
   bool isZoomAsShutterEnabled() const;
   void setZoomAsShutterEnabled(bool enabled);
 
+  bool isProximityAsShutterEnabled() const;
+  void setProximityAsShutterEnabled(bool enabled);
+
   int device() const;
   void setDevice(int device);
 
@@ -180,6 +184,7 @@ signals:
   void gridEnabledChanged();
   void faceDetectionEnabledChanged();
   void zoomAsShutterChanged();
+  void proximityAsShutterChanged();
   void deviceAboutToChange();
   void deviceChanged();