diff options
-rw-r--r-- | demos/declarative/flickr/mobile/TitleBar.qml | 7 | ||||
-rw-r--r-- | src/declarative/fx/qfxflickable.cpp | 19 | ||||
-rw-r--r-- | src/declarative/fx/qfxgridview.cpp | 5 | ||||
-rw-r--r-- | src/declarative/fx/qfxlistview.cpp | 9 | ||||
-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 | ||||
-rw-r--r-- | tests/auto/declarative/qmlengine/functions.qml | 6 | ||||
-rw-r--r-- | tests/auto/declarative/qmlengine/tst_qmlengine.cpp | 87 |
10 files changed, 180 insertions, 49 deletions
diff --git a/demos/declarative/flickr/mobile/TitleBar.qml b/demos/declarative/flickr/mobile/TitleBar.qml index 6d655a6..49d670f 100644 --- a/demos/declarative/flickr/mobile/TitleBar.qml +++ b/demos/declarative/flickr/mobile/TitleBar.qml @@ -3,6 +3,8 @@ import Qt 4.6 Item { id: TitleBar + property string untaggedString: "Uploads from everyone" + property string taggedString: "Recent uploads tagged " BorderImage { source: "images/titlebar2.sci"; width: parent.width; height: parent.height + 14; y: -7 } Item { @@ -22,13 +24,14 @@ Item { anchors.leftMargin: 10; anchors.rightMargin: 10 anchors.verticalCenter: parent.verticalCenter elide: "ElideLeft" - text: (RssModel.tags=="" ? "Uploads from everyone" : "Recent Uploads tagged " + RssModel.tags) + text: (RssModel.tags=="" ? untaggedString : taggedString + RssModel.tags) font.bold: true; color: "white"; style: "Raised"; styleColor: "black" } Button { - id: TagButton; x: TitleBar.width - 50; y: 3; width: 45; height: 32; text: "..." + id: TagButton; x: TitleBar.width - 50; width: 45; height: 32; text: "..." onClicked: if (TitleBar.state == "Tags") accept(); else TitleBar.state = "Tags" + anchors.verticalCenter: parent.verticalCenter } Item { diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 428815a..440c1ca 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -607,7 +607,6 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *) { Q_Q(QFxFlickable); - pressed = false; if (lastPosTime.isNull()) return; @@ -871,13 +870,8 @@ void QFxFlickable::setViewportWidth(int w) else d->_flick->setWidth(w); // Make sure that we're entirely in view. - if (d->_moveX.value() > minXExtent() || maxXExtent() > 0) { - d->_tl.clear(); - d->_moveX.setValue(minXExtent()); - } else if (d->_moveX.value() < maxXExtent()) { - d->_tl.clear(); - d->_moveX.setValue(maxXExtent()); - } + if (!d->pressed) + d->fixupX(); emit viewportWidthChanged(); d->updateBeginningEnd(); } @@ -919,13 +913,8 @@ void QFxFlickable::setViewportHeight(int h) else d->_flick->setHeight(h); // Make sure that we're entirely in view. - if (d->_moveY.value() > minYExtent() || maxYExtent() > 0) { - d->_tl.clear(); - d->_moveY.setValue(minYExtent()); - } else if (d->_moveY.value() < maxYExtent()) { - d->_tl.clear(); - d->_moveY.setValue(maxYExtent()); - } + if (!d->pressed) + d->fixupY(); emit viewportHeightChanged(); d->updateBeginningEnd(); } diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index b429895..bf6e863 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -1254,6 +1254,7 @@ void QFxGridView::itemsInserted(int modelIndex, int count) void QFxGridView::itemsRemoved(int modelIndex, int count) { Q_D(QFxGridView); + bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count; int index = d->mapFromModel(modelIndex); if (index == -1) { if (modelIndex + count - 1 < d->visibleIndex) { @@ -1269,7 +1270,7 @@ void QFxGridView::itemsRemoved(int modelIndex, int count) d->currentIndex -= count; if (d->currentItem) d->currentItem->index -= count; - } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) { + } else if (currentRemoved) { // current item has been removed. d->releaseItem(d->currentItem); d->currentItem = 0; @@ -1311,7 +1312,7 @@ void QFxGridView::itemsRemoved(int modelIndex, int count) d->currentIndex -= count; if (d->currentItem) d->currentItem->index -= count; - } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) { + } else if (currentRemoved) { // current item has been removed. d->releaseItem(d->currentItem); d->currentItem = 0; diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 4030a0b..c1e03dd 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -1396,13 +1396,14 @@ void QFxListView::trackedPositionChanged() case Free: if (d->trackedItem->position() < d->position()) { d->setPosition(d->trackedItem->position()); + d->fixupPosition(); } else if (d->trackedItem->endPosition() > d->position() + d->size()) { qreal pos = d->trackedItem->endPosition() - d->size(); if (d->trackedItem->size() > d->size()) pos = d->trackedItem->position(); d->setPosition(pos); + d->fixupPosition(); } - d->fixupPosition(); break; case Snap: if (d->trackedItem->position() < d->startPosition() + d->snapPos) @@ -1521,6 +1522,7 @@ void QFxListView::itemsRemoved(int modelIndex, int count) { Q_D(QFxListView); d->updateUnrequestedIndexes(); + bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count; if (!d->mapRangeFromModel(modelIndex, count)) { if (modelIndex + count - 1 < d->visibleIndex) { // Items removed before our visible items. @@ -1535,7 +1537,7 @@ void QFxListView::itemsRemoved(int modelIndex, int count) d->currentIndex -= count; if (d->currentItem) d->currentItem->index -= count; - } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) { + } else if (currentRemoved) { // current item has been removed. d->releaseItem(d->currentItem); d->currentItem = 0; @@ -1578,8 +1580,9 @@ void QFxListView::itemsRemoved(int modelIndex, int count) d->currentIndex -= count; if (d->currentItem) d->currentItem->index -= count; - } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) { + } else if (currentRemoved) { // current item has been removed. + d->currentItem->attached->setIsCurrentItem(false); d->releaseItem(d->currentItem); d->currentItem = 0; d->currentIndex = -1; 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; } diff --git a/tests/auto/declarative/qmlengine/functions.qml b/tests/auto/declarative/qmlengine/functions.qml new file mode 100644 index 0000000..28e8ed4 --- /dev/null +++ b/tests/auto/declarative/qmlengine/functions.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + rectProperty: Qt.rect(0,0,100,100) + rectFProperty: Qt.rect(0,0.5,100,99.5) +} diff --git a/tests/auto/declarative/qmlengine/tst_qmlengine.cpp b/tests/auto/declarative/qmlengine/tst_qmlengine.cpp index 9a04c61..8c050cb 100644 --- a/tests/auto/declarative/qmlengine/tst_qmlengine.cpp +++ b/tests/auto/declarative/qmlengine/tst_qmlengine.cpp @@ -1,4 +1,6 @@ #include <qtest.h> +#include <QtDeclarative/qml.h> +#include <QtDeclarative/QmlComponent> #include <QtDeclarative/QmlEngine> #include <QtCore/QDebug> @@ -12,30 +14,83 @@ public: tst_qmlengine() {} private slots: - void componentSearchPath(); -}; + void valueTypeFunctions(); +private: + QmlEngine engine; +}; -void tst_qmlengine::componentSearchPath() +class MyTypeObject : public QObject { - QFile file(SRCDIR "/imports.qml"); - QVERIFY(file.open(QIODevice::ReadOnly)); + Q_OBJECT + Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty); + Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty); + Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty); + Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty); + Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged); + Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty); + +public: + MyTypeObject() {} - QmlEngine engine; + QPoint pointPropertyValue; + QPoint pointProperty() const { + return pointPropertyValue; + } + void setPointProperty(const QPoint &v) { + pointPropertyValue = v; + } - QList<QUrl> searchPath = engine.componentSearchPath(file.readAll(), - QUrl::fromLocalFile(file.fileName())); + QPointF pointFPropertyValue; + QPointF pointFProperty() const { + return pointFPropertyValue; + } + void setPointFProperty(const QPointF &v) { + pointFPropertyValue = v; + } - QList<QUrl> expected; - expected << QUrl::fromLocalFile(SRCDIR); - expected << QUrl::fromLocalFile(file.fileName()).resolved(QUrl("import1")); - expected << QUrl::fromLocalFile(file.fileName()).resolved(QUrl("import2")); + QSize sizePropertyValue; + QSize sizeProperty() const { + return sizePropertyValue; + } + void setSizeProperty(const QSize &v) { + sizePropertyValue = v; + } - QCOMPARE(searchPath.size(), expected.size()); - for (int i = 0; i < expected.size(); ++i) { - QCOMPARE(searchPath.at(i).toString(QUrl::StripTrailingSlash), - expected.at(i).toString(QUrl::StripTrailingSlash)); + QSizeF sizeFPropertyValue; + QSizeF sizeFProperty() const { + return sizeFPropertyValue; } + void setSizeFProperty(const QSizeF &v) { + sizeFPropertyValue = v; + } + + QRect rectPropertyValue; + QRect rectProperty() const { + return rectPropertyValue; + } + void setRectProperty(const QRect &v) { + rectPropertyValue = v; + } + + QRectF rectFPropertyValue; + QRectF rectFProperty() const { + return rectFPropertyValue; + } + void setRectFProperty(const QRectF &v) { + rectFPropertyValue = v; + } + +}; +QML_DECLARE_TYPE(MyTypeObject); +QML_DEFINE_TYPE(Test, 1, 0, 0, MyTypeObject, MyTypeObject); + +void tst_qmlengine::valueTypeFunctions() +{ + QmlComponent component(&engine, SRCDIR "/functions.qml"); + MyTypeObject *obj = qobject_cast<MyTypeObject*>(component.create()); + QCOMPARE(obj->rectProperty(), QRect(0,0,100,100)); + QCOMPARE(obj->rectFProperty(), QRectF(0,0.5,100,99.5)); } QTEST_MAIN(tst_qmlengine) |