try a bit harder to find a decent parent

svn path=/trunk/KDE/kdebase/runtime/; revision=1038831
This commit is contained in:
Aaron J. Seigo 2009-10-22 02:17:34 +00:00
parent d3abf0b709
commit c37cfda132

View File

@ -45,7 +45,8 @@ DECLARE_NUMBER_GET_SET_METHODS(QGraphicsLinearLayout, spacing, setSpacing)
QGraphicsLayoutItem *layoutItem(QScriptContext *ctx, int index = 0) QGraphicsLayoutItem *layoutItem(QScriptContext *ctx, int index = 0)
{ {
QGraphicsLayoutItem *item = qscriptvalue_cast<QGraphicsWidget*>(ctx->argument(index)); QObject *object = ctx->argument(index).toQObject();
QGraphicsLayoutItem *item = qobject_cast<QGraphicsWidget*>(object);
if (!item) { if (!item) {
item = qscriptvalue_cast<QGraphicsLinearLayout*>(ctx->argument(index)); item = qscriptvalue_cast<QGraphicsLinearLayout*>(ctx->argument(index));
@ -55,9 +56,13 @@ QGraphicsLayoutItem *layoutItem(QScriptContext *ctx, int index = 0)
item = qscriptvalue_cast<QGraphicsGridLayout*>(ctx->argument(index)); item = qscriptvalue_cast<QGraphicsGridLayout*>(ctx->argument(index));
} }
QObject *appletObject = ctx->argument(index).toQObject(); if (!item) {
if (appletObject) { AppletInterface *interface = qobject_cast<AppletInterface*>(object);
AppletInterface *interface = qobject_cast<AppletInterface*>(appletObject);
if (!interface) {
interface = qobject_cast<AppletInterface*>(ctx->engine()->globalObject().property("plasmoid").toQObject());
}
if (interface) { if (interface) {
item = interface->applet(); item = interface->applet();
} }
@ -68,10 +73,6 @@ QGraphicsLayoutItem *layoutItem(QScriptContext *ctx, int index = 0)
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
{ {
if (ctx->argumentCount() == 0) {
return ctx->throwError(i18n("LinearLayout requires a parent"));
}
QGraphicsLayoutItem *parent = layoutItem(ctx); QGraphicsLayoutItem *parent = layoutItem(ctx);
if (!parent) { if (!parent) {