add loadUi from the js engine
svn path=/trunk/KDE/kdebase/runtime/; revision=1188406
This commit is contained in:
parent
bc13065f9a
commit
58adcad0a2
@ -22,10 +22,13 @@
|
||||
#include <QDeclarativeContext>
|
||||
#include <QDeclarativeEngine>
|
||||
#include <QDeclarativeExpression>
|
||||
#include <QFile>
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QScriptEngine>
|
||||
#include <QScriptValueIterator>
|
||||
#include <QTimer>
|
||||
#include <QUiLoader>
|
||||
#include <QWidget>
|
||||
|
||||
#include <KConfigGroup>
|
||||
#include <KDebug>
|
||||
@ -152,6 +155,25 @@ void DeclarativeAppletScript::configChanged()
|
||||
m_env->callEventListeners("configchanged");
|
||||
}
|
||||
|
||||
QScriptValue DeclarativeAppletScript::loadui(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() != 1) {
|
||||
return context->throwError(i18n("loadui() takes one argument"));
|
||||
}
|
||||
|
||||
QString filename = context->argument(0).toString();
|
||||
QFile f(filename);
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
return context->throwError(i18n("Unable to open '%1'",filename));
|
||||
}
|
||||
|
||||
QUiLoader loader;
|
||||
QWidget *w = loader.load(&f);
|
||||
f.close();
|
||||
|
||||
return engine->newQObject(w, QScriptEngine::AutoOwnership);
|
||||
}
|
||||
|
||||
QScriptValue DeclarativeAppletScript::newPlasmaSvg(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() == 0) {
|
||||
@ -339,6 +361,10 @@ void DeclarativeAppletScript::setupObjects()
|
||||
}
|
||||
global.setProperty("startupArguments", args);
|
||||
|
||||
// Add a global loadui method for ui files
|
||||
QScriptValue fun = m_engine->newFunction(DeclarativeAppletScript::loadui);
|
||||
global.setProperty("loadui", fun);
|
||||
|
||||
bindI18N(m_engine);
|
||||
global.setProperty("dataEngine", m_engine->newFunction(DeclarativeAppletScript::dataEngine));
|
||||
global.setProperty("service", m_engine->newFunction(DeclarativeAppletScript::service));
|
||||
|
@ -61,6 +61,7 @@ public:
|
||||
|
||||
QScriptValue variantToScriptValue(QVariant var);
|
||||
|
||||
static QScriptValue loadui(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue newPlasmaSvg(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue newPlasmaFrameSvg(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue newPlasmaExtenderItem(QScriptContext *context, QScriptEngine *engine);
|
||||
|
Loading…
Reference in New Issue
Block a user