aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.cpp43
-rw-r--r--src/sensor.cpp70
-rw-r--r--src/sensor.h15
3 files changed, 98 insertions, 30 deletions
diff --git a/src/app.cpp b/src/app.cpp
index 06f4daa..1dd94cc 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -143,29 +143,56 @@ App::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h)
return;
}
- QString sensorName = settings.value (sensorNameKey).toString ();
- QString sensorAction = sensorName + "/action";
- QString sensorDelay = sensorName + "/delay";
+ QString sensorName = settings.value (sensorNameKey).toString ();
+ QString sensorEnterAction = sensorName + "/enterAction";
+ QString sensorExitAction = sensorName + "/exitAction";
+ QString sensorEnterDelay = sensorName + "/enterDelay";
+ QString sensorExitDelay = sensorName + "/exitDelay";
+ int emptyCount = 0;
if (sensorName.isEmpty () == true)
{
return;
}
- if (!settings.contains (sensorAction))
+ if (!settings.contains (sensorEnterAction))
{
- qDebug () << "App::loadSensor () sensor " << sensorName << " does not have action; ignoring...";
+ emptyCount ++;
+ }
+
+ if (!settings.contains (sensorExitAction))
+ {
+ emptyCount ++;
+ }
+
+ if (emptyCount == 2)
+ {
+ qDebug () << "App::loadSensor () sensor " << sensorName << " does not have any action in it, ignoring...";
return;
}
- if (!settings.contains (sensorDelay))
+ if (!settings.contains (sensorEnterDelay))
{
qDebug () << "App::loadSensor () sensor " << sensorName << " does not have delay; setting to 0";
- settings.setValue (sensorDelay, QVariant (0));
+ settings.setValue (sensorEnterDelay, QVariant (0));
+ }
+
+ if (!settings.contains (sensorExitDelay))
+ {
+ qDebug () << "App::loadSensor () sensor " << sensorName << " does not have exit delay; setting to 0";
+ settings.setValue (sensorExitDelay, QVariant (0));
}
qDebug () << "App::loadSensor () loaded sensor " << sensorName << " on screen " + screen->name();
- sensors.append (new Sensor (x, y, w, h, settings.value (sensorAction).toString (), settings.value (sensorDelay).toInt ()));
+ sensors.append (
+ new Sensor (
+ x, y, w, h,
+ settings.value (sensorEnterAction).toString (),
+ settings.value (sensorExitAction).toString (),
+ settings.value (sensorEnterDelay).toInt (),
+ settings.value (sensorExitDelay).toInt ()
+ )
+ );
}
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;
}
diff --git a/src/sensor.h b/src/sensor.h
index ed5add8..bc4857b 100644
--- a/src/sensor.h
+++ b/src/sensor.h
@@ -41,7 +41,7 @@ class Sensor : public QWidget
Q_OBJECT
public:
- explicit Sensor(int x, int y, int w, int h, QString action, int interval);
+ explicit Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval);
~Sensor();
protected:
@@ -49,12 +49,17 @@ protected:
void leaveEvent(QEvent * event);
private:
- QString action;
- QTimer *timer;
- int interval;
+ QString enterAction;
+ QString exitAction;
+ QTimer *enterTimer;
+ QTimer *exitTimer;
+ int enterInterval;
+ int exitInterval;
+ bool canTriggerExit;
public slots:
- void activate();
+ void activateEnter();
+ void activateExit();
};