diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-07-30 23:39:53 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-07-30 23:39:53 (GMT) |
commit | 0ce2bedf9b5da9d480b994a9b812c37d1f5caa39 (patch) | |
tree | 7e8ef6069f8c669ff6e92e23cf8b46cfad7ed3ee /src | |
parent | a70f8a2b0966420e1911554a117e066592b1822c (diff) | |
download | Qt-0ce2bedf9b5da9d480b994a9b812c37d1f5caa39.zip Qt-0ce2bedf9b5da9d480b994a9b812c37d1f5caa39.tar.gz Qt-0ce2bedf9b5da9d480b994a9b812c37d1f5caa39.tar.bz2 |
Introduce Loader item.
The Loader item takes the qml/qmlItem functionality from Item and
moves it to a specialized subclass.
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/fx/fx.pri | 3 | ||||
-rw-r--r-- | src/declarative/fx/qfxitem.cpp | 146 | ||||
-rw-r--r-- | src/declarative/fx/qfxitem.h | 12 | ||||
-rw-r--r-- | src/declarative/fx/qfxitem_p.h | 9 | ||||
-rw-r--r-- | src/declarative/fx/qfxloader.cpp | 188 | ||||
-rw-r--r-- | src/declarative/fx/qfxloader.h | 85 | ||||
-rw-r--r-- | src/declarative/fx/qfxloader_p.h | 80 |
7 files changed, 359 insertions, 164 deletions
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 <QtGui/qgraphicstransform.h> #include <QtDeclarative/qmlengine.h> -#include <private/qmlengine_p.h> #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<QString, QFxItem *>::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<QString, QFxItem *>::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<d->_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<QFxItem*>(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<QFxItem *>(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<QObject *> *data READ data DESIGNABLE false) Q_PROPERTY(QmlList<QFxItem *>* children READ children DESIGNABLE false) Q_PROPERTY(QmlList<QObject *>* 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<QmlState *>* states READ states DESIGNABLE false) Q_PROPERTY(QmlList<QmlTransition *>* 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<QFxAnchors *> dependantAnchors; QFxAnchors *_anchors; QFxContents *_contents; - QFxItem *qmlItem; - QmlComponent *_qmlcomp; - QUrl _qml; - QList<QUrl> _qmlnewloading; - QList<QmlComponent*> _qmlnewcomp; QmlNullableValue<qreal> _baselineOffset; bool _componentComplete:1; bool _keepMouse:1; - QHash<QString, QFxItem *> _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 <private/qmlengine_p.h> + +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<QString, QFxItem *>::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<QString, QFxItem *>::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<QFxItem *>(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 <QtDeclarative/qfxitem.h> + +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<QString, QFxItem *> cachedChildren; + + void _q_sourceLoaded(); +}; + +QT_END_NAMESPACE + +#endif // QFXLOADER_P_H |