summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtIdleDetector.cpp22
-rw-r--r--Swift/QtUI/QtIdleDetector.h17
2 files changed, 36 insertions, 3 deletions
diff --git a/Swift/QtUI/QtIdleDetector.cpp b/Swift/QtUI/QtIdleDetector.cpp
index e947854..783cc14 100644
--- a/Swift/QtUI/QtIdleDetector.cpp
+++ b/Swift/QtUI/QtIdleDetector.cpp
@@ -1,8 +1,15 @@
#include "QtIdleDetector.h"
+#include <QCursor>
+
namespace Swift {
QtIdleDetector::QtIdleDetector() {
+ signalled_ = false;
+ lastMoveTime_ = QDateTime::currentDateTime();
+ lastPosition_ = QCursor::pos();
+ connect(&timer_, SIGNAL(timeout()), this, SLOT(handleTimerTick()));
+ timer_.start(1000);
}
QtIdleDetector::~QtIdleDetector() {
@@ -12,5 +19,20 @@ void QtIdleDetector::forceNotIdle() {
}
+void QtIdleDetector::handleTimerTick() {
+ QPoint position = QCursor::pos();
+ QDateTime now = QDateTime::currentDateTime();
+ if (position != lastPosition_) {
+ if (signalled_) {
+ onInputNotIdle();
+ }
+ lastPosition_ = position;
+ lastMoveTime_ = now;
+ signalled_ = false;
+ } else if (!signalled_ && now > lastMoveTime_.addSecs(600) && position == lastPosition_) {
+ signalled_ = true;
+ onInputIdle();
+ }
+}
}
diff --git a/Swift/QtUI/QtIdleDetector.h b/Swift/QtUI/QtIdleDetector.h
index e21e4a8..444fb15 100644
--- a/Swift/QtUI/QtIdleDetector.h
+++ b/Swift/QtUI/QtIdleDetector.h
@@ -2,13 +2,24 @@
#include "Swift/Controllers/IdleDetector.h"
+#include <QObject>
+#include <QPoint>
+#include <QTimer>
+#include <QDateTime>
+
namespace Swift {
-class QtIdleDetector : public IdleDetector {
+class QtIdleDetector : public QObject, public IdleDetector {
+ Q_OBJECT
public:
QtIdleDetector();
virtual ~QtIdleDetector();
virtual void forceNotIdle();
-
-
+ private slots:
+ void handleTimerTick();
+ private:
+ QPoint lastPosition_;
+ QDateTime lastMoveTime_;
+ QTimer timer_;
+ bool signalled_;
};
}