1
/****************************************************************************
2
**
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
**
7
** This file is part of the QtCore module of the Qt Toolkit.
8
**
9
** $QT_BEGIN_LICENSE:LGPL$
10
** GNU Lesser General Public License Usage
11
** This file may be used under the terms of the GNU Lesser General Public
12
** License version 2.1 as published by the Free Software Foundation and
13
** appearing in the file LICENSE.LGPL included in the packaging of this
14
** file. Please review the following information to ensure the GNU Lesser
15
** General Public License version 2.1 requirements will be met:
16
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17
**
18
** In addition, as a special exception, Nokia gives you certain additional
19
** rights. These rights are described in the Nokia Qt LGPL Exception
20
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21
**
22
** GNU General Public License Usage
23
** Alternatively, this file may be used under the terms of the GNU General
24
** Public License version 3.0 as published by the Free Software Foundation
25
** and appearing in the file LICENSE.GPL included in the packaging of this
26
** file. Please review the following information to ensure the GNU General
27
** Public License version 3.0 requirements will be met:
28
** http://www.gnu.org/copyleft/gpl.html.
29
**
30
** Other Usage
31
** Alternatively, this file may be used in accordance with the terms and
32
** conditions contained in a signed written agreement between you and Nokia.
33
**
34
**
35
**
36
**
37
**
38
** $QT_END_LICENSE$
39
**
40
****************************************************************************/
41
42
#include "qbasictimer.h"
43
#include "qcoreapplication.h"
44
#include "qabstracteventdispatcher.h"
45
46
QT_BEGIN_NAMESPACE
47
48
/*!
49
    \class QBasicTimer
50
    \brief The QBasicTimer class provides timer events for objects.
51
52
    \ingroup events
53
54
    This is a fast, lightweight, and low-level class used by Qt
55
    internally. We recommend using the higher-level QTimer class
56
    rather than this class if you want to use timers in your
57
    applications. Note that this timer is a repeating timer that
58
    will send subsequent timer events unless the stop() function is called.
59
60
    To use this class, create a QBasicTimer, and call its start()
61
    function with a timeout interval and with a pointer to a QObject
62
    subclass. When the timer times out it will send a timer event to
63
    the QObject subclass. The timer can be stopped at any time using
64
    stop(). isActive() returns true for a timer that is running;
65
    i.e. it has been started, has not reached the timeout time, and
66
    has not been stopped. The timer's ID can be retrieved using
67
    timerId().
68
69
    The \l{widgets/wiggly}{Wiggly} example uses QBasicTimer to repaint
70
    a widget at regular intervals.
71
72
    \sa QTimer, QTimerEvent, QObject::timerEvent(), Timers, {Wiggly Example}
73
*/
74
75
76
/*!
77
    \fn QBasicTimer::QBasicTimer()
78
79
    Contructs a basic timer.
80
81
    \sa start()
82
*/
83
/*!
84
    \fn QBasicTimer::~QBasicTimer()
85
86
    Destroys the basic timer.
87
*/
88
89
/*!
90
    \fn bool QBasicTimer::isActive() const
91
92
    Returns true if the timer is running and has not been stopped; otherwise
93
    returns false.
94
95
    \sa start() stop()
96
*/
97
98
/*!
99
    \fn int QBasicTimer::timerId() const
100
101
    Returns the timer's ID.
102
103
    \sa QTimerEvent::timerId()
104
*/
105
106
/*!
107
    \fn void QBasicTimer::start(int msec, QObject *object)
108
109
    Starts (or restarts) the timer with a \a msec milliseconds
110
    timeout.
111
112
    The given \a object will receive timer events.
113
114
    \sa stop() isActive() QObject::timerEvent()
115
 */
116
void QBasicTimer::start(int msec, QObject *obj)
117
{
118
   stop();
119
   if (obj)
120
       id = obj->startTimer(msec);
121
}
122
123
/*!
124
    Stops the timer.
125
126
    \sa start() isActive()
127
*/
128
void QBasicTimer::stop()
129
{
130
    if (id) {
131
        QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
132
        if (eventDispatcher)
133
            eventDispatcher->unregisterTimer(id);
134
    }
135
    id = 0;
136
}
137
138
QT_END_NAMESPACE