add more spacing
[personal-kdebase.git] / workspace / plasma / scriptengines / javascript / qtgui / timer.cpp
blob6e3993e5160f034e48e92e12506bda364c024302
1 /*
2 * Copyright 2007 Richard J. Moore <rich@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <QtScript/QScriptValue>
20 #include <QtScript/QScriptEngine>
21 #include <QtScript/QScriptContext>
22 #include <QtScript/QScriptable>
23 #include <QtCore/QTimer>
24 #include "../backportglobal.h"
26 Q_DECLARE_METATYPE(QTimer*)
28 static QScriptValue newTimer(QScriptEngine *eng, QTimer *timer)
30 return eng->newQObject(timer, QScriptEngine::AutoOwnership);
33 static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
35 return newTimer(eng, new QTimer(qscriptvalue_cast<QObject*>(ctx->argument(0))));
38 static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng)
40 DECLARE_SELF(QTimer, toString);
41 return QScriptValue(eng, QString::fromLatin1("QTimer(interval=%0)")
42 .arg(self->interval()));
45 QScriptValue constructTimerClass(QScriptEngine *eng)
47 QScriptValue proto = newTimer(eng, new QTimer());
48 ADD_METHOD(proto, toString);
49 eng->setDefaultPrototype(qMetaTypeId<QTimer*>(), proto);
51 return eng->newFunction(ctor, proto);