src/corelib/kernel/qbasictimer.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 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 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    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.
       
    58 
       
    59     To use this class, create a QBasicTimer, and call its start()
       
    60     function with a timeout interval and with a pointer to a QObject
       
    61     subclass. When the timer times out it will send a timer event to
       
    62     the QObject subclass. The timer can be stopped at any time using
       
    63     stop(). isActive() returns true for a timer that is running;
       
    64     i.e. it has been started, has not reached the timeout time, and
       
    65     has not been stopped. The timer's ID can be retrieved using
       
    66     timerId().
       
    67 
       
    68     The \l{widgets/wiggly}{Wiggly} example uses QBasicTimer to repaint
       
    69     a widget at regular intervals.
       
    70 
       
    71     \sa QTimer, QTimerEvent, QObject::timerEvent(), Timers, {Wiggly Example}
       
    72 */
       
    73 
       
    74 
       
    75 /*!
       
    76     \fn QBasicTimer::QBasicTimer()
       
    77 
       
    78     Contructs a basic timer.
       
    79 
       
    80     \sa start()
       
    81 */
       
    82 /*!
       
    83     \fn QBasicTimer::~QBasicTimer()
       
    84 
       
    85     Destroys the basic timer.
       
    86 */
       
    87 
       
    88 /*!
       
    89     \fn bool QBasicTimer::isActive() const
       
    90 
       
    91     Returns true if the timer is running, has not yet timed
       
    92     out, and has not been stopped; otherwise returns false.
       
    93 
       
    94     \sa start() stop()
       
    95 */
       
    96 
       
    97 /*!
       
    98     \fn int QBasicTimer::timerId() const
       
    99 
       
   100     Returns the timer's ID.
       
   101 
       
   102     \sa QTimerEvent::timerId()
       
   103 */
       
   104 
       
   105 /*!
       
   106     \fn void QBasicTimer::start(int msec, QObject *object)
       
   107 
       
   108     Starts (or restarts) the timer with a \a msec milliseconds
       
   109     timeout.
       
   110 
       
   111     The given \a object will receive timer events.
       
   112 
       
   113     \sa stop() isActive() QObject::timerEvent()
       
   114  */
       
   115 void QBasicTimer::start(int msec, QObject *obj)
       
   116 {
       
   117    stop();
       
   118    if (obj)
       
   119        id = obj->startTimer(msec);
       
   120 }
       
   121 
       
   122 /*!
       
   123     Stops the timer.
       
   124 
       
   125     \sa start() isActive()
       
   126 */
       
   127 void QBasicTimer::stop()
       
   128 {
       
   129     if (id) {
       
   130         QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
       
   131         if (eventDispatcher)
       
   132             eventDispatcher->unregisterTimer(id);
       
   133     }
       
   134     id = 0;
       
   135 }
       
   136 
       
   137 QT_END_NAMESPACE