Added repeat property to DeviceKeys
authorMohammed Sameer <msameer@foolab.org>
Sat, 23 Mar 2013 22:44:37 +0000 (00:44 +0200)
committerMohammed Sameer <msameer@foolab.org>
Sat, 23 Mar 2013 22:44:37 +0000 (00:44 +0200)
We should not repeat key presses when we use zoom key as shutter.

qml/main.qml
src/devicekeys.cpp
src/devicekeys.h

index c34841d..7f9c35d 100644 (file)
@@ -449,5 +449,6 @@ PageStackWindow {
         DeviceKeys {
                 id: keys
                 active: Qt.application.active && pipelineManager.scaleAcquired
+                repeat: !settings.zoomAsShutter
         }
 }
index e6230e9..7025805 100644 (file)
@@ -23,7 +23,8 @@
 
 DeviceKeys::DeviceKeys(QObject *parent) :
   QObject(parent),
-  m_keys(0) {
+  m_keys(0),
+  m_repeating(true) {
 
 }
 
@@ -43,6 +44,7 @@ void DeviceKeys::setActive(bool active) {
   if (!active) {
     m_keys->deleteLater();
     m_keys = 0;
+    m_stats.clear();
   }
   else {
     m_keys = new MeeGo::QmKeys(this);
@@ -54,6 +56,10 @@ void DeviceKeys::setActive(bool active) {
 }
 
 void DeviceKeys::keyEvent(MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state) {
+  if (!setStats(key, state)) {
+    return;
+  }
+
   if (key == MeeGo::QmKeys::VolumeUp) {
     if (state == MeeGo::QmKeys::KeyUp) {
       emit volumeUpReleased();
@@ -72,3 +78,31 @@ void DeviceKeys::keyEvent(MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state) {
   }
 }
 
+bool DeviceKeys::setStats(MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state) {
+  if (m_repeating) {
+    return true;
+  }
+
+  if (!m_stats.contains(key)) {
+    m_stats.insert(key, state);
+    return true;
+  }
+
+  if (m_stats[key] != state) {
+    m_stats[key] = state;
+    return true;
+  }
+
+  return false;
+}
+
+bool DeviceKeys::isRepeating() {
+  return m_repeating;
+}
+
+void DeviceKeys::doRepeat(bool repeat) {
+  if (repeat != m_repeating) {
+    m_repeating = repeat;
+    emit repeatChanged();
+  }
+}
index 7427021..3478132 100644 (file)
 
 #include <QObject>
 #include <qmkeys.h>
+#include <QMap>
 
 class DeviceKeys : public QObject {
   Q_OBJECT
 
   Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged);
+  Q_PROPERTY(bool repeat READ isRepeating WRITE doRepeat NOTIFY repeatChanged);
 
 public:
   DeviceKeys(QObject *parent = 0);
@@ -38,18 +40,26 @@ public:
   bool isActive() const;
   void setActive(bool active);
 
+  bool isRepeating();
+  void doRepeat(bool repeat);
+
 signals:
   void activeChanged();
   void volumeUpPressed();
   void volumeUpReleased();
   void volumeDownPressed();
   void volumeDownReleased();
+  void repeatChanged();
 
 private slots:
   void keyEvent(MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state);
 
 private:
+  bool setStats(MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state);
+
   MeeGo::QmKeys *m_keys;
+  QMap<MeeGo::QmKeys::Key, MeeGo::QmKeys::State> m_stats;
+  bool m_repeating;
 };
 
 #endif /* DEVICE_KEYS_H */