diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2009-09-09 05:48:28 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2009-09-09 05:48:28 (GMT) |
commit | a5ed015bc369483206382689b77a4af0aaf0c547 (patch) | |
tree | 53abb53b912b60fc3efb826240fbf668a4a2b8c1 | |
parent | 543b7355a03a7010ec767dba3f538b96aacc4e89 (diff) | |
parent | ae7a3485c0e6748361789491af33ee7b7fe093bc (diff) | |
download | Qt-a5ed015bc369483206382689b77a4af0aaf0c547.zip Qt-a5ed015bc369483206382689b77a4af0aaf0c547.tar.gz Qt-a5ed015bc369483206382689b77a4af0aaf0c547.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
26 files changed, 803 insertions, 334 deletions
diff --git a/demos/declarative/minehunt/minehunt.qml b/demos/declarative/minehunt/minehunt.qml index fa169aa..72431af 100644 --- a/demos/declarative/minehunt/minehunt.qml +++ b/demos/declarative/minehunt/minehunt.qml @@ -135,8 +135,8 @@ Item { x: 1 y: 1 Component { - ComponentInstance { - component: tile + Loader { + sourceComponent: tile x: (index - (Math.floor(index/9) * 9)) * 41 y: Math.floor(index/9) * 41 } diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index bfaf4ab..ca17fda 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -37,6 +37,7 @@ The following table lists the QML elements provided by the Qt Declarative module \o \l ScriptAction \o \l Transition \o \l Follow +\o \l EaseFollow \o \l Behavior \endlist @@ -100,7 +101,6 @@ The following table lists the QML elements provided by the Qt Declarative module \o \l Loader \o \l Repeater \o \l SystemPalette -\o \l ComponentInstance \o \l GraphicsObjectContainer \endlist diff --git a/doc/src/tutorials/declarative.qdoc b/doc/src/tutorials/declarative.qdoc index 7780988..48beabd 100644 --- a/doc/src/tutorials/declarative.qdoc +++ b/doc/src/tutorials/declarative.qdoc @@ -392,7 +392,7 @@ the contact field. There are also two other ways to reuse components in QML. A component - can be reused from within the same QML file using Component and ComponentInstance + can be reused from within the same QML file using Component and Loader elements. The next code snippet produces three red rounded rectangles within a large blue rectangle. diff --git a/examples/declarative/tutorials/contacts/2_Reuse/1b/BlueRect.qml b/examples/declarative/tutorials/contacts/2_Reuse/1b/BlueRect.qml index ec115fe..7bcdf50 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/1b/BlueRect.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/1b/BlueRect.qml @@ -16,18 +16,18 @@ Rectangle { } } ] - ComponentInstance { - component: redRectangle + Loader { + sourceComponent: redRectangle anchors.right: parent.right anchors.top: parent.top } - ComponentInstance { - component: redRectangle + Loader { + sourceComponent: redRectangle anchors.left: parent.left anchors.top: parent.top } - ComponentInstance { - component: redRectangle + Loader { + sourceComponent: redRectangle anchors.left: parent.left anchors.bottom: parent.bottom } diff --git a/examples/declarative/webview/newwindows.qml b/examples/declarative/webview/newwindows.qml index 9ff902e2..57cbf4e 100644 --- a/examples/declarative/webview/newwindows.qml +++ b/examples/declarative/webview/newwindows.qml @@ -24,5 +24,5 @@ Row { } ] width: 500 - ComponentInstance { component: WebViewPage } + Loader { sourceComponent: WebViewPage } } diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index db1c73a..87873f2 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -69,6 +69,8 @@ MouseRegion: add "pressedButtons" property Timer: add start() and stop() slots WebView: add newWindowComponent and newWindowParent properties Loader: add status() and progress() properties +Loader: add sourceComponent property +Loader: add resizeMode property Deletions: Column/VerticalPositioner: lost "margins" property @@ -76,6 +78,7 @@ Row/HorizontalPositioner: lost "margins" property Grid/Positioner/Layout: lost "margins" property WebView: lost "interactive" property (always true now) Flickable: removed "dragMode" property +ComponentInstance: removed. Replaced by Loader.sourceComponent Other Changes: Drag: axis becomes an enum with values "XAxis", "YAxis", "XandYAxis" diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri index 80a6fdd..cfe78e1 100644 --- a/src/declarative/fx/fx.pri +++ b/src/declarative/fx/fx.pri @@ -1,8 +1,6 @@ HEADERS += \ fx/qfxanchors.h \ fx/qfxanchors_p.h \ - fx/qfxcomponentinstance.h \ - fx/qfxcomponentinstance_p.h \ fx/qfxevents_p.h \ fx/qfxflickable.h \ fx/qfxflickable_p.h \ @@ -49,7 +47,6 @@ HEADERS += \ SOURCES += \ fx/qfxanchors.cpp \ - fx/qfxcomponentinstance.cpp \ fx/qfxevents.cpp \ fx/qfxflickable.cpp \ fx/qfxflipable.cpp \ diff --git a/src/declarative/fx/qfxcomponentinstance.cpp b/src/declarative/fx/qfxcomponentinstance.cpp deleted file mode 100644 index 7a712aa..0000000 --- a/src/declarative/fx/qfxcomponentinstance.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfxcomponentinstance.h" -#include "qfxcomponentinstance_p.h" -#include <private/qfxperf_p.h> -#include <QtDeclarative/qmlinfo.h> - - -QT_BEGIN_NAMESPACE -QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,ComponentInstance,QFxComponentInstance) - -/*! - \internal - \class QFxComponentInstance ComponentInstance - - \brief The QFxComponentInstance class provides a way to instantiate an item from a component. - */ - -/*! - \qmlclass ComponentInstance QFxComponentInstance - \brief The ComponentInstance item allows you to instantiate a \l{Component}. - - \qml - Item { - Component { - id: RedSquare - Rectangle { color: "red"; width: 10; height: 10 } - } - - ComponentInstance { component: RedSquare } - } - \endqml -*/ -QFxComponentInstance::QFxComponentInstance(QFxItem *parent) - : QFxItem(*(new QFxComponentInstancePrivate), parent) -{ -} - -QFxComponentInstance::QFxComponentInstance(QFxComponentInstancePrivate &dd, QFxItem *parent) - : QFxItem(dd, parent) -{ -} - -/*! - \qmlproperty Component QFxComponentInstance::component - - This property holds the component to instantiate. -*/ -QmlComponent *QFxComponentInstance::component() const -{ - Q_D(const QFxComponentInstance); - return d->component; -} - -void QFxComponentInstance::setComponent(QmlComponent *c) -{ - Q_D(QFxComponentInstance); - if (d->component) { - qmlInfo(this) << "component is a write-once property."; - return; - } - d->component = c; - create(); -} - -void QFxComponentInstance::create() -{ - Q_D(QFxComponentInstance); - if (d->component) { - QObject *obj= d->component->create(qmlContext(this)); - if (obj) { - QFxItem *objitem = qobject_cast<QFxItem *>(obj); - if (objitem) { - d->instance = objitem; - objitem->setParentItem(this); - objitem->setFocus(true); - connect(objitem, SIGNAL(widthChanged()), this, SLOT(updateSize())); - connect(objitem, SIGNAL(heightChanged()), this, SLOT(updateSize())); - updateSize(); - emit instanceChanged(); - } else { - delete obj; - } - } - } -} - -void QFxComponentInstance::updateSize() -{ - QFxItem *i = instance(); - if (i) { - if (!widthValid()) - setImplicitWidth(i->width()); - if (!heightValid()) - setImplicitHeight(i->height()); - } -} - -/*! - \qmlproperty Item QFxComponentInstance::instance - - This property holds the instantiated component. -*/ -QFxItem *QFxComponentInstance::instance() const -{ - Q_D(const QFxComponentInstance); - return d->instance; -} - -QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxcomponentinstance_p.h b/src/declarative/fx/qfxcomponentinstance_p.h deleted file mode 100644 index defeb74..0000000 --- a/src/declarative/fx/qfxcomponentinstance_p.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFXCOMPONENTINSTANCE_P_H -#define QFXCOMPONENTINSTANCE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qfxitem_p.h" - - -QT_BEGIN_NAMESPACE -class QFxComponentInstancePrivate : public QFxItemPrivate -{ - Q_DECLARE_PUBLIC(QFxComponentInstance) - -public: - QFxComponentInstancePrivate() - : component(0), instance(0) - { - } - - QmlComponent *component; - QFxItem *instance; -}; - -QT_END_NAMESPACE - -#endif // QFXCOMPONENTINSTANCE_P_H diff --git a/src/declarative/fx/qfxloader.cpp b/src/declarative/fx/qfxloader.cpp index 869a5b0..e75ce6d 100644 --- a/src/declarative/fx/qfxloader.cpp +++ b/src/declarative/fx/qfxloader.cpp @@ -45,7 +45,7 @@ QT_BEGIN_NAMESPACE QFxLoaderPrivate::QFxLoaderPrivate() -: item(0), qmlcomp(0) +: item(0), component(0), ownComponent(false), resizeMode(QFxLoader::SizeLoaderToItem) { } @@ -59,9 +59,22 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Loader,QFxLoader) \qmlclass Loader \inherits Item - \brief The Loader item allows you to dynamically load an Item-based - subtree from a QML URL. - */ + \brief The Loader item allows dynamically loading an Item-based + subtree from a QML URL or Component. + + Loader instantiates an item from a component. The component to + instantiate may be specified directly by the \c sourceComponent + property, or loaded from a URL via the \c source property. + + It is also an effective means of delaying the creation of a component + until it is required: + \code + Loader { id: PageLoader } + Rectangle { + MouseRegion { anchors.fill: parent; onClicked: PageLoader.source = "Page1.qml" } + } + \endcode +*/ /*! \internal @@ -86,10 +99,10 @@ QFxLoader::~QFxLoader() /*! \qmlproperty url Loader::source - This property holds the dynamic URL of the QML for the item. + This property holds the URL of the QML component to + instantiate. - This property is used for dynamically loading QML into the - item. + \sa status, progress */ QUrl QFxLoader::source() const { @@ -103,44 +116,98 @@ void QFxLoader::setSource(const QUrl &url) if (d->source == url) return; - if (!d->source.isEmpty()) { - QHash<QString, QFxItem *>::Iterator iter = d->cachedChildren.find(d->source.toString()); - if (iter != d->cachedChildren.end()) - (*iter)->setOpacity(0.); + if (d->ownComponent) { + delete d->component; + d->component = 0; } - - d->source = url; d->item = 0; - emit itemChanged(); + delete d->item; + d->source = url; if (d->source.isEmpty()) { emit sourceChanged(); emit statusChanged(); emit progressChanged(); + emit itemChanged(); + return; + } + + d->component = new QmlComponent(qmlEngine(this), d->source, this); + d->ownComponent = true; + if (!d->component->isLoading()) { + d->_q_sourceLoaded(); + } else { + connect(d->component, SIGNAL(statusChanged(QmlComponent::Status)), + this, SLOT(_q_sourceLoaded())); + connect(d->component, SIGNAL(progressChanged(qreal)), + this, SIGNAL(progressChanged())); + emit statusChanged(); + emit progressChanged(); + emit sourceChanged(); + emit itemChanged(); + } +} + +/*! + \qmlproperty Component Loader::sourceComponent + The sourceComponent property holds the \l{Component} to instantiate. + + \qml + Item { + Component { + id: RedSquare + Rectangle { color: "red"; width: 10; height: 10 } + } + + Loader { sourceComponent: RedSquare } + Loader { sourceComponent: RedSquare; x: 10 } + } + \endqml + + \sa source +*/ + +QmlComponent *QFxLoader::sourceComponent() const +{ + Q_D(const QFxLoader); + return d->component; +} + +void QFxLoader::setSourceComponent(QmlComponent *comp) +{ + Q_D(QFxLoader); + if (comp == d->component) return; + + d->source = QUrl(); + if (d->ownComponent) { + delete d->component; + d->component = 0; } + delete d->item; + d->item = 0; - QHash<QString, QFxItem *>::Iterator iter = d->cachedChildren.find(d->source.toString()); - if (iter != d->cachedChildren.end()) { - (*iter)->setOpacity(1.); - d->item = (*iter); + d->component = comp; + d->ownComponent = false; + if (!d->component) { emit sourceChanged(); emit statusChanged(); emit progressChanged(); emit itemChanged(); + return; + } + + if (!d->component->isLoading()) { + d->_q_sourceLoaded(); } else { - d->qmlcomp = - new QmlComponent(qmlEngine(this), d->source, this); - if (!d->qmlcomp->isLoading()) { - d->_q_sourceLoaded(); - } else { - connect(d->qmlcomp, SIGNAL(statusChanged(QmlComponent::Status)), - this, SLOT(_q_sourceLoaded())); - connect(d->qmlcomp, SIGNAL(progressChanged(qreal)), - this, SIGNAL(progressChanged())); - emit statusChanged(); - emit progressChanged(); - } + connect(d->component, SIGNAL(statusChanged(QmlComponent::Status)), + this, SLOT(_q_sourceLoaded())); + connect(d->component, SIGNAL(progressChanged(qreal)), + this, SIGNAL(progressChanged())); + emit progressChanged(); + emit sourceChanged(); + emit statusChanged(); + emit itemChanged(); } } @@ -148,33 +215,39 @@ void QFxLoaderPrivate::_q_sourceLoaded() { Q_Q(QFxLoader); - if (qmlcomp) { + if (component) { QmlContext *ctxt = new QmlContext(qmlContext(q)); ctxt->addDefaultObject(q); - if (!qmlcomp->errors().isEmpty()) { - qWarning() << qmlcomp->errors(); - delete qmlcomp; - qmlcomp = 0; + if (!component->errors().isEmpty()) { + qWarning() << component->errors(); emit q->sourceChanged(); emit q->statusChanged(); emit q->progressChanged(); return; } - QObject *obj = qmlcomp->create(ctxt); - if (!qmlcomp->errors().isEmpty()) - qWarning() << qmlcomp->errors(); - QFxItem *qmlChild = qobject_cast<QFxItem *>(obj); - if (qmlChild) { - qmlChild->setParentItem(q); - cachedChildren.insert(source.toString(), qmlChild); - item = qmlChild; + + QObject *obj = component->create(ctxt); + if (obj) { + item = qobject_cast<QFxItem *>(obj); + if (item) { + item->setParentItem(q); +// item->setFocus(true); + QFxItem *resizeItem = 0; + if (resizeMode == QFxLoader::SizeLoaderToItem) + resizeItem = item; + else if (resizeMode == QFxLoader::SizeItemToLoader) + resizeItem = q; + if (resizeItem) { + QObject::connect(resizeItem, SIGNAL(widthChanged()), q, SLOT(_q_updateSize())); + QObject::connect(resizeItem, SIGNAL(heightChanged()), q, SLOT(_q_updateSize())); + } + _q_updateSize(); + } } else { - delete qmlChild; + delete obj; source = QUrl(); } - delete qmlcomp; - qmlcomp = 0; emit q->sourceChanged(); emit q->statusChanged(); emit q->progressChanged(); @@ -196,6 +269,19 @@ void QFxLoaderPrivate::_q_sourceLoaded() \sa progress */ +QFxLoader::Status QFxLoader::status() const +{ + Q_D(const QFxLoader); + + if (d->component) + return static_cast<QFxLoader::Status>(d->component->status()); + + if (d->item) + return Ready; + + return d->source.isEmpty() ? Null : Error; +} + /*! \qmlproperty real Loader::progress @@ -204,27 +290,89 @@ void QFxLoaderPrivate::_q_sourceLoaded() \sa status */ -QFxLoader::Status QFxLoader::status() const +qreal QFxLoader::progress() const { Q_D(const QFxLoader); - if (d->qmlcomp) - return static_cast<QFxLoader::Status>(d->qmlcomp->status()); - if (d->item) - return Ready; + return 1.0; - return d->source.isEmpty() ? Null : Error; + if (d->component) + return d->component->progress(); + + return 0.0; } -qreal QFxLoader::progress() const +/*! + \qmlproperty enum Loader::resizeMode + + This property determines how the Loader or item are resized: + \list + \o NoResize - no item will be resized + \o SizeLoaderToItem - the Loader will be sized to the size of the item, unless the size of the Loader has been otherwise specified. + \o SizeItemToLoader - the item will be sized to the size of the Loader. + \endlist + + The default resizeMode is SizeLoaderToItem. +*/ +QFxLoader::ResizeMode QFxLoader::resizeMode() const { Q_D(const QFxLoader); + return d->resizeMode; +} - if (d->qmlcomp) - return d->qmlcomp->progress(); +void QFxLoader::setResizeMode(ResizeMode mode) +{ + Q_D(QFxLoader); + if (mode == d->resizeMode) + return; - return d->item ? 1.0 : 0.0; + if (d->item) { + QFxItem *resizeItem = 0; + if (d->resizeMode == SizeLoaderToItem) + resizeItem = d->item; + else if (d->resizeMode == SizeItemToLoader) + resizeItem = this; + if (resizeItem) { + disconnect(resizeItem, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); + disconnect(resizeItem, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); + } + } + + d->resizeMode = mode; + + if (d->item) { + QFxItem *resizeItem = 0; + if (d->resizeMode == SizeLoaderToItem) + resizeItem = d->item; + else if (d->resizeMode == SizeItemToLoader) + resizeItem = this; + if (resizeItem) { + connect(resizeItem, SIGNAL(widthChanged()), this, SLOT(_q_updateSize())); + connect(resizeItem, SIGNAL(heightChanged()), this, SLOT(_q_updateSize())); + } + } +} + +void QFxLoaderPrivate::_q_updateSize() +{ + Q_Q(QFxLoader); + if (!item) + return; + switch (resizeMode) { + case QFxLoader::SizeLoaderToItem: + if (!q->widthValid()) + q->setImplicitWidth(item->width()); + if (!q->heightValid()) + q->setImplicitHeight(item->height()); + break; + case QFxLoader::SizeItemToLoader: + item->setWidth(q->width()); + item->setHeight(q->height()); + break; + default: + break; + } } /*! diff --git a/src/declarative/fx/qfxloader.h b/src/declarative/fx/qfxloader.h index 132c8f4..b967465 100644 --- a/src/declarative/fx/qfxloader.h +++ b/src/declarative/fx/qfxloader.h @@ -55,14 +55,15 @@ class Q_DECLARATIVE_EXPORT QFxLoader : public QFxItem { Q_OBJECT Q_ENUMS(Status) + Q_ENUMS(ResizeMode) Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QmlComponent *sourceComponent READ sourceComponent WRITE setSourceComponent NOTIFY sourceChanged) + Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) Q_PROPERTY(QFxItem *item READ item NOTIFY itemChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) //### sourceItem - //### sourceComponent - //### resizeMode { NoResize, SizeLoaderToItem (default), SizeItemToLoader } public: QFxLoader(QFxItem *parent=0); @@ -71,10 +72,17 @@ public: QUrl source() const; void setSource(const QUrl &); + QmlComponent *sourceComponent() const; + void setSourceComponent(QmlComponent *); + enum Status { Null, Ready, Loading, Error }; Status status() const; qreal progress() const; + enum ResizeMode { NoResize, SizeLoaderToItem, SizeItemToLoader }; + ResizeMode resizeMode() const; + void setResizeMode(ResizeMode mode); + QFxItem *item() const; Q_SIGNALS: @@ -87,6 +95,7 @@ private: Q_DISABLE_COPY(QFxLoader) Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxLoader) Q_PRIVATE_SLOT(d_func(), void _q_sourceLoaded()) + Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) }; QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxloader_p.h b/src/declarative/fx/qfxloader_p.h index 13f3b53..0700fcd 100644 --- a/src/declarative/fx/qfxloader_p.h +++ b/src/declarative/fx/qfxloader_p.h @@ -69,10 +69,12 @@ public: QUrl source; QFxItem *item; - QmlComponent *qmlcomp; - QHash<QString, QFxItem *> cachedChildren; + QmlComponent *component; + bool ownComponent; + QFxLoader::ResizeMode resizeMode; void _q_sourceLoaded(); + void _q_updateSize(); }; QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index f291ac0..1c35606 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -91,8 +91,8 @@ Item { height: 10 } } - ComponentInstance { component: RedSquare } - ComponentInstance { component: RedSquare; x: 20 } + Loader { sourceComponent: RedSquare } + Loader { sourceComponent: RedSquare; x: 20 } } \endqml */ @@ -328,6 +328,7 @@ QmlComponent::QmlComponent(QmlEngine *engine, QmlCompiledData *cc, int start, in d->start = start; d->count = count; d->url = cc->url; + d->progress = 1.0; } /*! diff --git a/src/declarative/util/qfxperf.cpp b/src/declarative/util/qfxperf.cpp index 90f639e..739e480 100644 --- a/src/declarative/util/qfxperf.cpp +++ b/src/declarative/util/qfxperf.cpp @@ -58,7 +58,6 @@ Q_DEFINE_PERFORMANCE_LOG(QFxPerf, "QFx") { Q_DEFINE_PERFORMANCE_METRIC(CreateParticle, " QFxParticles: Particle creation") Q_DEFINE_PERFORMANCE_METRIC(ItemComponentComplete, " QFxItem::componentComplete") Q_DEFINE_PERFORMANCE_METRIC(ImageComponentComplete, " QFxImage::componentComplete") - Q_DEFINE_PERFORMANCE_METRIC(ComponentInstanceComponentComplete, " QFxComponentInstance::componentComplete") Q_DEFINE_PERFORMANCE_METRIC(BaseLayoutComponentComplete, " QFxBasePositioner::componentComplete") Q_DEFINE_PERFORMANCE_METRIC(TextComponentComplete, " QFxText::componentComplete") Q_DEFINE_PERFORMANCE_METRIC(QFxText_setText, " QFxText::setText") diff --git a/src/declarative/util/qfxperf_p.h b/src/declarative/util/qfxperf_p.h index a1e38b7..cea7e80 100644 --- a/src/declarative/util/qfxperf_p.h +++ b/src/declarative/util/qfxperf_p.h @@ -77,7 +77,6 @@ Q_DECLARE_PERFORMANCE_LOG(QFxPerf) { Q_DECLARE_PERFORMANCE_METRIC(CreateParticle) Q_DECLARE_PERFORMANCE_METRIC(ItemComponentComplete) Q_DECLARE_PERFORMANCE_METRIC(ImageComponentComplete) - Q_DECLARE_PERFORMANCE_METRIC(ComponentInstanceComponentComplete) Q_DECLARE_PERFORMANCE_METRIC(BaseLayoutComponentComplete) Q_DECLARE_PERFORMANCE_METRIC(TextComponentComplete) Q_DECLARE_PERFORMANCE_METRIC(QFxText_setText) diff --git a/src/declarative/util/qmleasefollow.cpp b/src/declarative/util/qmleasefollow.cpp new file mode 100644 index 0000000..83dbde7 --- /dev/null +++ b/src/declarative/util/qmleasefollow.cpp @@ -0,0 +1,391 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmleasefollow.h" +#include <QtDeclarative/qmlmetaproperty.h> +#include <math.h> +#include <QtCore/qdebug.h> +#include <private/qmlanimation_p.h> + +QT_BEGIN_NAMESPACE + +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,EaseFollow,QmlEaseFollow); + +class QmlEaseFollowPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QmlEaseFollow) +public: + QmlEaseFollowPrivate() + : source(0), velocity(200), duration(-1), + reversingMode(QmlEaseFollow::Eased), initialVelocity(0), + initialValue(0), invert(false), trackVelocity(0), clockOffset(0), + lastTick(0), clock(this) + {} + + qreal source; + qreal velocity; + qreal duration; + QmlEaseFollow::ReversingMode reversingMode; + + qreal initialVelocity; + qreal initialValue; + bool invert; + + qreal trackVelocity; + + QmlMetaProperty target; + + int clockOffset; + int lastTick; + void tick(int); + void clockStart(); + void clockStop(); + QTickAnimationProxy<QmlEaseFollowPrivate, &QmlEaseFollowPrivate::tick> clock; + + void restart(); + + // Parameters for use in tick() + qreal a; // Acceleration + qreal tf; // Total time + qreal tp; // Time at which peak velocity occurs + qreal vp; // Velocity at tp + qreal sp; // Displacement at tp + qreal vi; // "Normalized" initialvelocity + bool recalc(); +}; + +bool QmlEaseFollowPrivate::recalc() +{ + qreal s = source - initialValue; + vi = initialVelocity; + + s = (invert?-1.0:1.0) * s; + vi = (invert?-1.0:1.0) * vi; + + if (duration > 0 && velocity > 0) { + tf = s / velocity; + if (tf > (duration / 1000.)) tf = (duration / 1000.); + } else if (duration > 0) { + tf = duration / 1000.; + } else if (velocity > 0) { + tf = s / velocity; + } else { + return false; + } + + qreal c1 = 0.25 * tf * tf; + qreal c2 = 0.5 * vi * tf - s; + qreal c3 = -0.25 * vi * vi; + + qreal a1 = (-c2 + sqrt(c2 * c2 - 4 * c1 * c3)) / (2. * c1); + // qreal a2 = (-c2 - sqrt(c2 * c2 - 4 * c1 * c3)) / (2. * c1); + + qreal tp1 = 0.5 * tf - 0.5 * vi / a1; + // qreal tp2 = 0.5 * tf - 0.5 * vi / a2; + qreal vp1 = a1 * tp1 + vi; + // qreal vp2 = a2 * tp2 + vi; + + qreal sp1 = 0.5 * a1 * tp1 * tp1 + vi * tp1; + // qreal sp2 = 0.5 * a2 * tp2 * tp2 + vi * tp2; + + a = a1; + tp = tp1; + vp = vp1; + sp = sp1; + + return true; +} + +void QmlEaseFollowPrivate::clockStart() +{ + if (clock.state() == QAbstractAnimation::Running) { + clockOffset = lastTick; + return; + } else { + clockOffset = 0; + lastTick = 0; + clock.start(); + } +} + +void QmlEaseFollowPrivate::clockStop() +{ + clockOffset = 0; + lastTick = 0; + clock.stop(); +} + +void QmlEaseFollowPrivate::tick(int t) +{ + lastTick = t; + t -= clockOffset; + + qreal time_seconds = qreal(t) / 1000.; + + if (time_seconds < tp) { + + trackVelocity = vi + time_seconds * a; + trackVelocity = (invert?-1.0:1.0) * trackVelocity; + + qreal value = 0.5 * a * time_seconds * time_seconds + vi * time_seconds; + value = (invert?-1.0:1.0) * value; + target.write(initialValue + value); + + } else if (time_seconds < tf) { + + time_seconds -= tp; + + trackVelocity = vp - time_seconds * a; + trackVelocity = (invert?-1.0:1.0) * trackVelocity; + + qreal value = 0.5 * a * tp * tp + vi * tp + - 0.5 * a * time_seconds * time_seconds + vp * time_seconds; + value = (invert?-1.0:1.0) * value; + + target.write(initialValue + value); + + } else { + + clock.stop(); + + trackVelocity = 0; + target.write(source); + } +} + +/*! + \qmlclass EaseFollow QmlEaseFollow + \brief The EaseFollow element allows a property to smoothly track a value. + + The EaseFollow smoothly animates a property's value to a set target value + using an ease in/out quad easing curve. If the target value changes while + the animation is in progress, the easing curves used to animate to the old + and the new target values are spliced together to avoid any obvious visual + glitches. + + The property animation is configured by setting the velocity at which the + animation should occur, or the duration that the animation should take. + If both a velocity and a duration are specified, the one that results in + the quickest animation is chosen for each change in the target value. + + For example, animating from 0 to 800 will take 4 seconds if a velocity + of 200 is set, will take 8 seconds with a duration of 8000 set, and will + take 4 seconds with both a velocity of 200 and a duration of 8000 set. + Animating from 0 to 20000 will take 10 seconds if a velocity of 200 is set, + will take 8 seconds with a duration of 8000 set, and will take 8 seconds + with both a velocity of 200 and a duration of 8000 set. + + The follow example shows one rectangle tracking the position of another. +\code +import Qt 4.6 + +Rectangle { + width: 800; height: 600; color: "blue" + + Rectangle { + color: "green" + width: 60; height: 60; + x: -5; y: -5; + x: EaseFollow { source: Rect1.x - 5; velocity: 200 } + y: EaseFollow { source: Rect1.y - 5; velocity: 200 } + } + + Rectangle { + id: Rect1 + color: "red" + width: 50; height: 50; + } + + focus: true + Keys.onRightPressed: Rect1.x = Rect1.x + 100 + Keys.onLeftPressed: Rect1.x = Rect1.x - 100 + Keys.onUpPressed: Rect1.y = Rect1.y - 100 + Keys.onDownPressed: Rect1.y = Rect1.y + 100 +} +\endcode +*/ + +QmlEaseFollow::QmlEaseFollow(QObject *parent) +: QObject(*(new QmlEaseFollowPrivate), parent) +{ +} + +QmlEaseFollow::~QmlEaseFollow() +{ +} + +/*! + \qmlproperty qreal EaseFollow::source + This property holds the source value which will be tracked. + + Bind to a property in order to track its changes. +*/ +qreal QmlEaseFollow::sourceValue() const +{ + Q_D(const QmlEaseFollow); + return d->source; +} + +/*! + \qmlproperty enumeration EaseFollow::reversingMode + + Sets how the EaseFollow behaves if an animation diration is reversed. + + If reversing mode is \c Eased, the animation will smoothly decelerate, and + then reverse direction. If the reversing mode is \c Immediate, the + animation will immediately begin accelerating in the reverse direction, + begining with a velocity of 0. If the reversing mode is \c Sync, the + property is immediately set to the target value. +*/ +QmlEaseFollow::ReversingMode QmlEaseFollow::reversingMode() const +{ + Q_D(const QmlEaseFollow); + return d->reversingMode; +} + +void QmlEaseFollow::setReversingMode(ReversingMode m) +{ + Q_D(QmlEaseFollow); + d->reversingMode = m; +} + +void QmlEaseFollowPrivate::restart() +{ + initialValue = target.read().toReal(); + + if (source == initialValue) { + clockStop(); + return; + } + + bool hasReversed = trackVelocity != 0. && + ((trackVelocity > 0) == ((initialValue - source) > 0)); + + if (hasReversed) { + switch (reversingMode) { + default: + case QmlEaseFollow::Eased: + break; + case QmlEaseFollow::Sync: + target.write(source); + return; + case QmlEaseFollow::Immediate: + initialVelocity = 0; + clockStop(); + break; + } + } + + trackVelocity = initialVelocity; + + invert = (source < initialValue); + + if (!recalc()) { + target.write(source); + clockStop(); + return; + } + + clockStart(); +} + +void QmlEaseFollow::setSourceValue(qreal s) +{ + Q_D(QmlEaseFollow); + + d->source = s; + d->initialVelocity = d->trackVelocity; + d->restart(); +} + +/*! + \qmlproperty qreal EaseFollow::duration + + This property holds the animation duration used when tracking the source. + + Setting this to -1 disables the duration value. +*/ +qreal QmlEaseFollow::duration() const +{ + Q_D(const QmlEaseFollow); + return d->duration; +} + +void QmlEaseFollow::setDuration(qreal v) +{ + Q_D(QmlEaseFollow); + d->duration = v; + d->trackVelocity = 0; + + if (d->clock.state() == QAbstractAnimation::Running) + d->restart(); +} + +qreal QmlEaseFollow::velocity() const +{ + Q_D(const QmlEaseFollow); + return d->velocity; +} + +/*! + \qmlproperty qreal EaseFollow::velocity + + This property holds the average velocity allowed when tracking the source. + + Setting this to -1 disables the velocity value. +*/ +void QmlEaseFollow::setVelocity(qreal v) +{ + Q_D(QmlEaseFollow); + d->velocity = v; + d->trackVelocity = 0; + + if (d->clock.state() == QAbstractAnimation::Running) + d->restart(); +} + +void QmlEaseFollow::setTarget(const QmlMetaProperty &t) +{ + Q_D(QmlEaseFollow); + d->target = t; +} + +QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxcomponentinstance.h b/src/declarative/util/qmleasefollow.h index b223ca2..adcb647 100644 --- a/src/declarative/fx/qfxcomponentinstance.h +++ b/src/declarative/util/qmleasefollow.h @@ -39,10 +39,12 @@ ** ****************************************************************************/ -#ifndef QFXCOMPONENTINSTANCE_H -#define QFXCOMPONENTINSTANCE_H +#ifndef QMLEASEFOLLOW_H +#define QMLEASEFOLLOW_H -#include <QtDeclarative/qfxitem.h> +#include <QtCore/qobject.h> +#include <QtDeclarative/qml.h> +#include <QtDeclarative/qmlpropertyvaluesource.h> QT_BEGIN_HEADER @@ -50,44 +52,46 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -//### remove -//### add component property to Loader - -class QFxComponentInstancePrivate; -class Q_DECLARATIVE_EXPORT QFxComponentInstance : public QFxItem +class QmlMetaProperty; +class QmlEaseFollowPrivate; +class Q_DECLARATIVE_EXPORT QmlEaseFollow : public QObject, + public QmlPropertyValueSource { Q_OBJECT - Q_PROPERTY(QmlComponent *component READ component WRITE setComponent) - Q_PROPERTY(QFxItem *instance READ instance) - Q_CLASSINFO("DefaultProperty", "component") -public: - QFxComponentInstance(QFxItem *parent=0); + Q_DECLARE_PRIVATE(QmlEaseFollow) + Q_INTERFACES(QmlPropertyValueSource) + Q_ENUMS(ReversingMode) - QmlComponent *component() const; - void setComponent(QmlComponent *); + Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue) + Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) + Q_PROPERTY(qreal duration READ duration WRITE setDuration) + Q_PROPERTY(ReversingMode reversingMode READ reversingMode WRITE setReversingMode) + +public: + enum ReversingMode { Eased, Immediate, Sync }; - QFxItem *instance() const; + QmlEaseFollow(QObject *parent = 0); + ~QmlEaseFollow(); -Q_SIGNALS: - void instanceChanged(); + ReversingMode reversingMode() const; + void setReversingMode(ReversingMode); -private Q_SLOTS: - void updateSize(); + qreal sourceValue() const; + void setSourceValue(qreal); -private: - void create(); + qreal velocity() const; + void setVelocity(qreal); -protected: - QFxComponentInstance(QFxComponentInstancePrivate &dd, QFxItem *parent); + qreal duration() const; + void setDuration(qreal); -private: - Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QFxComponentInstance) + virtual void setTarget(const QmlMetaProperty &); }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxComponentInstance) +QML_DECLARE_TYPE(QmlEaseFollow); QT_END_HEADER -#endif // QFXCOMPONENTINSTANCE_H +#endif // QMLEASEFOLLOW_H diff --git a/src/declarative/util/qmlfollow.h b/src/declarative/util/qmlfollow.h index 1f6376a..ff34d08 100644 --- a/src/declarative/util/qmlfollow.h +++ b/src/declarative/util/qmlfollow.h @@ -52,13 +52,12 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QmlFollowPrivate; -class Q_DECLARATIVE_EXPORT QmlFollow : public QObject, public QmlPropertyValueSource, - public QmlParserStatus +class Q_DECLARATIVE_EXPORT QmlFollow : public QObject, + public QmlPropertyValueSource { Q_OBJECT Q_DECLARE_PRIVATE(QmlFollow) Q_INTERFACES(QmlPropertyValueSource) - Q_INTERFACES(QmlParserStatus) Q_PROPERTY(qreal source READ sourceValue WRITE setSourceValue) Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity) diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index f1b599f..a57f69f 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -8,6 +8,7 @@ SOURCES += \ util/qmlanimation.cpp \ util/qmlsystempalette.cpp \ util/qmlfollow.cpp \ + util/qmleasefollow.cpp \ util/qmlstate.cpp\ util/qmltransitionmanager.cpp \ util/qmlstateoperations.cpp \ @@ -33,6 +34,7 @@ HEADERS += \ util/qmlanimation_p.h \ util/qmlsystempalette.h \ util/qmlfollow.h \ + util/qmleasefollow.h \ util/qmlstate.h\ util/qmlstateoperations.h \ util/qmlpropertychanges.h \ diff --git a/tests/auto/declarative/qfxloader/NoResize.qml b/tests/auto/declarative/qfxloader/NoResize.qml new file mode 100644 index 0000000..cfbb55a --- /dev/null +++ b/tests/auto/declarative/qfxloader/NoResize.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +Loader { + resizeMode: "NoResize" + width: 200; height: 80 + source: "Rect120x60.qml" +} diff --git a/tests/auto/declarative/qfxloader/Rect120x60.qml b/tests/auto/declarative/qfxloader/Rect120x60.qml new file mode 100644 index 0000000..aa4b0c2 --- /dev/null +++ b/tests/auto/declarative/qfxloader/Rect120x60.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Rectangle { + width: 120 + height:60 +} diff --git a/tests/auto/declarative/qfxloader/SetSourceComponent.qml b/tests/auto/declarative/qfxloader/SetSourceComponent.qml new file mode 100644 index 0000000..c5dd7ff --- /dev/null +++ b/tests/auto/declarative/qfxloader/SetSourceComponent.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Item { + Component { id: Comp; Rectangle { width: 120; height: 60 } } + Loader { sourceComponent: Comp } +} diff --git a/tests/auto/declarative/qfxloader/SizeToItem.qml b/tests/auto/declarative/qfxloader/SizeToItem.qml new file mode 100644 index 0000000..b52fa03 --- /dev/null +++ b/tests/auto/declarative/qfxloader/SizeToItem.qml @@ -0,0 +1,6 @@ +import Qt 4.6 + +Loader { + resizeMode: "SizeLoaderToItem" + source: "Rect120x60.qml" +} diff --git a/tests/auto/declarative/qfxloader/SizeToLoader.qml b/tests/auto/declarative/qfxloader/SizeToLoader.qml new file mode 100644 index 0000000..1a107e1 --- /dev/null +++ b/tests/auto/declarative/qfxloader/SizeToLoader.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +Loader { + resizeMode: "SizeItemToLoader" + width: 200; height: 80 + source: "Rect120x60.qml" +} diff --git a/tests/auto/declarative/qfxloader/qfxloader.pro b/tests/auto/declarative/qfxloader/qfxloader.pro new file mode 100644 index 0000000..643c18c --- /dev/null +++ b/tests/auto/declarative/qfxloader/qfxloader.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +SOURCES += tst_qfxloader.cpp + +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxloader/tst_qfxloader.cpp b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp new file mode 100644 index 0000000..2109898 --- /dev/null +++ b/tests/auto/declarative/qfxloader/tst_qfxloader.cpp @@ -0,0 +1,103 @@ +#include <qtest.h> +#include <QtDeclarative/qmlengine.h> +#include <QtDeclarative/qmlcomponent.h> +#include <QtDeclarative/qfxloader.h> + +class tst_qfxloader : public QObject + +{ + Q_OBJECT +public: + tst_qfxloader(); + +private slots: + void url(); + void component(); + void sizeLoaderToItem(); + void sizeItemToLoader(); + void noResize(); + +private: + QmlEngine engine; +}; + +/* +inline QUrl TEST_FILE(const QString &filename) +{ + QFileInfo fileInfo(__FILE__); + return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath(filename)); +} + +inline QUrl TEST_FILE(const char *filename) +{ + return TEST_FILE(QLatin1String(filename)); +} +*/ + +tst_qfxloader::tst_qfxloader() +{ +} + +void tst_qfxloader::url() +{ + QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"Rect120x60.qml\" }"), QUrl("file://" SRCDIR "/")); + QFxLoader *loader = qobject_cast<QFxLoader*>(component.create()); + QVERIFY(loader != 0); + QVERIFY(loader->item()); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); +} + +void tst_qfxloader::component() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/SetSourceComponent.qml")); + QFxItem *item = qobject_cast<QFxItem*>(component.create()); + QVERIFY(item); + + QFxLoader *loader = qobject_cast<QFxLoader*>(item->QGraphicsObject::children().at(1)); + QVERIFY(loader); + QVERIFY(loader->item()); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); +} + +void tst_qfxloader::sizeLoaderToItem() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/SizeToItem.qml")); + QFxLoader *loader = qobject_cast<QFxLoader*>(component.create()); + QVERIFY(loader != 0); + QCOMPARE(loader->width(), 120.0); + QCOMPARE(loader->height(), 60.0); +} + +void tst_qfxloader::sizeItemToLoader() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/SizeToLoader.qml")); + QFxLoader *loader = qobject_cast<QFxLoader*>(component.create()); + QVERIFY(loader != 0); + QCOMPARE(loader->width(), 200.0); + QCOMPARE(loader->height(), 80.0); + + QFxItem *rect = loader->item(); + QVERIFY(rect); + QCOMPARE(rect->width(), 200.0); + QCOMPARE(rect->height(), 80.0); +} + +void tst_qfxloader::noResize() +{ + QmlComponent component(&engine, QUrl("file://" SRCDIR "/NoResize.qml")); + QFxLoader *loader = qobject_cast<QFxLoader*>(component.create()); + QVERIFY(loader != 0); + QCOMPARE(loader->width(), 200.0); + QCOMPARE(loader->height(), 80.0); + + QFxItem *rect = loader->item(); + QVERIFY(rect); + QCOMPARE(rect->width(), 120.0); + QCOMPARE(rect->height(), 60.0); +} + +QTEST_MAIN(tst_qfxloader) + +#include "tst_qfxloader.moc" |