From 0ce2bedf9b5da9d480b994a9b812c37d1f5caa39 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 31 Jul 2009 09:39:53 +1000 Subject: Introduce Loader item. The Loader item takes the qml/qmlItem functionality from Item and moves it to a specialized subclass. --- demos/declarative/contacts/contacts.qml | 16 +- doc/src/declarative/elements.qdoc | 1 + doc/src/tutorials/declarative.qdoc | 16 +- examples/declarative/flowview/flowview.qml | 2 +- examples/declarative/loader/loader.qml | 6 +- .../contacts/1_Drawing_and_Animation/GroupBox.qml | 8 +- .../tutorials/contacts/2_Reuse/1a/ContactField.qml | 8 +- .../tutorials/contacts/2_Reuse/GroupBox.qml | 8 +- .../contacts/3_Collections/3/ContactView.qml | 12 +- .../tutorials/contacts/3_Collections/GroupBox.qml | 8 +- src/declarative/fx/fx.pri | 3 + src/declarative/fx/qfxitem.cpp | 146 ---------------- src/declarative/fx/qfxitem.h | 12 +- src/declarative/fx/qfxitem_p.h | 9 +- src/declarative/fx/qfxloader.cpp | 188 +++++++++++++++++++++ src/declarative/fx/qfxloader.h | 85 ++++++++++ src/declarative/fx/qfxloader_p.h | 80 +++++++++ 17 files changed, 403 insertions(+), 205 deletions(-) create mode 100644 src/declarative/fx/qfxloader.cpp create mode 100644 src/declarative/fx/qfxloader.h create mode 100644 src/declarative/fx/qfxloader_p.h diff --git a/demos/declarative/contacts/contacts.qml b/demos/declarative/contacts/contacts.qml index 189a5d7..6bd7b21 100644 --- a/demos/declarative/contacts/contacts.qml +++ b/demos/declarative/contacts/contacts.qml @@ -42,7 +42,7 @@ Rect { MouseRegion { anchors.fill: parent onClicked: { - Details.qml = 'Contact.qml'; + Details.source = 'Contact.qml'; wrapper.state ='opened'; contacts.mode = 'edit'; } @@ -67,27 +67,27 @@ Rect { } ] } - Item { + Loader { id: Details anchors.fill: wrapper opacity: 0 Bind { - target: Details.qmlItem + target: Details.item property: "contactId" value: model.recid } Bind { - target: Details.qmlItem + target: Details.item property: "label" value: model.label } Bind { - target: Details.qmlItem + target: Details.item property: "phone" value: model.phone } Bind { - target: Details.qmlItem + target: Details.item property: "email" value: model.email } @@ -130,7 +130,7 @@ Rect { signal: "clicked()" script: { if (wrapper.state == 'opened' && !contacts.mouseGrabbed) { - Details.qmlItem.update(); + Details.item.update(); wrapper.state = ''; contacts.mode = 'list'; contactList.exec(); @@ -154,7 +154,7 @@ Rect { signal: "confirmed()" script: { if (wrapper.state == 'opened' && !contacts.mouseGrabbed) { - Details.qmlItem.remove(); + Details.item.remove(); wrapper.state = ''; contacts.mode = 'list'; contactList.exec(); diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index 88b5963..63cd377 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -94,6 +94,7 @@ The following table lists the Qml elements provided by the Qt Declarative module \o \list +\o \l Loader \o \l Repeater \o \l ComponentInstance \o \l GraphicsObjectContainer diff --git a/doc/src/tutorials/declarative.qdoc b/doc/src/tutorials/declarative.qdoc index 3fad672..b7a4d7d 100644 --- a/doc/src/tutorials/declarative.qdoc +++ b/doc/src/tutorials/declarative.qdoc @@ -402,9 +402,9 @@ This can be useful when the component is not complex enough to justify its own file. The third way to reuse components allows for delaying loading - of the QML until some later event. Each \l{Item}{Item} includes - a special child, qmlItem, which has its definition provided by the - contents of the qml property of its parent. + of the QML until some later event. \l{Loader}{Loader} includes + a special child, item, which has its definition provided by the + contents of the source property of the loader. \snippet declarative/tutorials/contacts/2_Reuse/1a/ContactField.qml load @@ -656,8 +656,8 @@ \snippet declarative/tutorials/contacts/3_Collections/3/ContactView.qml setting qml - Each item has a qml property that represents the filename for the contents of - a special qmlItem child of the \l{Item}{Item}. By setting the qml property of the Details + \l{Loader}{Loader} has a source property that represents the filename for the contents of + a special item child of the \l{Loader}{Loader}. By setting the source property of the Details component on clicking the mouse region, the more complex component isn't loaded until needed. The down side about this though is the properties of Contact cannot be set until the item is loaded. This requires using the Bind element. @@ -667,8 +667,8 @@ Unlike binding a value to the property of a component directly, the Bind element allows both the target and the property set to themselves be to dynamic values. - This means that when the qml property is set, it will change the - qmlItem property of the Details component. This in turn triggers the Bind - elements to set the required properties of the qmlItem, which is now + This means that when the source property is set, it will change the + item property of the Details component. This in turn triggers the Bind + elements to set the required properties of the item, which is now an instance of the Contact component. */ diff --git a/examples/declarative/flowview/flowview.qml b/examples/declarative/flowview/flowview.qml index 77b3230..ff15d96 100644 --- a/examples/declarative/flowview/flowview.qml +++ b/examples/declarative/flowview/flowview.qml @@ -45,7 +45,7 @@ Rect { delegate: Package { Item { id: List; Package.name: "list"; width:120; height: 400; } Item { id: Grid; Package.name: "grid"; width:400; height: 120; } - Item { id: MyContent; width:400; height: 120; qml: weblet } + Loader { id: MyContent; width:400; height: 120; source: weblet } StateGroup { states: [ diff --git a/examples/declarative/loader/loader.qml b/examples/declarative/loader/loader.qml index 447d73a..f507651 100644 --- a/examples/declarative/loader/loader.qml +++ b/examples/declarative/loader/loader.qml @@ -1,8 +1,10 @@ import Qt 4.6 Rect { - id: Shell width: 300 height: 400 - qml: "Browser.qml" + Loader { + anchors.fill: parent + source: "Browser.qml" + } } diff --git a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/GroupBox.qml b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/GroupBox.qml index 42feeb1..29e00d9 100644 --- a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/GroupBox.qml +++ b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/GroupBox.qml @@ -17,15 +17,15 @@ FocusRealm { height: groupBox.height-20 color: "white" pen.color: "black" - Item { + Loader { id: subItem - qml: groupBox.contents + source: groupBox.contents anchors.top: parent.top anchors.topMargin: 10 anchors.right: parent.right anchors.rightMargin: 10 - width: qmlItem.width - height: qmlItem.height + width: item.width + height: item.height } } Rect { diff --git a/examples/declarative/tutorials/contacts/2_Reuse/1a/ContactField.qml b/examples/declarative/tutorials/contacts/2_Reuse/1a/ContactField.qml index e3081b9..cf50fb0 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/1a/ContactField.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/1a/ContactField.qml @@ -6,11 +6,11 @@ Item { clip: true width: 230 height: 30 - Item { + Loader { id: removeButton - qml: "RemoveButton.qml" - width: qmlItem.width - height: qmlItem.height + source: "RemoveButton.qml" + width: item.width + height: item.height anchors.right: parent.right anchors.top: parent.top anchors.bottom: parent.bottom diff --git a/examples/declarative/tutorials/contacts/2_Reuse/GroupBox.qml b/examples/declarative/tutorials/contacts/2_Reuse/GroupBox.qml index 42feeb1..29e00d9 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/GroupBox.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/GroupBox.qml @@ -17,15 +17,15 @@ FocusRealm { height: groupBox.height-20 color: "white" pen.color: "black" - Item { + Loader { id: subItem - qml: groupBox.contents + source: groupBox.contents anchors.top: parent.top anchors.topMargin: 10 anchors.right: parent.right anchors.rightMargin: 10 - width: qmlItem.width - height: qmlItem.height + width: item.width + height: item.height } } Rect { diff --git a/examples/declarative/tutorials/contacts/3_Collections/3/ContactView.qml b/examples/declarative/tutorials/contacts/3_Collections/3/ContactView.qml index 46e09a0..cc115e3 100644 --- a/examples/declarative/tutorials/contacts/3_Collections/3/ContactView.qml +++ b/examples/declarative/tutorials/contacts/3_Collections/3/ContactView.qml @@ -56,33 +56,33 @@ Item { MouseRegion { anchors.fill: label onClicked: { - Details.qml = 'Contact.qml'; + Details.source = 'Contact.qml'; wrapper.state='opened'; } } - Item { + Loader { id: Details anchors.fill: parent opacity: 0 //! [setting qml] //! [binding] Bind { - target: Details.qmlItem + target: Details.item property: "contactId" value: model.recid } Bind { - target: Details.qmlItem + target: Details.item property: "label" value: model.label } Bind { - target: Details.qmlItem + target: Details.item property: "phone" value: model.phone } Bind { - target: Details.qmlItem + target: Details.item property: "email" value: model.email } diff --git a/examples/declarative/tutorials/contacts/3_Collections/GroupBox.qml b/examples/declarative/tutorials/contacts/3_Collections/GroupBox.qml index 42feeb1..29e00d9 100644 --- a/examples/declarative/tutorials/contacts/3_Collections/GroupBox.qml +++ b/examples/declarative/tutorials/contacts/3_Collections/GroupBox.qml @@ -17,15 +17,15 @@ FocusRealm { height: groupBox.height-20 color: "white" pen.color: "black" - Item { + Loader { id: subItem - qml: groupBox.contents + source: groupBox.contents anchors.top: parent.top anchors.topMargin: 10 anchors.right: parent.right anchors.rightMargin: 10 - width: qmlItem.width - height: qmlItem.height + width: item.width + height: item.height } } Rect { diff --git a/src/declarative/fx/fx.pri b/src/declarative/fx/fx.pri index 9b4b5ab..e43c0cb 100644 --- a/src/declarative/fx/fx.pri +++ b/src/declarative/fx/fx.pri @@ -19,6 +19,8 @@ HEADERS += \ fx/qfxkeyproxy.h \ fx/qfxlayouts.h \ fx/qfxlayouts_p.h \ + fx/qfxloader.h \ + fx/qfxloader_p.h \ fx/qfxmouseregion.h \ fx/qfxmouseregion_p.h \ fx/qfxpath.h \ @@ -55,6 +57,7 @@ SOURCES += \ fx/qfxkeyactions.cpp \ fx/qfxkeyproxy.cpp \ fx/qfxlayouts.cpp \ + fx/qfxloader.cpp \ fx/qfxmouseregion.cpp \ fx/qfxpath.cpp \ fx/qfxpathview.cpp \ diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 6df538e..709a243 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -51,7 +51,6 @@ #include #include -#include #include "qmlstate.h" #include "qlistmodelinterface.h" #include "qfxanchors_p.h" @@ -743,151 +742,6 @@ void QFxItem::setClip(bool c) } /*! - \internal - \property QFxItem::qmlItem -*/ - -/*! \fn QFxItem *QFxItem::qmlItem() const - \internal - */ -QFxItem *QFxItem::qmlItem() const -{ - Q_D(const QFxItem); - return d->qmlItem; -} - -/*! - \qmlproperty url Item::qml - This property holds the dynamic URL of the QML for the item. - - This property is used for dynamically loading QML into the - item. Querying for the QML only has meaning if the QML has been - dynamically set; otherwise an empty URL is returned. -*/ - -/*! \fn void QFxItem::qmlChanged() - This signal is emitted whenever the item's dynamic QML - string changes. - - \sa setQml() - */ - -/*! - \property QFxItem::qml - This property holds the dynamic URL of the QML for the item. - - This property is used for dynamically loading QML into the - item. Querying for the QML only has meaning if the QML has been - dynamically set; otherwise an empty URL is returned. -*/ -QUrl QFxItem::qml() const -{ - Q_D(const QFxItem); - return d->_qml; -} - -void QFxItem::setQml(const QUrl &qml) -{ - Q_D(QFxItem); - if (d->_qml == qml) - return; - - if (!d->_qml.isEmpty()) { - QHash::Iterator iter = d->_qmlChildren.find(d->_qml.toString()); - if (iter != d->_qmlChildren.end()) - (*iter)->setOpacity(0.); - } - - d->_qml = qml; - d->qmlItem = 0; - - if (d->_qml.isEmpty()) { - emit qmlChanged(); - return; - } - - QHash::Iterator iter = d->_qmlChildren.find(d->_qml.toString()); - if (iter != d->_qmlChildren.end()) { - (*iter)->setOpacity(1.); - d->qmlItem = (*iter); - emit qmlChanged(); - } else { - d->_qmlcomp = - new QmlComponent(qmlEngine(this), d->_qml, this); - if (!d->_qmlcomp->isLoading()) - qmlLoaded(); - else - QObject::connect(d->_qmlcomp, SIGNAL(statusChanged(QmlComponent::Status)), - this, SLOT(qmlLoaded())); - } -} - -/*! \fn void QFxItem::newChildCreated(const QString &url, QScriptValue v) - This signal is emitted with the \a url and the script value \a v, - when a new child is created. - */ - -/*! - \internal - */ -void QFxItem::qmlLoaded() -{ - Q_D(QFxItem); - - { // newChild... - // ### - for (int i=0; i_qmlnewloading.length(); ++i) { - QmlComponent *c = d->_qmlnewcomp.at(i); - if (c->isLoading()) - continue; - - QmlContext *ctxt = new QmlContext(qmlContext(this)); - QObject* o = c ? c->create(ctxt):0; - QFxItem* ret = qobject_cast(o); - if (ret) { - ret->setParentItem(this); - QScriptValue v = QmlEnginePrivate::getScriptEngine(qmlEngine(this))->newQObject(ret); - emit newChildCreated(d->_qmlnewloading.at(i).toString(),v); - } - - delete c; - d->_qmlnewloading.removeAt(i); - d->_qmlnewcomp.removeAt(i); - --i; - } - } - - // setQml... - if (d->_qmlcomp) { - QmlContext *ctxt = new QmlContext(qmlContext(this)); - ctxt->addDefaultObject(this); - - if (!d->_qmlcomp->errors().isEmpty()) { - qWarning() << d->_qmlcomp->errors(); - delete d->_qmlcomp; - d->_qmlcomp = 0; - emit qmlChanged(); - return; - } - QObject *obj = d->_qmlcomp->create(ctxt); - if (!d->_qmlcomp->errors().isEmpty()) - qWarning() << d->_qmlcomp->errors(); - QFxItem *qmlChild = qobject_cast(obj); - if (qmlChild) { - qmlChild->setParentItem(this); - d->_qmlChildren.insert(d->_qml.toString(), qmlChild); - d->qmlItem = qmlChild; - } else { - delete qmlChild; - d->_qml = QUrl(); - } - delete d->_qmlcomp; - d->_qmlcomp = 0; - emit qmlChanged(); - } -} - -/*! \qmlproperty real Item::x \qmlproperty real Item::y \qmlproperty real Item::width diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index c31b8bb..884a6d8 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -127,15 +127,13 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserSta Q_PROPERTY(QmlList *data READ data DESIGNABLE false) Q_PROPERTY(QmlList* children READ children DESIGNABLE false) Q_PROPERTY(QmlList* resources READ resources DESIGNABLE false) - Q_PROPERTY(QFxAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL) - Q_PROPERTY(QFxContents * contents READ contents DESIGNABLE false CONSTANT FINAL) Q_PROPERTY(QmlList* states READ states DESIGNABLE false) Q_PROPERTY(QmlList* transitions READ transitions DESIGNABLE false) Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) - Q_PROPERTY(QUrl qml READ qml WRITE setQml NOTIFY qmlChanged) // ### name? Move to own class? - Q_PROPERTY(QFxItem *qmlItem READ qmlItem NOTIFY qmlChanged) // ### see above Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged FINAL) Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged FINAL) + Q_PROPERTY(QFxContents * contents READ contents DESIGNABLE false CONSTANT FINAL) + Q_PROPERTY(QFxAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL) Q_PROPERTY(QFxAnchorLine left READ left CONSTANT FINAL) Q_PROPERTY(QFxAnchorLine right READ right CONSTANT FINAL) Q_PROPERTY(QFxAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL) @@ -187,10 +185,6 @@ public: QString state() const; void setState(const QString &); - QFxItem *qmlItem() const; - QUrl qml() const; - void setQml(const QUrl &); - qreal baselineOffset() const; void setBaselineOffset(qreal); @@ -238,7 +232,6 @@ Q_SIGNALS: void rotationChanged(); void scaleChanged(); void qmlChanged(); - void newChildCreated(const QString &url, QScriptValue); protected: bool isComponentComplete() const; @@ -261,7 +254,6 @@ protected: private Q_SLOTS: void doUpdate(); - void qmlLoaded(); protected: QFxItem(QFxItemPrivate &dd, QFxItem *parent = 0); diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h index 181c91d..862171b 100644 --- a/src/declarative/fx/qfxitem_p.h +++ b/src/declarative/fx/qfxitem_p.h @@ -73,7 +73,7 @@ class QFxItemPrivate : public QGraphicsItemPrivate public: QFxItemPrivate() - : _anchors(0), _contents(0), qmlItem(0), _qmlcomp(0), + : _anchors(0), _contents(0), _baselineOffset(0), _componentComplete(true), _keepMouse(false), _anchorLines(0), @@ -149,19 +149,12 @@ public: QList dependantAnchors; QFxAnchors *_anchors; QFxContents *_contents; - QFxItem *qmlItem; - QmlComponent *_qmlcomp; - QUrl _qml; - QList _qmlnewloading; - QList _qmlnewcomp; QmlNullableValue _baselineOffset; bool _componentComplete:1; bool _keepMouse:1; - QHash _qmlChildren; - struct AnchorLines { AnchorLines(QFxItem *); QFxAnchorLine left; diff --git a/src/declarative/fx/qfxloader.cpp b/src/declarative/fx/qfxloader.cpp new file mode 100644 index 0000000..7cf85af --- /dev/null +++ b/src/declarative/fx/qfxloader.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** 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 "qfxloader_p.h" +#include + +QT_BEGIN_NAMESPACE + +QFxLoaderPrivate::QFxLoaderPrivate() +: item(0), qmlcomp(0) +{ +} + +QFxLoaderPrivate::~QFxLoaderPrivate() +{ +} + +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. + */ + +/*! + \internal + \class QFxLoader + \qmlclass Loader + */ + +/*! + Create a new QFxLoader instance. + */ +QFxLoader::QFxLoader(QFxItem *parent) + : QFxItem(*(new QFxLoaderPrivate), parent) +{ +} + +/*! + Destroy the loader instance. + */ +QFxLoader::~QFxLoader() +{ +} + +/*! + \internal + \fn void QFxItem::sourceChanged() + This signal is emitted whenever the item's dynamic QML + source url changes. + */ + +/*! + \qmlproperty url Loader::source + This property holds the dynamic URL of the QML for the item. + + This property is used for dynamically loading QML into the + item. +*/ +QUrl QFxLoader::source() const +{ + Q_D(const QFxLoader); + return d->source; +} + +void QFxLoader::setSource(const QUrl &url) +{ + Q_D(QFxLoader); + if (d->source == url) + return; + + if (!d->source.isEmpty()) { + QHash::Iterator iter = d->cachedChildren.find(d->source.toString()); + if (iter != d->cachedChildren.end()) + (*iter)->setOpacity(0.); + } + + d->source = url; + d->item = 0; + + if (d->source.isEmpty()) { + emit sourceChanged(); + return; + } + + QHash::Iterator iter = d->cachedChildren.find(d->source.toString()); + if (iter != d->cachedChildren.end()) { + (*iter)->setOpacity(1.); + d->item = (*iter); + emit sourceChanged(); + } 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())); + } +} + +void QFxLoaderPrivate::_q_sourceLoaded() +{ + Q_Q(QFxLoader); + + if (qmlcomp) { + QmlContext *ctxt = new QmlContext(qmlContext(q)); + ctxt->addDefaultObject(q); + + if (!qmlcomp->errors().isEmpty()) { + qWarning() << qmlcomp->errors(); + delete qmlcomp; + qmlcomp = 0; + emit q->sourceChanged(); + return; + } + QObject *obj = qmlcomp->create(ctxt); + if (!qmlcomp->errors().isEmpty()) + qWarning() << qmlcomp->errors(); + QFxItem *qmlChild = qobject_cast(obj); + if (qmlChild) { + qmlChild->setParentItem(q); + cachedChildren.insert(source.toString(), qmlChild); + item = qmlChild; + } else { + delete qmlChild; + source = QUrl(); + } + delete qmlcomp; + qmlcomp = 0; + emit q->sourceChanged(); + } +} + +/*! + \qmlproperty url Loader::item + This property holds the top-level item created from source. +*/ +QFxItem *QFxLoader::item() const +{ + Q_D(const QFxLoader); + return d->item; +} + +QT_END_NAMESPACE + +#include "moc_qfxloader.cpp" diff --git a/src/declarative/fx/qfxloader.h b/src/declarative/fx/qfxloader.h new file mode 100644 index 0000000..f11d116 --- /dev/null +++ b/src/declarative/fx/qfxloader.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** 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 QFXLOADER_H +#define QFXLOADER_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QFxLoaderPrivate; +class Q_DECLARATIVE_EXPORT QFxLoader : public QFxItem +{ + Q_OBJECT + + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QFxItem *item READ item) + +public: + QFxLoader(QFxItem *parent=0); + virtual ~QFxLoader(); + + QUrl source() const; + void setSource(const QUrl &); + + QFxItem *item() const; + +Q_SIGNALS: + void sourceChanged(); + +private: + Q_DISABLE_COPY(QFxLoader) + Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxLoader) + Q_PRIVATE_SLOT(d_func(), void _q_sourceLoaded()) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QFxLoader) + +QT_END_HEADER + +#endif // QFXLOADER_H diff --git a/src/declarative/fx/qfxloader_p.h b/src/declarative/fx/qfxloader_p.h new file mode 100644 index 0000000..13f3b53 --- /dev/null +++ b/src/declarative/fx/qfxloader_p.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** 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 QFXLOADER_P_H +#define QFXLOADER_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" +#include "qfxloader.h" + +QT_BEGIN_NAMESPACE + +class QmlContext; +class QFxLoaderPrivate : public QFxItemPrivate +{ + Q_DECLARE_PUBLIC(QFxLoader) + +public: + QFxLoaderPrivate(); + ~QFxLoaderPrivate(); + + QUrl source; + QFxItem *item; + QmlComponent *qmlcomp; + QHash cachedChildren; + + void _q_sourceLoaded(); +}; + +QT_END_NAMESPACE + +#endif // QFXLOADER_P_H -- cgit v0.12