diff options
| author | MageJohn <magejohnyjtp@gmail.com> | 2019-02-18 23:34:31 +0000 |
|---|---|---|
| committer | MageJohn <magejohnyjtp@gmail.com> | 2019-02-18 23:34:31 +0000 |
| commit | a79a11d22dcb1bb0cbe47874d7f8ff5d58f2271a (patch) | |
| tree | 37d3347671d5080a75c3c65c4be8a6b0b7e7d2ed /src/sensor.cpp | |
| parent | fe8218f49006190ee779a80173b5cf54eed1ca92 (diff) | |
| download | lead-a79a11d22dcb1bb0cbe47874d7f8ff5d58f2271a.tar lead-a79a11d22dcb1bb0cbe47874d7f8ff5d58f2271a.tar.gz lead-a79a11d22dcb1bb0cbe47874d7f8ff5d58f2271a.zip | |
Implement basic delay support
The ini file now has two entries for each corner, one for the action to
be performed and one for the interval after which it will be performed
if the mouse doesn't leave the hot corner/edge. This is a little
inelegant, and I'd like to make the ini file nicer at some point.
Diffstat (limited to 'src/sensor.cpp')
| -rw-r--r-- | src/sensor.cpp | 38 |
1 files changed, 32 insertions, 6 deletions
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); } |
