aboutsummaryrefslogtreecommitdiff
path: root/src/sensor.cpp
diff options
context:
space:
mode:
authorMageJohn <MageJohn@users.noreply.github.com>2019-02-19 16:59:06 +0000
committerGitHub <noreply@github.com>2019-02-19 16:59:06 +0000
commit7e9c4e1b9bfa3966cca992256b885f75c8660753 (patch)
treed1126cb0e6975ae678cd021c004ccf51f02b3079 /src/sensor.cpp
parenta1ddbe5b94b21877c1a082256857d2e6feb692fe (diff)
parentd843e6a66a11e07595c8c4964fb8a1d343172990 (diff)
downloadlead-7e9c4e1b9bfa3966cca992256b885f75c8660753.tar
lead-7e9c4e1b9bfa3966cca992256b885f75c8660753.tar.gz
lead-7e9c4e1b9bfa3966cca992256b885f75c8660753.zip
Merge pull request #1 from Almamu/master
Merge changes from Almamu
Diffstat (limited to 'src/sensor.cpp')
-rw-r--r--src/sensor.cpp70
1 files changed, 53 insertions, 17 deletions
diff --git a/src/sensor.cpp b/src/sensor.cpp
index 49fd149..597d4f9 100644
--- a/src/sensor.cpp
+++ b/src/sensor.cpp
@@ -34,18 +34,32 @@ SOFTWARE.
namespace Lead {
-Sensor::Sensor(int x, int y, int w, int h, QString action, int interval):
+Sensor::Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval):
QWidget(),
- action(action),
- interval(interval)
+ enterAction(enterAction),
+ exitAction(exitAction),
+ enterInterval(enterInterval),
+ exitInterval(exitInterval)
{
- qDebug() << "lead::Sensor() " << x << "," << y << "," << w << "," << h << " : action=" << action << " : interval=" << interval;
+ qDebug()
+ << "lead::Sensor() " << x << "," << y << "," << w << "," << h
+ << " : enterAction=" << enterAction
+ << " : exitAction=" << exitAction
+ << " : enterInterval=" << enterInterval
+ << " : exitInterval=" << exitInterval;
- this->timer = new QTimer(this);
- this->timer->setSingleShot(true);
- this->timer->setInterval(interval);
+ this->canTriggerExit = false;
- connect(this->timer, SIGNAL(timeout()), this, SLOT(activate()));
+ this->enterTimer = new QTimer(this);
+ this->enterTimer->setSingleShot(true);
+ this->enterTimer->setInterval(enterInterval);
+
+ this->exitTimer = new QTimer (this);
+ this->exitTimer->setSingleShot (true);
+ this->exitTimer->setInterval (exitInterval);
+
+ connect(this->enterTimer, SIGNAL(timeout()), this, SLOT(activateEnter()));
+ connect(this->exitTimer, SIGNAL(timeout()), this, SLOT(activateExit()));
//setStyleSheet("background-color:red;");
setGeometry(x, y, w, h);
@@ -58,34 +72,56 @@ Sensor::Sensor(int x, int y, int w, int h, QString action, int interval):
Sensor::~Sensor()
{
- delete this->timer;
+ delete this->enterTimer;
+ delete this->exitTimer;
}
void
Sensor::enterEvent(QEvent * event)
{
- qDebug() << "lead::Sensor::enterEvent() " << this->x() << ":" << this->y() << " interval: " << this->interval;
+ qDebug()
+ << "lead::Sensor::enterEvent() "<< this->x() << ":" << this->y()
+ << " enterInterval: " << this->enterTimer
+ << " exitInterval: " << this->exitTimer;
- this->timer->start();
+ this->enterTimer->start();
+ this->exitTimer->start();
}
void
Sensor::leaveEvent(QEvent * event)
{
- qDebug() << "lead::Sensor::leaveEvent() " << this->x() << ":" << this->y() << " interval: " << this->interval;
-
- this->timer->stop();
+ qDebug()
+ << "lead::Sensor::leaveEvent() "<< this->x() << ":" << this->y()
+ << " enterInterval: " << this->enterTimer
+ << " exitInterval: " << this->exitTimer;
+
+ if (this->canTriggerExit)
+ {
+ QProcess::startDetached(exitAction);
+ }
+
+ this->enterTimer->stop();
+ this->exitTimer->stop();
+ this->canTriggerExit = false;
}
void
-Sensor::activate()
+Sensor::activateEnter()
+{
+ qDebug() << "lead::Sensor::activateEnter() " << this->x() << ":" << this->y() << " action: " << this->enterAction;
+
+ QProcess::startDetached(enterAction);
+}
+
+void Sensor::activateExit()
{
- qDebug() << "lead::Sensor::activate() " << this->x() << ":" << this->y() << " action: " << this->action;
+ qDebug () << "lead::Sensor::activateExit() " << this->x() << ":" << this->y() << " action: " << this->exitAction << " can run now";
- QProcess::startDetached(action);
+ this->canTriggerExit = true;
}