widgets()

svn path=/trunk/KDE/kdebase/workspace/; revision=1119843
This commit is contained in:
Aaron J. Seigo 2010-04-27 20:07:08 +00:00 committed by Marco Martin
parent 7d27adbe34
commit fa83ab3f21
3 changed files with 24 additions and 0 deletions

View File

@ -208,6 +208,28 @@ QScriptValue Containment::addWidget(QScriptContext *context, QScriptEngine *engi
return engine->undefinedValue();
}
QScriptValue Containment::widgets(QScriptContext *context, QScriptEngine *engine)
{
Q_UNUSED(context)
Containment *c = qobject_cast<Containment*>(context->thisObject().toQObject());
if (!c || !c->d->containment) {
return engine->undefinedValue();
}
QScriptValue widgets = engine->newArray();
ScriptEngine *env = ScriptEngine::envFor(engine);
int count = 0;
foreach (Plasma::Applet *widget, c->d->containment.data()->applets()) {
widgets.setProperty(count, env->wrap(widget));
++count;
}
widgets.setProperty("length", count);
return widgets;
}
uint Containment::id() const
{
if (!d->containment) {

View File

@ -82,6 +82,7 @@ public:
static QScriptValue widgetById(QScriptContext *context, QScriptEngine *engine);
static QScriptValue addWidget(QScriptContext *context, QScriptEngine *engine);
static QScriptValue widgets(QScriptContext *context, QScriptEngine *engine);
public Q_SLOTS:
void remove();

View File

@ -153,6 +153,7 @@ QScriptValue ScriptEngine::wrap(Containment *c)
QScriptEngine::ExcludeSuperClassMethods);
v.setProperty("widgetById", newFunction(Containment::widgetById));
v.setProperty("addWidget", newFunction(Containment::addWidget));
v.setProperty("widgets", newFunction(Containment::widgets));
return v;
}