Qt 4.8
qdeclarativetimer.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "private/qdeclarativetimer_p.h"
43 
44 #include <QtCore/qcoreapplication.h>
45 #include <QtCore/qpauseanimation.h>
46 #include <qdebug.h>
47 
48 #include <private/qobject_p.h>
49 
51 
52 
53 
55 {
57 public:
59  : interval(1000), running(false), repeating(false), triggeredOnStart(false)
60  , classBegun(false), componentComplete(false), firstTick(true) {}
61  int interval;
63  bool running : 1;
64  bool repeating : 1;
65  bool triggeredOnStart : 1;
66  bool classBegun : 1;
68  bool firstTick : 1;
69 };
70 
114  : QObject(*(new QDeclarativeTimerPrivate), parent)
115 {
117  connect(&d->pause, SIGNAL(currentLoopChanged(int)), this, SLOT(ticked()));
118  connect(&d->pause, SIGNAL(finished()), this, SLOT(finished()));
119  d->pause.setLoopCount(1);
120  d->pause.setDuration(d->interval);
121 }
122 
134 {
136  if (interval != d->interval) {
137  d->interval = interval;
138  update();
140  }
141 }
142 
143 int QDeclarativeTimer::interval() const
144 {
145  Q_D(const QDeclarativeTimer);
146  return d->interval;
147 }
148 
164 {
165  Q_D(const QDeclarativeTimer);
166  return d->running;
167 }
168 
170 {
172  if (d->running != running) {
173  d->running = running;
174  d->firstTick = true;
176  update();
177  }
178 }
179 
195 {
196  Q_D(const QDeclarativeTimer);
197  return d->repeating;
198 }
199 
201 {
203  if (repeating != d->repeating) {
204  d->repeating = repeating;
205  update();
207  }
208 }
209 
231 {
232  Q_D(const QDeclarativeTimer);
233  return d->triggeredOnStart;
234 }
235 
237 {
239  if (d->triggeredOnStart != triggeredOnStart) {
240  d->triggeredOnStart = triggeredOnStart;
241  update();
243  }
244 }
245 
257 {
258  setRunning(true);
259 }
260 
272 {
273  setRunning(false);
274 }
275 
288 {
289  setRunning(false);
290  setRunning(true);
291 }
292 
294 {
296  if (d->classBegun && !d->componentComplete)
297  return;
298  d->pause.stop();
299  if (d->running) {
300  d->pause.setCurrentTime(0);
301  d->pause.setLoopCount(d->repeating ? -1 : 1);
302  d->pause.setDuration(d->interval);
303  d->pause.start();
304  if (d->triggeredOnStart && d->firstTick) {
307  }
308  }
309 }
310 
312 {
314  d->classBegun = true;
315 }
316 
318 {
320  d->componentComplete = true;
321  update();
322 }
323 
333 {
335  if (d->running && (d->pause.currentTime() > 0 || (d->triggeredOnStart && d->firstTick)))
336  emit triggered();
337  d->firstTick = false;
338 }
339 
341 {
343  if (d->repeating || !d->running)
344  return;
345  emit triggered();
346  d->running = false;
347  d->firstTick = false;
349 }
350 
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QDeclarativeParserStatus ** d
void setTriggeredOnStart(bool triggeredOnStart)
#define SLOT(a)
Definition: qobjectdefs.h:226
void classBegin()
Invoked after class creation, but before any properties have been set.
The QPauseAnimation class provides a pause for QSequentialAnimationGroup.
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool triggeredOnStart() const
void setRepeating(bool repeating)
#define emit
Definition: qobjectdefs.h:76
void ticked()
This handler is called when the Timer is triggered.
int interval() const
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QDeclarativeTimer(QObject *parent=0)
void setInterval(int interval)
QObject * parent
Definition: qobject.h:92
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
void triggeredOnStartChanged()
removePostedEvents
Removes all events of the given eventType that were posted using postEvent() for receiver.
void setRunning(bool running)
void componentComplete()
Invoked after the root component that caused this instantiation has completed construction.