summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-10-14 04:38:29 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-10-14 04:38:29 (GMT)
commit9410f4b0e9aa3ce310c65f24c60576ce7317f88d (patch)
tree01a1f00025083124657e722e82776ff627b75507 /src
parent1db61e89cb96022a6f5bffdc698f1f4dd4400b68 (diff)
parent513cc4be0bec4a5fb303062ecbecf87708dc0e9b (diff)
downloadQt-9410f4b0e9aa3ce310c65f24c60576ce7317f88d.zip
Qt-9410f4b0e9aa3ce310c65f24c60576ce7317f88d.tar.gz
Qt-9410f4b0e9aa3ce310c65f24c60576ce7317f88d.tar.bz2
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src')
-rw-r--r--src/declarative/extra/qmlfontloader.cpp14
-rw-r--r--src/declarative/fx/qfxborderimage.cpp14
-rw-r--r--src/declarative/fx/qfxpixmapcache.cpp18
-rw-r--r--src/declarative/qml/qmlcomponent.cpp65
-rw-r--r--src/declarative/qml/qmlcomponent.h3
-rw-r--r--src/declarative/qml/qmlcomponent_p.h21
-rw-r--r--src/declarative/qml/qmlcompositetypemanager.cpp18
-rw-r--r--src/declarative/qml/qmlengine.cpp17
-rw-r--r--src/declarative/qml/qmlengine_p.h2
9 files changed, 155 insertions, 17 deletions
diff --git a/src/declarative/extra/qmlfontloader.cpp b/src/declarative/extra/qmlfontloader.cpp
index 66c8567..4a447de 100644
--- a/src/declarative/extra/qmlfontloader.cpp
+++ b/src/declarative/extra/qmlfontloader.cpp
@@ -92,6 +92,15 @@ QmlFontLoader::~QmlFontLoader()
{
}
+static QString toLocalFileOrQrc(const QUrl& url)
+{
+ QString r = url.toLocalFile();
+ if (r.isEmpty() && url.scheme() == QLatin1String("qrc"))
+ r = QLatin1Char(':') + url.path();
+ return r;
+}
+
+
/*!
\qmlproperty url FontLoader::source
The url of the font to load.
@@ -112,8 +121,9 @@ void QmlFontLoader::setSource(const QUrl &url)
d->status = Loading;
emit statusChanged();
#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
- if (d->url.scheme() == QLatin1String("file")) {
- QFile file(d->url.toLocalFile());
+ QString lf = toLocalFileOrQrc(d->url);
+ if (!lf.isEmpty()) {
+ QFile file(lf);
file.open(QIODevice::ReadOnly);
QByteArray ba = file.readAll();
d->addFontToDatabase(ba);
diff --git a/src/declarative/fx/qfxborderimage.cpp b/src/declarative/fx/qfxborderimage.cpp
index 8f98a11..f1574e5 100644
--- a/src/declarative/fx/qfxborderimage.cpp
+++ b/src/declarative/fx/qfxborderimage.cpp
@@ -138,6 +138,15 @@ QFxBorderImage::~QFxBorderImage()
The URL may be absolute, or relative to the URL of the component.
*/
+static QString toLocalFileOrQrc(const QUrl& url)
+{
+ QString r = url.toLocalFile();
+ if (r.isEmpty() && url.scheme() == QLatin1String("qrc"))
+ r = QLatin1Char(':') + url.path();
+ return r;
+}
+
+
void QFxBorderImage::setSource(const QUrl &url)
{
Q_D(QFxBorderImage);
@@ -180,8 +189,9 @@ void QFxBorderImage::setSource(const QUrl &url)
d->status = Loading;
if (d->url.path().endsWith(QLatin1String(".sci"))) {
#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
- if (d->url.scheme() == QLatin1String("file")) {
- QFile file(d->url.toLocalFile());
+ QString lf = toLocalFileOrQrc(d->url);
+ if (!lf.isEmpty()) {
+ QFile file(lf);
file.open(QIODevice::ReadOnly);
setGridScaledImage(QFxGridScaledImage(&file));
} else
diff --git a/src/declarative/fx/qfxpixmapcache.cpp b/src/declarative/fx/qfxpixmapcache.cpp
index 80b5011..13e1b16 100644
--- a/src/declarative/fx/qfxpixmapcache.cpp
+++ b/src/declarative/fx/qfxpixmapcache.cpp
@@ -124,6 +124,14 @@ static bool readImage(QIODevice *dev, QPixmap *pixmap)
This class is NOT reentrant.
*/
+static QString toLocalFileOrQrc(const QUrl& url)
+{
+ QString r = url.toLocalFile();
+ if (r.isEmpty() && url.scheme() == QLatin1String("qrc"))
+ r = QLatin1Char(':') + url.path();
+ return r;
+}
+
/*!
Finds the cached pixmap corresponding to \a url.
A previous call to get() must have requested the URL,
@@ -142,8 +150,9 @@ bool QFxPixmapCache::find(const QUrl& url, QPixmap *pixmap)
bool ok = true;
if (!QPixmapCache::find(key,pixmap)) {
#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
- if (url.scheme()==QLatin1String("file")) {
- QFile f(url.toLocalFile());
+ QString lf = toLocalFileOrQrc(url);
+ if (!lf.isEmpty()) {
+ QFile f(lf);
if (f.open(QIODevice::ReadOnly)) {
if (!readImage(&f, pixmap)) {
qWarning() << "Format error loading" << url;
@@ -207,10 +216,11 @@ bool QFxPixmapCache::find(const QUrl& url, QPixmap *pixmap)
QNetworkReply *QFxPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap *pixmap)
{
#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
- if (url.scheme()==QLatin1String("file")) {
+ QString lf = toLocalFileOrQrc(url);
+ if (!lf.isEmpty()) {
QString key = url.toString();
if (!QPixmapCache::find(key,pixmap)) {
- QFile f(url.toLocalFile());
+ QFile f(lf);
if (f.open(QIODevice::ReadOnly)) {
if (!readImage(&f, pixmap)) {
qWarning() << "Format error loading" << url;
diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp
index 9a761b2..dc71989 100644
--- a/src/declarative/qml/qmlcomponent.cpp
+++ b/src/declarative/qml/qmlcomponent.cpp
@@ -95,6 +95,27 @@ Item {
Loader { sourceComponent: RedSquare; x: 20 }
}
\endqml
+
+ \section1 Attached Properties
+
+ \e onCompleted
+
+ Emitted after component "startup" has completed. This can be used to
+ execute script code at startup, once the full QML environment has been
+ established.
+
+ The \c {Component::onCompleted} attached property can be applied to
+ any element. The order of running the \c onCompleted scripts is
+ undefined.
+
+ \qml
+ Rectangle {
+ Component.onCompleted: print("Completed Running!")
+ Rectangle {
+ Component.onCompleted: print("Nested Completed Running!")
+ }
+ }
+ \endqml
*/
QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Component,QmlComponent);
@@ -532,6 +553,11 @@ QmlComponentPrivate::beginCreate(QmlContext *context, const QBitField &bindings)
bindValues = ep->bindValues;
parserStatus = ep->parserStatus;
+ componentAttacheds = ep->componentAttacheds;
+ if (componentAttacheds)
+ componentAttacheds->prev = &componentAttacheds;
+
+ ep->componentAttacheds = 0;
ep->bindValues.clear();
ep->parserStatus.clear();
completePending = true;
@@ -593,10 +619,49 @@ void QmlComponentPrivate::completeCreate()
QmlEnginePrivate::clear(ps);
}
+ while (componentAttacheds) {
+ QmlComponentAttached *a = componentAttacheds;
+ if (a->next) a->next->prev = &componentAttacheds;
+ componentAttacheds = a->next;
+ a->prev = 0; a->next = 0;
+ emit a->completed();
+ }
+
bindValues.clear();
parserStatus.clear();
completePending = false;
}
}
+QmlComponentAttached::QmlComponentAttached(QObject *parent)
+: QObject(parent), prev(0), next(0)
+{
+}
+
+QmlComponentAttached::~QmlComponentAttached()
+{
+ if (prev) *prev = next;
+ if (next) next->prev = prev;
+ prev = 0;
+ next = 0;
+}
+
+QmlComponentAttached *QmlComponent::qmlAttachedProperties(QObject *obj)
+{
+ QmlComponentAttached *a = new QmlComponentAttached(obj);
+
+ QmlEngine *engine = qmlEngine(obj);
+ if (!engine || !QmlEnginePrivate::get(engine)->rootComponent)
+ return a;
+
+ QmlEnginePrivate *p = QmlEnginePrivate::get(engine);
+
+ a->next = p->componentAttacheds;
+ a->prev = &p->componentAttacheds;
+ if (a->next) a->next->prev = &a->next;
+ p->componentAttacheds = a;
+
+ return a;
+}
+
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlcomponent.h b/src/declarative/qml/qmlcomponent.h
index c6924e3..dcf9347 100644
--- a/src/declarative/qml/qmlcomponent.h
+++ b/src/declarative/qml/qmlcomponent.h
@@ -59,6 +59,7 @@ class QmlCompiledData;
class QByteArray;
class QmlComponentPrivate;
class QmlEngine;
+class QmlComponentAttached;
class Q_DECLARATIVE_EXPORT QmlComponent : public QObject
{
Q_OBJECT
@@ -95,6 +96,8 @@ public:
void loadUrl(const QUrl &url);
void setData(const QByteArray &, const QUrl &baseUrl);
+ static QmlComponentAttached *qmlAttachedProperties(QObject *);
+
Q_SIGNALS:
void statusChanged(QmlComponent::Status);
void progressChanged(qreal);
diff --git a/src/declarative/qml/qmlcomponent_p.h b/src/declarative/qml/qmlcomponent_p.h
index 2d0c77f..7eedfbd 100644
--- a/src/declarative/qml/qmlcomponent_p.h
+++ b/src/declarative/qml/qmlcomponent_p.h
@@ -70,12 +70,13 @@ class QmlComponent;
class QmlEngine;
class QmlCompiledData;
+class QmlComponentAttached;
class QmlComponentPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QmlComponent)
public:
- QmlComponentPrivate() : typeData(0), progress(0.), start(-1), count(-1), cc(0), completePending(false), engine(0) {}
+ QmlComponentPrivate() : typeData(0), progress(0.), start(-1), count(-1), cc(0), completePending(false), componentAttacheds(0), engine(0) {}
QObject *create(QmlContext *context, const QBitField &);
@@ -98,6 +99,7 @@ public:
QList<QmlEnginePrivate::SimpleList<QmlAbstractBinding> > bindValues;
QList<QmlEnginePrivate::SimpleList<QmlParserStatus> > parserStatus;
+ QmlComponentAttached *componentAttacheds;
bool completePending;
@@ -110,6 +112,23 @@ public:
}
};
+class QmlComponentAttached : public QObject
+{
+ Q_OBJECT
+public:
+ QmlComponentAttached(QObject *parent = 0);
+ ~QmlComponentAttached();
+
+ QmlComponentAttached **prev;
+ QmlComponentAttached *next;
+
+signals:
+ void completed();
+
+private:
+ friend class QmlComponentPrivate;
+};
+
QT_END_NAMESPACE
#endif // QMLCOMPONENT_P_H
diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp
index 13bd02c..3c76344 100644
--- a/src/declarative/qml/qmlcompositetypemanager.cpp
+++ b/src/declarative/qml/qmlcompositetypemanager.cpp
@@ -262,13 +262,22 @@ void QmlCompositeTypeManager::resourceReplyFinished()
reply->deleteLater();
}
+static QString toLocalFileOrQrc(const QUrl& url)
+{
+ QString r = url.toLocalFile();
+ if (r.isEmpty() && url.scheme() == QLatin1String("qrc"))
+ r = QLatin1Char(':') + url.path();
+ return r;
+}
+
void QmlCompositeTypeManager::loadResource(QmlCompositeTypeResource *resource)
{
QUrl url(resource->url);
- if (url.scheme() == QLatin1String("file")) {
+ QString lf = toLocalFileOrQrc(url);
+ if (!lf.isEmpty()) {
- QFile file(url.toLocalFile());
+ QFile file(lf);
if (file.open(QFile::ReadOnly)) {
resource->data = file.readAll();
resource->status = QmlCompositeTypeResource::Complete;
@@ -290,9 +299,10 @@ void QmlCompositeTypeManager::loadSource(QmlCompositeTypeData *unit)
{
QUrl url(unit->imports.baseUrl());
- if (url.scheme() == QLatin1String("file")) {
+ QString lf = toLocalFileOrQrc(url);
+ if (!lf.isEmpty()) {
- QFile file(url.toLocalFile());
+ QFile file(lf);
if (file.open(QFile::ReadOnly)) {
QByteArray data = file.readAll();
setData(unit, data, url);
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index ef0f975..d5f64c2 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -125,8 +125,8 @@ static QString userLocalDataPath(const QString& app)
QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e)
: rootContext(0), currentExpression(0),
isDebugging(false), contextClass(0), objectClass(0), valueTypeClass(0), globalClass(0),
- nodeListClass(0), namedNodeMapClass(0), sqlQueryClass(0), scriptEngine(this), rootComponent(0),
- networkAccessManager(0), typeManager(e), uniqueId(1)
+ nodeListClass(0), namedNodeMapClass(0), sqlQueryClass(0), scriptEngine(this),
+ componentAttacheds(0), rootComponent(0), networkAccessManager(0), typeManager(e), uniqueId(1)
{
QScriptValue qtObject =
scriptEngine.newQMetaObject(StaticQtMetaObject::get());
@@ -955,6 +955,15 @@ QVariant QmlScriptClass::toVariant(QmlEngine *engine, const QScriptValue &val)
return QVariant();
}
+// XXX this beyonds in QUrl::toLocalFile()
+static QString toLocalFileOrQrc(const QUrl& url)
+{
+ QString r = url.toLocalFile();
+ if (r.isEmpty() && url.scheme() == QLatin1String("qrc"))
+ r = QLatin1Char(':') + url.path();
+ return r;
+}
+
/////////////////////////////////////////////////////////////
struct QmlEnginePrivate::ImportedNamespace {
QStringList urls;
@@ -985,7 +994,7 @@ struct QmlEnginePrivate::ImportedNamespace {
QUrl url = QUrl(urls.at(i) + QLatin1String("/") + QString::fromUtf8(type) + QLatin1String(".qml"));
if (vmaj || vmin) {
// Check version file - XXX cache these in QmlEngine!
- QFile qmldir(QUrl(urls.at(i)+QLatin1String("/qmldir")).toLocalFile());
+ QFile qmldir(toLocalFileOrQrc(QUrl(urls.at(i)+QLatin1String("/qmldir"))));
if (qmldir.open(QIODevice::ReadOnly)) {
do {
QByteArray lineba = qmldir.readLine();
@@ -1016,7 +1025,7 @@ struct QmlEnginePrivate::ImportedNamespace {
}
} else {
// XXX search non-files too! (eg. zip files, see QT-524)
- QFileInfo f(url.toLocalFile());
+ QFileInfo f(toLocalFileOrQrc(url));
if (f.exists()) {
if (url_return)
*url_return = url;
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index 7978023..4c90a80 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -95,6 +95,7 @@ class QmlAbstractBinding;
class QScriptDeclarativeClass;
class QmlTypeNameScriptClass;
class QmlTypeNameCache;
+class QmlComponentAttached;
class QmlEnginePrivate : public QObjectPrivate
{
@@ -174,6 +175,7 @@ public:
QList<SimpleList<QmlAbstractBinding> > bindValues;
QList<SimpleList<QmlParserStatus> > parserStatus;
+ QmlComponentAttached *componentAttacheds;
QmlComponent *rootComponent;
mutable QNetworkAccessManager *networkAccessManager;