aboutsummaryrefslogtreecommitdiff
path: root/src/sensor.cpp
diff options
context:
space:
mode:
authorAlexis Maiquez Murcia <almamu@almamu.com>2019-02-19 16:56:26 +0100
committerAlexis Maiquez Murcia <almamu@almamu.com>2019-02-19 16:56:26 +0100
commita64ffe1153d7b637007c2dde8bd39c559c97a1fe (patch)
treed1b7d773b093fd5f9e82d6ec7fdbc2437e40431a /src/sensor.cpp
parent81aba56ae3ff565d5650ead18344c0d66ee62579 (diff)
downloadlead-a64ffe1153d7b637007c2dde8bd39c559c97a1fe.tar
lead-a64ffe1153d7b637007c2dde8bd39c559c97a1fe.tar.gz
lead-a64ffe1153d7b637007c2dde8bd39c559c97a1fe.zip
Added support for sensor leaving events with delay support
Here delay means the time the mouse has to be in the sensor for the leave event to trigger the action Signed-off-by: Alexis Maiquez Murcia <almamu@almamu.com>
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;
}