summaryrefslogtreecommitdiffstats
path: root/src/declarative/fx
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-09-07 06:19:33 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-09-07 06:19:33 (GMT)
commitcdc50db23a89721f793ef353fb4d64b0631456c0 (patch)
tree06f017b87a3052ddb32359b14b6ae94ca070183d /src/declarative/fx
parenteb1890d43f2abbac594f17eea047e88c3c0b529e (diff)
downloadQt-cdc50db23a89721f793ef353fb4d64b0631456c0.zip
Qt-cdc50db23a89721f793ef353fb4d64b0631456c0.tar.gz
Qt-cdc50db23a89721f793ef353fb4d64b0631456c0.tar.bz2
Add status and progress properties to Loader.
Diffstat (limited to 'src/declarative/fx')
-rw-r--r--src/declarative/fx/qfxloader.cpp65
-rw-r--r--src/declarative/fx/qfxloader.h13
2 files changed, 74 insertions, 4 deletions
diff --git a/src/declarative/fx/qfxloader.cpp b/src/declarative/fx/qfxloader.cpp
index 95ddae3..869a5b0 100644
--- a/src/declarative/fx/qfxloader.cpp
+++ b/src/declarative/fx/qfxloader.cpp
@@ -111,9 +111,12 @@ void QFxLoader::setSource(const QUrl &url)
d->source = url;
d->item = 0;
+ emit itemChanged();
if (d->source.isEmpty()) {
emit sourceChanged();
+ emit statusChanged();
+ emit progressChanged();
return;
}
@@ -122,14 +125,22 @@ void QFxLoader::setSource(const QUrl &url)
(*iter)->setOpacity(1.);
d->item = (*iter);
emit sourceChanged();
+ emit statusChanged();
+ emit progressChanged();
+ emit itemChanged();
} else {
d->qmlcomp =
new QmlComponent(qmlEngine(this), d->source, this);
- if (!d->qmlcomp->isLoading())
+ if (!d->qmlcomp->isLoading()) {
d->_q_sourceLoaded();
- else
+ } 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();
+ }
}
}
@@ -146,6 +157,8 @@ void QFxLoaderPrivate::_q_sourceLoaded()
delete qmlcomp;
qmlcomp = 0;
emit q->sourceChanged();
+ emit q->statusChanged();
+ emit q->progressChanged();
return;
}
QObject *obj = qmlcomp->create(ctxt);
@@ -163,10 +176,58 @@ void QFxLoaderPrivate::_q_sourceLoaded()
delete qmlcomp;
qmlcomp = 0;
emit q->sourceChanged();
+ emit q->statusChanged();
+ emit q->progressChanged();
+ emit q->itemChanged();
}
}
/*!
+ \qmlproperty enum Loader::status
+
+ This property holds the status of QML loading. It can be one of:
+ \list
+ \o Null - no QML source has been set
+ \o Ready - the QML source has been loaded
+ \o Loading - the QML source is currently being loaded
+ \o Error - an error occurred while loading the QML source
+ \endlist
+
+ \sa progress
+*/
+
+/*!
+ \qmlproperty real Loader::progress
+
+ This property holds the progress of QML data loading, from 0.0 (nothing loaded)
+ to 1.0 (finished).
+
+ \sa status
+*/
+QFxLoader::Status QFxLoader::status() const
+{
+ Q_D(const QFxLoader);
+
+ if (d->qmlcomp)
+ return static_cast<QFxLoader::Status>(d->qmlcomp->status());
+
+ if (d->item)
+ return Ready;
+
+ return d->source.isEmpty() ? Null : Error;
+}
+
+qreal QFxLoader::progress() const
+{
+ Q_D(const QFxLoader);
+
+ if (d->qmlcomp)
+ return d->qmlcomp->progress();
+
+ return d->item ? 1.0 : 0.0;
+}
+
+/*!
\qmlproperty Item Loader::item
This property holds the top-level item created from source.
*/
diff --git a/src/declarative/fx/qfxloader.h b/src/declarative/fx/qfxloader.h
index 8c555c6..132c8f4 100644
--- a/src/declarative/fx/qfxloader.h
+++ b/src/declarative/fx/qfxloader.h
@@ -54,12 +54,14 @@ class QFxLoaderPrivate;
class Q_DECLARATIVE_EXPORT QFxLoader : public QFxItem
{
Q_OBJECT
+ Q_ENUMS(Status)
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
- Q_PROPERTY(QFxItem *item READ item) //### NOTIFY itemChanged
+ 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
- //### status, progress
//### resizeMode { NoResize, SizeLoaderToItem (default), SizeItemToLoader }
public:
@@ -69,10 +71,17 @@ public:
QUrl source() const;
void setSource(const QUrl &);
+ enum Status { Null, Ready, Loading, Error };
+ Status status() const;
+ qreal progress() const;
+
QFxItem *item() const;
Q_SIGNALS:
+ void itemChanged();
void sourceChanged();
+ void statusChanged();
+ void progressChanged();
private:
Q_DISABLE_COPY(QFxLoader)