summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-10-25 17:20:54 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-10-25 17:20:54 (GMT)
commit22b51f8f82f6bd3186339b05943c1e19aa71050f (patch)
tree65f5444a7e6213ae4caa58b03b9ab974e9dc10d4 /Swift/QtUI
parentbfdf408bed69a279eb710de915e932764ceaed76 (diff)
downloadswift-contrib-22b51f8f82f6bd3186339b05943c1e19aa71050f.zip
swift-contrib-22b51f8f82f6bd3186339b05943c1e19aa71050f.tar.bz2
Autoaway.
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_;
};
}