diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-08-27 23:59:22 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-08-27 23:59:22 (GMT) |
commit | 41c9c45f766c187287c3107e8fb121610ccbf3b5 (patch) | |
tree | eae3b22365c5dbdb3554b3ee98cd02deaac385b7 /src/declarative/qml | |
parent | 70e650500e6e13be336857dac17a110097da70ef (diff) | |
parent | 1651d5d9109d60f9f6a63e18e31b59b90aeda6f8 (diff) | |
download | Qt-41c9c45f766c187287c3107e8fb121610ccbf3b5.zip Qt-41c9c45f766c187287c3107e8fb121610ccbf3b5.tar.gz Qt-41c9c45f766c187287c3107e8fb121610ccbf3b5.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Conflicts:
src/declarative/qml/qmlengine.cpp
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/qmlcompiler.cpp | 10 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 79 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine_p.h | 5 | ||||
-rw-r--r-- | src/declarative/qml/qmlmetaproperty.cpp | 2 |
4 files changed, 85 insertions, 11 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 764699e..070add7 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -1235,13 +1235,9 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, // default property or to sub-objects (which are always in binding // sub-contexts) COMPILE_CHECK(buildIdProperty(prop, obj)); - if (prop->type == QVariant::String){ - if(!prop->values.at(0)->value.isString()){ - //Need to convert to string to assign to the QString id property - prop->values.at(0)->value = Variant(prop->values.at(0)->value.asString()); - } + if (prop->type == QVariant::String && + prop->values.at(0)->value.isString()) COMPILE_CHECK(buildPropertyAssignment(prop, obj, ctxt)); - } } else if (isAttachedPropertyName(prop->name)) { @@ -1702,7 +1698,7 @@ bool QmlCompiler::buildListProperty(QmlParser::Property *prop, // children: [ Item {}, Item {} ] // } // -// We allow assigning multiple values to single value properties +// We allow assignming multiple values to single value properties bool QmlCompiler::buildPropertyAssignment(QmlParser::Property *prop, QmlParser::Object *obj, const BindingContext &ctxt) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 3f6f9b4..d06376a 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -55,6 +55,7 @@ #include <QNetworkReply> #include <QNetworkRequest> #include <QNetworkAccessManager> +#include <QDesktopServices> #include <QTimer> #include <QList> #include <QPair> @@ -71,6 +72,7 @@ #include <QtCore/qthread.h> #include <QtCore/qcoreapplication.h> #include <QtCore/qdir.h> +#include <QtGui/qcolor.h> #include <QtGui/qvector3d.h> #include <qmlcomponent.h> #include "private/qmlcomponentjs_p.h" @@ -96,6 +98,14 @@ struct StaticQtMetaObject : public QObject { return &static_cast<StaticQtMetaObject*> (0)->staticQtMetaObject; } }; +QScriptValue desktopOpenUrl(QScriptContext *ctxt, QScriptEngine *e) +{ + if(!ctxt->argumentCount()) + return e->newVariant(QVariant(false)); + bool ret = QDesktopServices::openUrl(QUrl(ctxt->argument(0).toString())); + return e->newVariant(QVariant(ret)); +} + QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) : rootContext(0), currentBindContext(0), currentExpression(0), isDebugging(false), contextClass(0), objectClass(0), valueTypeClass(0), @@ -104,9 +114,19 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) { QScriptValue qtObject = scriptEngine.newQMetaObject(StaticQtMetaObject::get()); + QScriptValue desktopObject = scriptEngine.newObject(); + desktopObject.setProperty(QLatin1String("openUrl"),scriptEngine.newFunction(desktopOpenUrl, 1)); + qtObject.setProperty(QLatin1String("DesktopServices"), desktopObject); scriptEngine.globalObject().setProperty(QLatin1String("Qt"), qtObject); qt_add_qmlxmlhttprequest(&scriptEngine); + + qtObject.setProperty(QLatin1String("rgba"), scriptEngine.newFunction(QmlEnginePrivate::rgba, 4)); + qtObject.setProperty(QLatin1String("hsla"), scriptEngine.newFunction(QmlEnginePrivate::hsla, 4)); + qtObject.setProperty(QLatin1String("rect"), scriptEngine.newFunction(QmlEnginePrivate::rect, 4)); + qtObject.setProperty(QLatin1String("point"), scriptEngine.newFunction(QmlEnginePrivate::point, 2)); + qtObject.setProperty(QLatin1String("size"), scriptEngine.newFunction(QmlEnginePrivate::size, 2)); + qtObject.setProperty(QLatin1String("vector3d"), scriptEngine.newFunction(QmlEnginePrivate::vector, 3)); } QmlEnginePrivate::~QmlEnginePrivate() @@ -163,7 +183,7 @@ void QmlEnginePrivate::init() scriptEngine.globalObject().setProperty(QLatin1String("createComponent"), scriptEngine.newFunction(QmlEnginePrivate::createComponent, 1)); scriptEngine.globalObject().setProperty(QLatin1String("vector"), - scriptEngine.newFunction(QmlEnginePrivate::vector, 1)); + scriptEngine.newFunction(QmlEnginePrivate::vector, 3)); if (QCoreApplication::instance()->thread() == q->thread() && QmlEngineDebugServer::isDebuggingEnabled()) { @@ -701,7 +721,7 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi QVector3D as usual. This function takes three numeric components and combines them into a - QMLJS string that can be used with any property that takes a + QVector3D value that can be used with any property that takes a QVector3D argument. The following QML code: \code @@ -732,6 +752,59 @@ QScriptValue QmlEnginePrivate::vector(QScriptContext *ctxt, QScriptEngine *engin return engine->newVariant(qVariantFromValue(QVector3D(x, y, z))); } +QScriptValue QmlEnginePrivate::rgba(QScriptContext *ctxt, QScriptEngine *engine) +{ + int argCount = ctxt->argumentCount(); + if(argCount < 3) + return engine->nullValue(); + qsreal r = ctxt->argument(0).toNumber(); + qsreal g = ctxt->argument(1).toNumber(); + qsreal b = ctxt->argument(2).toNumber(); + qsreal a = (argCount == 4) ? ctxt->argument(3).toNumber() : 1; + return qScriptValueFromValue(engine, qVariantFromValue(QColor::fromRgbF(r, g, b, a))); +} + +QScriptValue QmlEnginePrivate::hsla(QScriptContext *ctxt, QScriptEngine *engine) +{ + int argCount = ctxt->argumentCount(); + if(argCount < 3) + return engine->nullValue(); + qsreal h = ctxt->argument(0).toNumber(); + qsreal s = ctxt->argument(1).toNumber(); + qsreal l = ctxt->argument(2).toNumber(); + qsreal a = (argCount == 4) ? ctxt->argument(3).toNumber() : 1; + return qScriptValueFromValue(engine, qVariantFromValue(QColor::fromHslF(h, s, l, a))); +} + +QScriptValue QmlEnginePrivate::rect(QScriptContext *ctxt, QScriptEngine *engine) +{ + if(ctxt->argumentCount() < 4) + return engine->nullValue(); + qsreal x = ctxt->argument(0).toNumber(); + qsreal y = ctxt->argument(1).toNumber(); + qsreal w = ctxt->argument(2).toNumber(); + qsreal h = ctxt->argument(3).toNumber(); + return qScriptValueFromValue(engine, qVariantFromValue(QRectF(x, y, w, h))); +} + +QScriptValue QmlEnginePrivate::point(QScriptContext *ctxt, QScriptEngine *engine) +{ + if(ctxt->argumentCount() < 2) + return engine->nullValue(); + qsreal x = ctxt->argument(0).toNumber(); + qsreal y = ctxt->argument(1).toNumber(); + return qScriptValueFromValue(engine, qVariantFromValue(QPointF(x, y))); +} + +QScriptValue QmlEnginePrivate::size(QScriptContext *ctxt, QScriptEngine *engine) +{ + if(ctxt->argumentCount() < 2) + return engine->nullValue(); + qsreal w = ctxt->argument(0).toNumber(); + qsreal h = ctxt->argument(1).toNumber(); + return qScriptValueFromValue(engine, qVariantFromValue(QSizeF(w, h))); +} + QmlScriptClass::QmlScriptClass(QmlEngine *bindengine) : QScriptClass(QmlEnginePrivate::getScriptEngine(bindengine)), engine(bindengine) @@ -974,7 +1047,7 @@ QScriptValue QmlObjectToString(QScriptContext *context, QScriptEngine *engine) ret += QString::number((quintptr)obj,16); ret += QLatin1String(")"); }else{ - ret += "null"; + ret += QLatin1String("null"); } return engine->newVariant(ret); } diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 5506b56..aeee355 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -214,6 +214,11 @@ public: static QScriptValue createComponent(QScriptContext*, QScriptEngine*); static QScriptValue createQmlObject(QScriptContext*, QScriptEngine*); static QScriptValue vector(QScriptContext*, QScriptEngine*); + static QScriptValue rgba(QScriptContext*, QScriptEngine*); + static QScriptValue hsla(QScriptContext*, QScriptEngine*); + static QScriptValue point(QScriptContext*, QScriptEngine*); + static QScriptValue size(QScriptContext*, QScriptEngine*); + static QScriptValue rect(QScriptContext*, QScriptEngine*); static QScriptEngine *getScriptEngine(QmlEngine *e) { return &e->d_func()->scriptEngine; } static QmlEngine *getEngine(QScriptEngine *e) { return static_cast<QmlScriptEngine*>(e)->p->q_func(); } diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index cc5e4ee..1e8ce91 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -532,7 +532,7 @@ QmlAbstractBinding *QmlMetaProperty::binding() const QmlAbstractBinding *binding = data->bindings; while (binding) { // ### This wont work for value types - if (binding->propertyIndex() == d->coreIdx) + if (binding->propertyIndex() == d->coreIdx) //### should we check for enabled? return binding; binding = binding->m_nextBinding; } |