summaryrefslogtreecommitdiffstats
path: root/qtinterface/tqtimer.h
blob: f1c1390fd05e2c9a70f92aaae04e93845420ed22 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*

Copyright (C) 2010 Timothy Pearson <kb9vqf@pearsoncomputing.net>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB.  If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.

*/

#ifndef TQTIMER_H
#define TQTIMER_H

#include <tqt.h>

#ifdef USE_QT3

// Reimplement the QTimer class
// For Qt3, no changes are needed

#include <qtimer.h>

#endif // USE_QT3

#ifdef USE_QT4

// Reimplement the QTimer class
// For Qt4, some changes are needed

// Linker tricks required to override a class without changing its name
#define QTimer IQTimer
#include <QtCore/qtimer.h>
#undef QTimer

class QTimer : public IQTimer {
// This is taken straight from the Qt header file, with all Q_OBJECT, slot, and similar keywords stripped out.
// Also, all inline functions must be converted to simple declarations.
// This is the last and most obnoxious part of the linker tricks mentioned above
// Essentially, the compiler needs to know that these Q functions exist so that the above I functions
// are not attempted to link.  Instead, these empty declarations allow the linker to pull in the complete Q function
// from the Qt toolkit in use.  Convoluted, yes, but it should make maintinance MUCH easier as the Qt API changes.
public:
    explicit QTimer(QObject *parent = 0);
    ~QTimer();

    inline bool isActive() const;
    int timerId() const;

    void setInterval(int msec);
    int interval() const;

    inline void setSingleShot(bool singleShot);
    inline bool isSingleShot() const;

    static void singleShot(int msec, QObject *receiver, const char *member);

    void start(int msec);

    void start();
    void stop();

    void timeout();
// End Qt header file copy

// This is where the new member functions should be placed
// Unlike the above copied block, these members must be defined in the associated .cpp file,
// and they should usually do something.  Feel free to include as many Qt files as needed
// in the cpp source file, but DO NOT include them in this header file.
    int myNewFunction(int parameter_one);

// Begin Qt header file copy
protected:
    void timerEvent(QTimerEvent *);

private:
    inline int startTimer(int);
    inline void killTimer(int);
};

//inline void QTimer::setSingleShot(bool asingleShot) { single = asingleShot; }
// End Qt header file copy

#endif // USE_QT4

// #ifdef USE_QT4
//
// // Reimplement the QTimer class
// // For Qt4, a few overrides are required
// // Specifically, these functions were altered:
// // OLD:						NEW:
// //
//
// #include <qtimer.h>
//
// class Q_EXPORT TQTimer : public QTimer
// {
//     Q_OBJECT
// public:
//     TQTimer( QObject *parent=0, const char *name=0 );
//    ~TQTimer();
//
//    // FIXME: Example ONLY
//    virtual void oldFunction ();
// };
//
// #endif // USE_QT4

#endif /* TQTIMER_H */