From d2d6f9acd776f00f961fe4fca78ce4ec13be12c5 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Murcia Date: Tue, 19 Feb 2019 16:25:04 +0100 Subject: ~ Simplified sensor's configuration load to make the ini more configurable and re-usable across screens Signed-off-by: Alexis Maiquez Murcia --- src/app.cpp | 50 +++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/app.cpp b/src/app.cpp index 1b63b72..93f7384 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -136,40 +136,36 @@ App::loadScreen(QScreen* screen) void App::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h) { + QString sensorsListKey = screen->name() + "/" + name; - QString action = screen->name() + "/" + name + "-" + "action"; - QString interval = screen->name() + "/" + name + "-" + "interval"; - - if (!settings.contains(interval)) - { - qDebug() << "App::loadSensor() interval for " << name << " not found; setting to 0"; - - // set default - settings.setValue(interval, QVariant(0)); - } - - if (!settings.contains(action)) + if (settings.contains (sensorsListKey) == false) { - qDebug() << "App::loadSensor() action for " << name << " not found; creating empty key"; - - // restore missing action - settings.setValue(action, QString()); return; } - if (settings.value(action).toString().isEmpty()) + QStringList sensorsList = settings.value (sensorsListKey).toString ().split (';', QString::SkipEmptyParts); + + for (int i = 0; i < sensorsList.size (); i ++) { - qDebug() << "App::loadSensor() action for " << name << " is empty"; - return; + QString sensorName = sensorsList.at (i); + QString sensorAction = sensorName + "/action"; + QString sensorDelay = sensorName + "/delay"; + + if (!settings.contains (sensorAction)) + { + qDebug () << "App::loadSensor () sensor " << sensorName << " does not have action; ignoring..."; + continue; + } + + if (!settings.contains (sensorDelay)) + { + qDebug () << "App::loadSensor () sensor " << sensorName << " does not have delay; setting to 0"; + settings.setValue (sensorDelay, 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 ())); } - - - // create sensor and save in list so we can delete all sensors on delete - - qDebug() << "App::loadSensor() action for " << name << " is " << settings.value(action).toString(); - qDebug() << "App::loadSensor() interval for " << name << " is " << settings.value(interval).toInt(); - - sensors.append( new Sensor(x, y, w, h, settings.value(action).toString(), settings.value(interval).toInt()) ); } -- cgit v1.2.3 From 81aba56ae3ff565d5650ead18344c0d66ee62579 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Murcia Date: Tue, 19 Feb 2019 16:37:51 +0100 Subject: - Removed the loop as that was useless Signed-off-by: Alexis Maiquez Murcia --- src/app.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/app.cpp b/src/app.cpp index 93f7384..06f4daa 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -136,36 +136,36 @@ App::loadScreen(QScreen* screen) void App::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h) { - QString sensorsListKey = screen->name() + "/" + name; + QString sensorNameKey = screen->name() + "/" + name; - if (settings.contains (sensorsListKey) == false) + if (settings.contains (sensorNameKey) == false) { return; } - QStringList sensorsList = settings.value (sensorsListKey).toString ().split (';', QString::SkipEmptyParts); + QString sensorName = settings.value (sensorNameKey).toString (); + QString sensorAction = sensorName + "/action"; + QString sensorDelay = sensorName + "/delay"; - for (int i = 0; i < sensorsList.size (); i ++) + if (sensorName.isEmpty () == true) { - QString sensorName = sensorsList.at (i); - QString sensorAction = sensorName + "/action"; - QString sensorDelay = sensorName + "/delay"; - - if (!settings.contains (sensorAction)) - { - qDebug () << "App::loadSensor () sensor " << sensorName << " does not have action; ignoring..."; - continue; - } - - if (!settings.contains (sensorDelay)) - { - qDebug () << "App::loadSensor () sensor " << sensorName << " does not have delay; setting to 0"; - settings.setValue (sensorDelay, 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 ())); + return; + } + + if (!settings.contains (sensorAction)) + { + qDebug () << "App::loadSensor () sensor " << sensorName << " does not have action; ignoring..."; + return; } + + if (!settings.contains (sensorDelay)) + { + qDebug () << "App::loadSensor () sensor " << sensorName << " does not have delay; setting to 0"; + settings.setValue (sensorDelay, 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 ())); } -- cgit v1.2.3 From a64ffe1153d7b637007c2dde8bd39c559c97a1fe Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Murcia Date: Tue, 19 Feb 2019 16:56:26 +0100 Subject: 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 --- src/app.cpp | 43 +++++++++++++++++++++++++++++------- src/sensor.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++-------------- src/sensor.h | 15 ++++++++----- 3 files changed, 98 insertions(+), 30 deletions(-) (limited to 'src') 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(); }; -- cgit v1.2.3 From bb9187523dcc0f7ba3adfe4634ba2f78897416f4 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Murcia Date: Tue, 19 Feb 2019 17:02:43 +0100 Subject: Keep compatibility with old versions of the ini file to prevent breaking user's workflow Signed-off-by: Alexis Maiquez Murcia --- src/app.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/app.cpp b/src/app.cpp index 1dd94cc..bb7c777 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -167,7 +167,8 @@ App::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h) if (emptyCount == 2) { - qDebug () << "App::loadSensor () sensor " << sensorName << " does not have any action in it, ignoring..."; + // to not make this a breaking change, keep compatibility with old configurations + sensors.append (new Sensor (x, y, w, h, sensorName, "", 0, 0)); return; } -- cgit v1.2.3