-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQtTimer.h
43 lines (34 loc) · 829 Bytes
/
QtTimer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef QTTIMER_H
#define QTTIMER_H
#include <QObject>
#include <QTimerEvent>
extern "C" {
#include "putty.h"
}
#include "QtStuff.h"
class QtTimer : public QObject {
Q_OBJECT
int timerId;
long nextTick;
public:
QtTimer() { timerId = -1; }
void startTimerForTick(long nextTick) {
long ticks = nextTick - GETTICKCOUNT();
if (ticks <= 0) ticks = 1; /* just in case */
if (timerId != -1) this->killTimer(timerId);
timerId = this->startTimer(ticks);
this->nextTick = nextTick;
}
protected:
void timerEvent(QTimerEvent *event) {
long next;
killTimer(timerId);
// only one timer is active at any point of time
assert(event->timerId() == timerId);
timerId = -1;
if (run_timers(this->nextTick, &next)) {
startTimerForTick(next);
}
}
};
#endif // QTTIMER_H