summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-06-23 06:05:54 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-06-23 06:05:54 (GMT)
commitb418419f23cec0880b6b351d304b1a755f82ab73 (patch)
tree22f467c2eee0a51d3ec14e20f77e240b944ed55d
parent19e9e13420de8bb1996c426ef7af14efdbcbbd6b (diff)
downloadQt-b418419f23cec0880b6b351d304b1a755f82ab73.zip
Qt-b418419f23cec0880b6b351d304b1a755f82ab73.tar.gz
Qt-b418419f23cec0880b6b351d304b1a755f82ab73.tar.bz2
A simple timer element.
-rw-r--r--src/declarative/extra/extra.pri6
-rw-r--r--src/declarative/extra/qmltimer.cpp97
-rw-r--r--src/declarative/extra/qmltimer.h80
3 files changed, 181 insertions, 2 deletions
diff --git a/src/declarative/extra/extra.pri b/src/declarative/extra/extra.pri
index 83978f1..2590fbc 100644
--- a/src/declarative/extra/extra.pri
+++ b/src/declarative/extra/extra.pri
@@ -1,12 +1,14 @@
SOURCES += \
extra/qnumberformat.cpp \
extra/qmlnumberformatter.cpp \
- extra/qfxintegermodel.cpp
+ extra/qfxintegermodel.cpp \
+ extra/qmltimer.cpp
HEADERS += \
extra/qnumberformat.h \
extra/qmlnumberformatter.h \
- extra/qfxintegermodel.h
+ extra/qfxintegermodel.h \
+ extra/qmltimer.h
contains(QT_CONFIG, xmlpatterns) {
QT+=xmlpatterns
diff --git a/src/declarative/extra/qmltimer.cpp b/src/declarative/extra/qmltimer.cpp
new file mode 100644
index 0000000..1e1a6de
--- /dev/null
+++ b/src/declarative/extra/qmltimer.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "QtCore/qpauseanimation.h"
+#include "private/qobject_p.h"
+#include "qmltimer.h"
+#include "qdebug.h"
+
+QT_BEGIN_NAMESPACE
+
+QML_DEFINE_TYPE(QmlTimer,Timer)
+
+class QmlTimerPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QmlTimer)
+public:
+ QmlTimerPrivate() : interval(1000) {}
+ int interval;
+ QPauseAnimation pause;
+};
+
+QmlTimer::QmlTimer(QObject *parent)
+ : QObject(*(new QmlTimerPrivate), parent)
+{
+ Q_D(QmlTimer);
+ connect(&d->pause, SIGNAL(currentLoopChanged(int)), this, SLOT(ticked()));
+ d->pause.setLoopCount(-1);
+ d->pause.setDuration(d->interval);
+}
+
+void QmlTimer::setInterval(int interval)
+{
+ Q_D(QmlTimer);
+ if (interval != d->interval) {
+ d->interval = interval;
+ d->pause.setDuration(d->interval);
+ d->pause.start();
+ }
+}
+
+int QmlTimer::interval() const
+{
+ Q_D(const QmlTimer);
+ return d->interval;
+}
+
+void QmlTimer::componentComplete()
+{
+ Q_D(QmlTimer);
+ if (d->pause.state() != QAbstractAnimation::Running)
+ d->pause.start();
+}
+
+void QmlTimer::ticked()
+{
+ emit timeout();
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/extra/qmltimer.h b/src/declarative/extra/qmltimer.h
new file mode 100644
index 0000000..75603c6
--- /dev/null
+++ b/src/declarative/extra/qmltimer.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMLTIMER_H
+#define QMLTIMER_H
+
+#include <QtDeclarative/qfxglobal.h>
+#include <QtCore/qobject.h>
+#include <QtDeclarative/qml.h>
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class QmlTimerPrivate;
+class Q_DECLARATIVE_EXPORT QmlTimer : public QObject, public QmlParserStatus
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QmlTimer)
+ Q_PROPERTY(int interval READ interval WRITE setInterval)
+
+public:
+ QmlTimer(QObject *parent=0);
+
+ void setInterval(int interval);
+ int interval() const;
+
+protected:
+ void componentComplete();
+
+Q_SIGNALS:
+ void timeout();
+
+private Q_SLOTS:
+ void ticked();
+};
+QML_DECLARE_TYPE(QmlTimer)
+
+QT_END_NAMESPACE
+QT_END_HEADER
+#endif