From fc05ac9f3b35a7ff6afcb56852e2266aab4b18c4 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Wed, 18 Nov 2009 21:33:00 +0000 Subject: [PATCH] make timers useful svn path=/trunk/KDE/kdebase/runtime/; revision=1051107 --- scriptengines/javascript/qtgui/timer.cpp | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/scriptengines/javascript/qtgui/timer.cpp b/scriptengines/javascript/qtgui/timer.cpp index 6e3993e51..95fad2334 100644 --- a/scriptengines/javascript/qtgui/timer.cpp +++ b/scriptengines/javascript/qtgui/timer.cpp @@ -42,11 +42,40 @@ static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng) .arg(self->interval())); } +static QScriptValue singleShot(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QTimer, start); + if (ctx->argumentCount()) { + self->setSingleShot(ctx->argument(0).toBool()); + } + return QScriptValue(eng, self->isSingleShot()); +} + +static QScriptValue interval(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QTimer, interval); + if (ctx->argumentCount()) { + self->setInterval(ctx->argument(0).toInt32()); + } + return QScriptValue(eng, self->interval()); +} + +static QScriptValue isActive(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QTimer, isActive); + return QScriptValue(eng, self->isActive()); +} + QScriptValue constructTimerClass(QScriptEngine *eng) { QScriptValue proto = newTimer(eng, new QTimer()); ADD_METHOD(proto, toString); eng->setDefaultPrototype(qMetaTypeId(), proto); + QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; + QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; + proto.setProperty("singleShot", eng->newFunction(singleShot), getter | setter); + proto.setProperty("interval", eng->newFunction(interval), getter | setter); + proto.setProperty("isActive", eng->newFunction(isActive), getter); return eng->newFunction(ctor, proto); }