diff options
| Commit | c5403e9c5fb08319e984d939b975915dddf59791 (patch) | |
|---|---|---|
| Author | 2019-02-19 16:06:21 +0100 | |
| Committer | 2019-02-19 16:06:21 +0100 | |
| Files | 03157462eb5ac0f3ce74e340abd20b74bf88ebfe /src/sensor.cpp | |
| lead-c5403e9c5fb08319e984d939b975915dddf59791.tar lead-c5403e9c5fb08319e984d939b975915dddf59791.tar.gz lead-c5403e9c5fb08319e984d939b975915dddf59791.zip | ||
| Parent | 9ec7c51b9c82d6898e35be764c10fd852baefe57 (diff) | |
| Parent | a1ddbe5b94b21877c1a082256857d2e6feb692fe (diff) | |
Merge pull request #1 from MageJohn/master
Merge from MageJohn
1 files changed, 32 insertions, 6 deletions
| -rw-r--r-- | src/sensor.cpp | 38 |
diff --git a/src/sensor.cpp b/src/sensor.cpp index d84f0a2..49fd149 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -34,12 +34,18 @@ SOFTWARE. namespace Lead { -Sensor::Sensor(int x, int y, int w, int h, QString action): - QWidget() +Sensor::Sensor(int x, int y, int w, int h, QString action, int interval): + QWidget(), + action(action), + interval(interval) { - qDebug() << "lead::Sensor() " << x << "," << y << "," << w << "," << h << " : " << action; + qDebug() << "lead::Sensor() " << x << "," << y << "," << w << "," << h << " : action=" << action << " : interval=" << interval; - this->action = action; + this->timer = new QTimer(this); + this->timer->setSingleShot(true); + this->timer->setInterval(interval); + + connect(this->timer, SIGNAL(timeout()), this, SLOT(activate())); //setStyleSheet("background-color:red;"); setGeometry(x, y, w, h); @@ -51,13 +57,33 @@ Sensor::Sensor(int x, int y, int w, int h, QString action): Sensor::~Sensor() -{} +{ + delete this->timer; +} void Sensor::enterEvent(QEvent * event) { - qDebug() << "lead::Sensor::enterEvent() " << this->x() << ":" << this->y() << " action: " << this->action; + qDebug() << "lead::Sensor::enterEvent() " << this->x() << ":" << this->y() << " interval: " << this->interval; + + this->timer->start(); +} + + +void +Sensor::leaveEvent(QEvent * event) +{ + qDebug() << "lead::Sensor::leaveEvent() " << this->x() << ":" << this->y() << " interval: " << this->interval; + + this->timer->stop(); +} + + +void +Sensor::activate() +{ + qDebug() << "lead::Sensor::activate() " << this->x() << ":" << this->y() << " action: " << this->action; QProcess::startDetached(action); } |
