From 678c4bc25da24def57d57f9c94d4163320f5e67c Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Mon, 24 Aug 2009 13:54:07 +1000 Subject: Centralize QNetworkRequest attribute setting, turn on pipelining. ... in two places. Qt expects the "application" to configure caching, proxy, pipelining, etc., on a QNetworkAccessManager, so now we do that in the two most important cases: the loader example and qmlviewer tool. --- examples/declarative/loader/loader.pro | 2 +- examples/declarative/loader/main.cpp | 23 +++++++++++++++++++++++ src/declarative/extra/qfxanimatedimageitem.cpp | 1 - src/declarative/extra/qmlfontloader.cpp | 1 - src/declarative/extra/qmlxmllistmodel.cpp | 1 - src/declarative/fx/qfxborderimage.cpp | 1 - src/declarative/fx/qfxpixmapcache.cpp | 1 - src/declarative/util/qmlscript.cpp | 1 - tools/qmlviewer/qmlviewer.cpp | 16 +++++++++++++++- 9 files changed, 39 insertions(+), 8 deletions(-) diff --git a/examples/declarative/loader/loader.pro b/examples/declarative/loader/loader.pro index baa5b8c..089eaff 100644 --- a/examples/declarative/loader/loader.pro +++ b/examples/declarative/loader/loader.pro @@ -1,7 +1,7 @@ SOURCES = main.cpp RESOURCES = loader.qrc -QT += script declarative +QT += script declarative network target.path = $$[QT_INSTALL_EXAMPLES]/declarative/loader sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS loader.pro diff --git a/examples/declarative/loader/main.cpp b/examples/declarative/loader/main.cpp index d018181..68f20d4 100644 --- a/examples/declarative/loader/main.cpp +++ b/examples/declarative/loader/main.cpp @@ -10,8 +10,11 @@ #include #include #include +#include #include #include +#include +#include QFxView *canvas = 0; @@ -148,6 +151,24 @@ public slots: } }; +class ConfiguredNetworkAccessManager : public QNetworkAccessManager { +public: + ConfiguredNetworkAccessManager() + { + QNetworkDiskCache *cache = new QNetworkDiskCache; + cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-loader-network-cache")); + setCache(cache); + } + + QNetworkReply *createRequest (Operation op, const QNetworkRequest &req, QIODevice * outgoingData) + { + QNetworkRequest request = req; + request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); + request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); + return QNetworkAccessManager::createRequest(op,request,outgoingData); + } +}; + int main(int argc, char *argv[]) { @@ -162,6 +183,8 @@ int main(int argc, char *argv[]) canvas = new QFxView; canvas->setFocusPolicy(Qt::StrongFocus); + canvas->engine()->setNetworkAccessManager(new ConfiguredNetworkAccessManager); + mw->setCentralWidget(canvas); QMenuBar *mb = mw->menuBar(); diff --git a/src/declarative/extra/qfxanimatedimageitem.cpp b/src/declarative/extra/qfxanimatedimageitem.cpp index d366111..5a491e0 100644 --- a/src/declarative/extra/qfxanimatedimageitem.cpp +++ b/src/declarative/extra/qfxanimatedimageitem.cpp @@ -201,7 +201,6 @@ void QFxAnimatedImageItem::setSource(const QUrl &url) } else { d->status = Loading; QNetworkRequest req(d->url); - req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); d->reply = qmlContext(this)->engine()->networkAccessManager()->get(req); QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(movieRequestFinished())); diff --git a/src/declarative/extra/qmlfontloader.cpp b/src/declarative/extra/qmlfontloader.cpp index 2f54f24..5373d02 100644 --- a/src/declarative/extra/qmlfontloader.cpp +++ b/src/declarative/extra/qmlfontloader.cpp @@ -121,7 +121,6 @@ void QmlFontLoader::setSource(const QUrl &url) #endif { QNetworkRequest req(d->url); - req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); d->reply = qmlEngine(this)->networkAccessManager()->get(req); QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(replyFinished())); } diff --git a/src/declarative/extra/qmlxmllistmodel.cpp b/src/declarative/extra/qmlxmllistmodel.cpp index 077e9a9..9b74799 100644 --- a/src/declarative/extra/qmlxmllistmodel.cpp +++ b/src/declarative/extra/qmlxmllistmodel.cpp @@ -605,7 +605,6 @@ void QmlXmlListModel::reload() emit statusChanged(d->status); QNetworkRequest req(d->src); - req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); d->reply = qmlContext(this)->engine()->networkAccessManager()->get(req); QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(requestFinished())); QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), diff --git a/src/declarative/fx/qfxborderimage.cpp b/src/declarative/fx/qfxborderimage.cpp index 16677e0..60faa84 100644 --- a/src/declarative/fx/qfxborderimage.cpp +++ b/src/declarative/fx/qfxborderimage.cpp @@ -187,7 +187,6 @@ void QFxBorderImage::setSource(const QUrl &url) #endif { QNetworkRequest req(d->url); - req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); d->sciReply = qmlEngine(this)->networkAccessManager()->get(req); QObject::connect(d->sciReply, SIGNAL(finished()), this, SLOT(sciRequestFinished())); diff --git a/src/declarative/fx/qfxpixmapcache.cpp b/src/declarative/fx/qfxpixmapcache.cpp index 0ca77c3..7fc713b 100644 --- a/src/declarative/fx/qfxpixmapcache.cpp +++ b/src/declarative/fx/qfxpixmapcache.cpp @@ -218,7 +218,6 @@ QNetworkReply *QFxPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap * QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); if (iter == qfxActiveNetworkReplies.end()) { QNetworkRequest req(url); - req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); QSharedNetworkReply *item = new QSharedNetworkReply(engine->networkAccessManager()->get(req)); iter = qfxActiveNetworkReplies.insert(key, item); } else { diff --git a/src/declarative/util/qmlscript.cpp b/src/declarative/util/qmlscript.cpp index 0bff047..de2128d 100644 --- a/src/declarative/util/qmlscript.cpp +++ b/src/declarative/util/qmlscript.cpp @@ -151,7 +151,6 @@ void QmlScript::setSource(const QUrl &source) #endif { QNetworkRequest req(d->url); - req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); d->reply = qmlEngine(this)->networkAccessManager()->get(req); QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(replyFinished())); diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp index ae61fd0..272ebcb 100644 --- a/tools/qmlviewer/qmlviewer.cpp +++ b/tools/qmlviewer/qmlviewer.cpp @@ -191,6 +191,19 @@ private: QString customargs; }; +class ConfiguredNetworkAccessManager : public QNetworkAccessManager { +public: + ConfiguredNetworkAccessManager() { } + + QNetworkReply *createRequest (Operation op, const QNetworkRequest &req, QIODevice * outgoingData) + { + QNetworkRequest request = req; + request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); + request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); + return QNetworkAccessManager::createRequest(op,request,outgoingData); + } +}; + QString QmlViewer::getVideoFileName() { QString title = convertAvailable || ffmpegAvailable ? tr("Save Video File") : tr("Save PNG Frames"); @@ -240,6 +253,7 @@ QmlViewer::QmlViewer(QWidget *parent, Qt::WindowFlags flags) canvas->setAttribute(Qt::WA_OpaquePaintEvent); canvas->setAttribute(Qt::WA_NoSystemBackground); canvas->setContentResizable(!skin || !scaleSkin); + canvas->engine()->setNetworkAccessManager(new ConfiguredNetworkAccessManager); canvas->setFocus(); QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); @@ -966,7 +980,7 @@ void QmlViewer::setupProxy() else proxyFactory->unsetHttpProxy(); nam->setProxyFactory(proxyFactory); - } +} void QmlViewer::setNetworkCacheSize(int size) { -- cgit v0.12 From de6b4c941146d0286e98a6f35ac5a609381e17ee Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 24 Aug 2009 14:51:12 +1000 Subject: Add missing CONSTANT to view property. --- src/declarative/fx/qfxlistview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index b6301f6..04fc3bd 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -59,7 +59,7 @@ public: attachedProperties.remove(parent()); } - Q_PROPERTY(QFxListView *view READ view) + Q_PROPERTY(QFxListView *view READ view CONSTANT) QFxListView *view() { return m_view; } Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged) -- cgit v0.12 From 4ec82624f77d49c2e5f02b04518c8bde1be16145 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Mon, 24 Aug 2009 14:55:16 +1000 Subject: Use 'extend' for now. 'extends' is a JavaScript reserved words --- src/declarative/util/qmlstate.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/declarative/util/qmlstate.h b/src/declarative/util/qmlstate.h index d15bd4a..0b48449 100644 --- a/src/declarative/util/qmlstate.h +++ b/src/declarative/util/qmlstate.h @@ -81,7 +81,7 @@ public: void deleteFromBinding(); }; -class ActionEvent +class ActionEvent { public: virtual ~ActionEvent(); @@ -126,7 +126,7 @@ class Q_DECLARATIVE_EXPORT QmlState : public QObject Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QmlBinding *when READ when WRITE setWhen) - Q_PROPERTY(QString extends READ extends WRITE setExtends) + Q_PROPERTY(QString extend READ extends WRITE setExtends) Q_PROPERTY(QmlList* changes READ changes) Q_CLASSINFO("DefaultProperty", "changes") @@ -137,7 +137,7 @@ public: QString name() const; void setName(const QString &); - /*'when' is a QmlBinding to limit state changes oscillation + /*'when' is a QmlBinding to limit state changes oscillation due to the unpredictable order of evaluation of bound expressions*/ bool isWhenKnown() const; QmlBinding *when() const; -- cgit v0.12 From d4c67f5293c0a6c7d7b586a401e1972b964d0c16 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 24 Aug 2009 11:58:43 +0200 Subject: Silence gcc compiler error --- src/declarative/qml/qmldom.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp index 2aaf492..9e12485 100644 --- a/src/declarative/qml/qmldom.cpp +++ b/src/declarative/qml/qmldom.cpp @@ -765,8 +765,11 @@ Text { id: MyText } */ QString QmlDomObject::objectId() const { - if (d->object) return d->object->id; - else return QByteArray(); + if (d->object) { + return d->object->id; + } else { + return QString(); + } } /*! -- cgit v0.12 From f7a3ece15715bea8c8588aa0682e6f798a533cab Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 25 Aug 2009 09:44:27 +1000 Subject: Largely revert 40c12237b506bd and implement simpler more efficient way. Still doubtful that ACTUAL version import is needed. --- src/declarative/qml/qmlcompiler.cpp | 2 +- src/declarative/qml/qmlcompositetypemanager.cpp | 26 ++--- src/declarative/qml/qmlengine.cpp | 128 ++++++------------------ src/declarative/qml/qmlengine_p.h | 20 +--- src/declarative/qml/qmlmetaproperty.cpp | 2 +- 5 files changed, 43 insertions(+), 135 deletions(-) diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 1771cb4..ad63b5b 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -1176,7 +1176,7 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, } QmlType *type = 0; - QmlEnginePrivate::get(engine)->resolveType(unit->imports, prop->name, &type, 0); + QmlEnginePrivate::get(engine)->resolveType(unit->imports, prop->name, &type, 0, 0, 0); // 0: attached properties not supported in QML component files if (!type || !type->attachedPropertiesType()) diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index 5bf2dc0..46ce857 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -327,26 +327,18 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) } QUrl url; - QmlEnginePrivate::ImportedNamespace *s; - QByteArray localTypeName; - - QmlEnginePrivate::get(engine)->resolveNamespace(unit->imports, typeName, &s, &localTypeName); - if (QmlEnginePrivate::get(engine)->resolveTypeInNamespace(s, localTypeName, &ref.type, &url)) { - int majorVersion; - int minorVersion; - if (s->getTypeInfo(localTypeName, 0, &majorVersion, &minorVersion)) { - foreach (QmlParser::Object *obj, parserRef->refObjects) { - // store namespace for DOM - obj->majorVersion = majorVersion; - obj->minorVersion = minorVersion; - } - } - } else { - // try base url - url = unit->imports.baseUrl().resolved(QUrl(QLatin1String(typeName + ".qml"))); + int majorVersion; + int minorVersion; + if (!QmlEnginePrivate::get(engine)->resolveType(unit->imports, typeName, &ref.type, &url, &majorVersion, &minorVersion)) { + // XXX could produce error message here. } if (ref.type) { + foreach (QmlParser::Object *obj, parserRef->refObjects) { + // store namespace for DOM + obj->majorVersion = majorVersion; + obj->minorVersion = minorVersion; + } unit->types << ref; continue; } diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index fd18b26..b3e08ea 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -1072,7 +1072,7 @@ void QmlObjectScriptClass::setProperty(QScriptValue &object, } -struct QmlImportedNamespacePrivate { +struct QmlEnginePrivate::ImportedNamespace { QStringList urls; QList majversions; QList minversions; @@ -1122,7 +1122,7 @@ struct QmlImportedNamespacePrivate { return QUrl(); } - QmlType *findBuiltin(const QByteArray& type, QByteArray* found=0) const + QmlType *findBuiltin(const QByteArray& type, int *vmajor, int *vminor) const { for (int i=0; id->urls.append(url); - s->d->majversions.append(vmaj); - s->d->minversions.append(vmin); - s->d->isLibrary.append(importType == QmlScriptParser::Import::Library); + s->urls.append(url); + s->majversions.append(vmaj); + s->minversions.append(vmin); + s->isLibrary.append(importType == QmlScriptParser::Import::Library); return true; } @@ -1202,13 +1203,13 @@ public: } QString unqualifiedtype = type.mid(slash+1); if (s) - return s->d->find(unqualifiedtype); + return s->find(unqualifiedtype); else return QUrl(); } - QmlType *findBuiltin(const QByteArray& type, QByteArray* found=0) + QmlType *findBuiltin(const QByteArray& type, int *vmajor, int *vminor) { QmlEnginePrivate::ImportedNamespace *s = 0; int slash = type.indexOf('/'); @@ -1226,37 +1227,16 @@ public: } QByteArray unqualifiedtype = slash < 0 ? type : type.mid(slash+1); // common-case opt (QString::mid works fine, but slower) if (s) - return s->d->findBuiltin(unqualifiedtype,found); + return s->findBuiltin(unqualifiedtype,vmajor,vminor); else return 0; - } + } QmlEnginePrivate::ImportedNamespace *findNamespace(const QString& type) { return set.value(type); } - void resolveNamespace(const QByteArray &type, QmlEnginePrivate::ImportedNamespace **ns, QByteArray *unqualifiedType) - { - QmlEnginePrivate::ImportedNamespace *s = 0; - int slash = type.indexOf('/'); - if (slash >= 0) { - while (!s) { - s = set.value(QString::fromLatin1(type.left(slash))); - int nslash = type.indexOf('/',slash+1); - if (nslash > 0) - slash = nslash; - else - break; - } - } else { - s = &unqualifiedset; - } - - *ns = s; - *unqualifiedType = slash < 0 ? type : type.mid(slash+1); // common-case opt (QString::mid works fine, but slower) - } - private: QmlEnginePrivate::ImportedNamespace unqualifiedset; QHash set; @@ -1279,37 +1259,6 @@ void QmlEnginePrivate::Imports::setBaseUrl(const QUrl& url) base = url; } -QmlEnginePrivate::ImportedNamespace::ImportedNamespace() - : d(new QmlImportedNamespacePrivate) -{ -} - -QmlEnginePrivate::ImportedNamespace::~ImportedNamespace() -{ - delete d; -} - -bool QmlEnginePrivate::ImportedNamespace::getTypeInfo(const QByteArray &typeName, QString *uri, int *majorVersion, int *minorVersion) -{ - for (int i=0; iurls.count(); ++i) { - int vmaj = d->majversions.at(i); - int vmin = d->minversions.at(i); - QByteArray qt = d->urls.at(i).toLatin1(); - qt += "/"; - qt += typeName; - if (QmlMetaType::qmlType(qt,vmaj,vmin)) { - if (uri) - *uri = d->urls.at(i); - if (majorVersion) - *majorVersion = d->majversions.at(i); - if (minorVersion) - *minorVersion = d->minversions.at(i); - return true; - } - } - return false; -} - /*! Adds \a path as a directory where installed QML components are defined in a URL-based directory structure. @@ -1362,11 +1311,21 @@ bool QmlEnginePrivate::addToImport(Imports* imports, const QString& uri, const Q \sa addToImport() */ -bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& type, QmlType** type_return, QUrl* url_return, ImportedNamespace** ns_return) const +bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& type, QmlType** type_return, QUrl* url_return, int *vmaj, int *vmin, ImportedNamespace** ns_return) const { + if (ns_return) { + *ns_return = imports.d->findNamespace(QLatin1String(type)); + if (*ns_return) + return true; + } if (type_return) { - QmlType* t = imports.d->findBuiltin(type); - if (!t) t = QmlMetaType::qmlType(type,0,0); // Try global namespace + QmlType* t = imports.d->findBuiltin(type,vmaj,vmin); + if (!t) { + // XXX do we really still need this? + t = QmlMetaType::qmlType(type,0,0); // Try global namespace + if (vmin) *vmin = 0; + if (vmaj) *vmaj = 0; + } if (t) { if (type_return) *type_return = t; if (qmlImportTrace()) @@ -1386,11 +1345,6 @@ bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& typ return true; } } - if (ns_return) { - *ns_return = imports.d->findNamespace(QLatin1String(type)); - if (*ns_return) - return true; - } if (qmlImportTrace()) qDebug() << "QmlEngine::resolveType" << type << " not found"; return false; @@ -1399,16 +1353,6 @@ bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& typ /*! \internal - Splits a fully qualified type name into the namespace and the unqualified type name. -*/ -void QmlEnginePrivate::resolveNamespace(const Imports& imports, const QByteArray &type, ImportedNamespace **ns, QByteArray *unqualifiedType) const -{ - imports.d->resolveNamespace(type, ns, unqualifiedType); -} - -/*! - \internal - Searching \e only in the namespace \a ns (previously returned in a call to resolveType(), \a type is found and returned to either a QmlType stored at \a type_return, or @@ -1416,31 +1360,17 @@ void QmlEnginePrivate::resolveNamespace(const Imports& imports, const QByteArray If either return pointer is 0, the corresponding search is not done. */ -bool QmlEnginePrivate::resolveTypeInNamespace(ImportedNamespace* ns, const QByteArray& type, QmlType** type_return, QUrl* url_return ) const +void QmlEnginePrivate::resolveTypeInNamespace(ImportedNamespace* ns, const QByteArray& type, QmlType** type_return, QUrl* url_return, int *vmaj, int *vmin ) const { if (!ns) - return false; + return; if (type_return) { - QmlType* t = ns->d->findBuiltin(type); - if (!t) t = QmlMetaType::qmlType(type,0,0); // Try global namespace - if (t) { - *type_return = t; - if (qmlImportTrace()) - qDebug() << "QmlEngine::resolveTypeInNamespace" << type << "= (builtin)"; - return true; - } + *type_return = ns->findBuiltin(type,vmaj,vmin); } if (url_return) { - QUrl url = ns->d->find(QLatin1String(type)); - if (url.isValid()) { - if (url_return) *url_return = url; - if (qmlImportTrace()) - qDebug() << "QmlEngine::resolveType" << type << "=" << url; - return true; - } + *url_return = ns->find(QLatin1String(type)); } - return false; } QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index c84b3b5..4be5a98 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -195,24 +195,10 @@ public: QUrl base; QmlImportsPrivate *d; }; - - struct ImportedNamespace { - ImportedNamespace(); - ~ImportedNamespace(); - - bool getTypeInfo(const QByteArray &typeName, QString *uri, int *vmaj, int *vmin); - private: - friend class QmlImportsPrivate; - friend class QmlEnginePrivate; - class QmlImportedNamespacePrivate *d; - }; - + struct ImportedNamespace; bool addToImport(Imports*, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const; - - bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, ImportedNamespace** ns_return=0) const; - - void resolveNamespace(const Imports& imports, const QByteArray &type, ImportedNamespace **s, QByteArray *unqualifiedType) const; - bool resolveTypeInNamespace(ImportedNamespace*, const QByteArray& type, QmlType** type_return, QUrl* url_return ) const; + bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, int *version_major, int *version_minor, ImportedNamespace** ns_return=0) const; + void resolveTypeInNamespace(ImportedNamespace*, const QByteArray& type, QmlType** type_return, QUrl* url_return, int *version_major, int *version_minor ) const; static QScriptValue qmlScriptObject(QObject*, QmlEngine*); diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 99f9f0c..63415da 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -224,7 +224,7 @@ void QmlMetaPropertyPrivate::initProperty(QObject *obj, const QString &name) if (typeData) { QmlType *t = 0; - enginePrivate->resolveType(typeData->imports, name.toLatin1(), &t, 0); + enginePrivate->resolveType(typeData->imports, name.toLatin1(), &t, 0, 0, 0); if (t && t->attachedPropertiesFunction()) { attachedFunc = t->index(); if (attachedFunc != -1) -- cgit v0.12 From 13fd16e67500e77b8cda34de448cb89ca38a5dab Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 25 Aug 2009 10:06:37 +1000 Subject: Remove unnecessary KeysAttached static map --- src/declarative/fx/qfxitem.cpp | 19 ++++++++++++------- src/declarative/fx/qfxitem.h | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index feb4e8c..ed2386b 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -704,7 +704,6 @@ private: }; static const SigMap sigMap[]; - static QHash attachedProperties; friend class QFxItem; }; @@ -738,8 +737,6 @@ const QFxKeysAttached::SigMap QFxKeysAttached::sigMap[] = { { 0, 0 } }; -QHash QFxKeysAttached::attachedProperties; - bool QFxKeysAttachedPrivate::isConnected(const char *signalName) { return isSignalConnected(signalIndex(signalName)); @@ -796,10 +793,12 @@ void QFxKeysAttached::keyReleased(QKeyEvent *event) QFxKeysAttached *QFxKeysAttached::qmlAttachedProperties(QObject *obj) { - QFxKeysAttached *rv = attachedProperties.value(obj); - if (!rv) { - rv = new QFxKeysAttached(obj); - attachedProperties.insert(obj, rv); + QFxKeysAttached *rv = 0; + QFxItem *item = qobject_cast(obj); + if (item) { + rv = item->keyHandler(); + if (!rv) + rv = new QFxKeysAttached(obj); } return rv; } @@ -1423,6 +1422,12 @@ void QFxItem::geometryChanged(const QRectF &newGeometry, } } +QFxKeysAttached *QFxItem::keyHandler() +{ + Q_D(QFxItem); + return d->keyHandler; +} + void QFxItem::setKeyHandler(QFxKeysAttached *handler) { Q_D(QFxItem); diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index 89c2cf1..222677c 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -197,6 +197,7 @@ private: QFxAnchorLine verticalCenter() const; QFxAnchorLine baseline() const; + QFxKeysAttached *keyHandler(); void setKeyHandler(QFxKeysAttached *); friend class QmlStatePrivate; -- cgit v0.12 From 243862b66bdfd9a6cdcaf7d588670e6cc93da447 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 25 Aug 2009 10:16:02 +1000 Subject: Add (non-functional) KeyNavigation type --- src/declarative/fx/qfxitem.cpp | 99 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index feb4e8c..ee8228a 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -299,6 +299,101 @@ void QFxContents::setItem(QFxItem *item) calcWidth(); } +class QFxKeyNavigationAttachedPrivate : public QObjectPrivate +{ +public: + QFxKeyNavigationAttachedPrivate() + : QObjectPrivate(), left(0), right(0), up(0), down(0) {} + + QFxItem *left; + QFxItem *right; + QFxItem *up; + QFxItem *down; +}; + +class QFxKeyNavigationAttached : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QFxKeyNavigationAttached); + + Q_PROPERTY(QFxItem *left READ left WRITE setLeft NOTIFY changed); + Q_PROPERTY(QFxItem *right READ right WRITE setRight NOTIFY changed); + Q_PROPERTY(QFxItem *up READ up WRITE setUp NOTIFY changed); + Q_PROPERTY(QFxItem *down READ down WRITE setDown NOTIFY changed); +public: + QFxKeyNavigationAttached(QObject * = 0); + + QFxItem *left() const; + void setLeft(QFxItem *); + QFxItem *right() const; + void setRight(QFxItem *); + QFxItem *up() const; + void setUp(QFxItem *); + QFxItem *down() const; + void setDown(QFxItem *); + + static QFxKeyNavigationAttached *qmlAttachedProperties(QObject *); +}; + +QFxKeyNavigationAttached::QFxKeyNavigationAttached(QObject *parent) +: QObject(*(new QFxKeyNavigationAttachedPrivate), parent) +{ +} + +QFxKeyNavigationAttached * +QFxKeyNavigationAttached::qmlAttachedProperties(QObject *obj) +{ + return new QFxKeyNavigationAttached(obj); +} + +QFxItem *QFxKeyNavigationAttached::left() const +{ + Q_D(const QFxKeyNavigationAttached); + return d->left; +} + +void QFxKeyNavigationAttached::setLeft(QFxItem *i) +{ + Q_D(QFxKeyNavigationAttached); + d->left = i; +} + +QFxItem *QFxKeyNavigationAttached::right() const +{ + Q_D(const QFxKeyNavigationAttached); + return d->right; +} + +void QFxKeyNavigationAttached::setRight(QFxItem *i) +{ + Q_D(QFxKeyNavigationAttached); + d->right = i; +} + +QFxItem *QFxKeyNavigationAttached::up() const +{ + Q_D(const QFxKeyNavigationAttached); + return d->up; +} + +void QFxKeyNavigationAttached::setUp(QFxItem *i) +{ + Q_D(QFxKeyNavigationAttached); + d->up = i; +} + +QFxItem *QFxKeyNavigationAttached::down() const +{ + Q_D(const QFxKeyNavigationAttached); + return d->down; +} + +void QFxKeyNavigationAttached::setDown(QFxItem *i) +{ + Q_D(QFxKeyNavigationAttached); + d->down = i; +} + /*! \qmlclass Keys \brief The Keys attached property provides key handling to Items. @@ -746,7 +841,7 @@ bool QFxKeysAttachedPrivate::isConnected(const char *signalName) } QFxKeysAttached::QFxKeysAttached(QObject *parent) - : QObject(*(new QFxKeysAttachedPrivate), parent) +: QObject(*(new QFxKeysAttachedPrivate), parent) { if (QFxItem *item = qobject_cast(parent)) item->setKeyHandler(this); @@ -2438,6 +2533,8 @@ QT_END_NAMESPACE QML_DECLARE_TYPE(QFxKeysAttached) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Keys,QFxKeysAttached) +QML_DECLARE_TYPE(QFxKeyNavigationAttached) +QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,KeyNavigation,QFxKeyNavigationAttached) #include "moc_qfxitem.cpp" #include "qfxitem.moc" -- cgit v0.12 From ffdb37081cac1fcaa6f62f38f18b8d271e95eb9c Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 25 Aug 2009 10:23:27 +1000 Subject: Missed files. --- examples/declarative/webview/evalandattach.html | 31 ++++++++++++++ examples/declarative/webview/evalandattach.qml | 55 +++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 examples/declarative/webview/evalandattach.html create mode 100644 examples/declarative/webview/evalandattach.qml diff --git a/examples/declarative/webview/evalandattach.html b/examples/declarative/webview/evalandattach.html new file mode 100644 index 0000000..c0992bb --- /dev/null +++ b/examples/declarative/webview/evalandattach.html @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + +
 
+ +
+

+ Below a qml(QFxItem) object inside webkit: +

+ + + + diff --git a/examples/declarative/webview/evalandattach.qml b/examples/declarative/webview/evalandattach.qml new file mode 100644 index 0000000..bf7f25e --- /dev/null +++ b/examples/declarative/webview/evalandattach.qml @@ -0,0 +1,55 @@ +import Qt 4.6 + +Item { + height: 640 + width: 360 + Text { + id: teksti + text: webView.statusText1 + anchors.top: parent.top + height: 30 + anchors.left: parent.left + width: parent.width/2 + } + + Text { + id: teksti2 + text: webView.statusText2 + anchors.top: parent.top + height: 30 + anchors.left: teksti.right + anchors.right: parent.right + } + + MouseRegion { + anchors.fill: teksti + onClicked: { webView.evaluateJavaScript ("do_it()") } + } + + WebView { + id: webView + property alias statusText1: txt.text + property alias statusText2: txt2.text + anchors.top: teksti.bottom + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + focus: true + interactive: true + settings.pluginsEnabled: true + javaScriptWindowObjects: [ + Object { + id: txt + WebView.windowObjectName: "statusText1" + property string text: "Click me!" + }, + Object { + id: txt2 + WebView.windowObjectName: "statusText2" + property string text: "" + } + ] + url: "evalandattach.html" + } + +} -- cgit v0.12 From 8823016dac5f0db41970926fada6db2b5f213e93 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 25 Aug 2009 10:23:59 +1000 Subject: typo --- examples/declarative/webview/content/SpinSquare.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/declarative/webview/content/SpinSquare.qml b/examples/declarative/webview/content/SpinSquare.qml index 6d5ada3..95159b6 100644 --- a/examples/declarative/webview/content/SpinSquare.qml +++ b/examples/declarative/webview/content/SpinSquare.qml @@ -2,7 +2,7 @@ import Qt 4.6 Item { property var period : 250 - propert var color : "black" + property var color : "black" id: Root Item { -- cgit v0.12 From 5a52ae5e95867b420c647082573290a9e2596bdd Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 25 Aug 2009 10:46:35 +1000 Subject: Remove the QmlBinding_Id from QmlContext on destruction --- src/declarative/qml/qmlbindingoptimizations.cpp | 12 +++++++++++- src/declarative/qml/qmlbindingoptimizations_p.h | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qmlbindingoptimizations.cpp b/src/declarative/qml/qmlbindingoptimizations.cpp index e1f4a90..e4ca358 100644 --- a/src/declarative/qml/qmlbindingoptimizations.cpp +++ b/src/declarative/qml/qmlbindingoptimizations.cpp @@ -64,6 +64,11 @@ QmlBinding_Id::QmlBinding_Id(QObject *object, int propertyIdx, QmlAbstractExpression::setContext(context); } +QmlBinding_Id::~QmlBinding_Id() +{ + removeFromContext(); +} + void QmlBinding_Id::setEnabled(bool e) { if (e) { @@ -103,7 +108,7 @@ void QmlBinding_Id::update() } } -void QmlBinding_Id::reset() +void QmlBinding_Id::removeFromContext() { if (m_prev) { *m_prev = m_next; @@ -111,6 +116,11 @@ void QmlBinding_Id::reset() m_next = 0; m_prev = 0; } +} + +void QmlBinding_Id::reset() +{ + removeFromContext(); QObject *o = 0; void *a[] = { &o, 0 }; diff --git a/src/declarative/qml/qmlbindingoptimizations_p.h b/src/declarative/qml/qmlbindingoptimizations_p.h index 2d2ffec..ab264c7 100644 --- a/src/declarative/qml/qmlbindingoptimizations_p.h +++ b/src/declarative/qml/qmlbindingoptimizations_p.h @@ -65,7 +65,8 @@ class QmlBinding_Id : public QmlAbstractExpression, { public: QmlBinding_Id(QObject *object, int propertyIdx, - QmlContext *context, int id); + QmlContext *context, int id); + virtual ~QmlBinding_Id(); // Inherited from QmlAbstractBinding virtual void setEnabled(bool); @@ -75,6 +76,8 @@ public: void reset(); private: + void removeFromContext(); + QmlBinding_Id **m_prev; QmlBinding_Id *m_next; -- cgit v0.12 From 7f41d39c293e1bd013acc0e79af2aa66e1f9e4d0 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 25 Aug 2009 11:20:08 +1000 Subject: Mobile version of Flickr demo in flickr-mobile.qml. --- demos/declarative/flickr/common/ImageDetails.qml | 160 +++++++++++++ demos/declarative/flickr/common/LikeOMeter.qml | 35 +++ demos/declarative/flickr/common/Loading.qml | 8 + demos/declarative/flickr/common/MediaButton.qml | 41 ++++ demos/declarative/flickr/common/MediaLineEdit.qml | 109 +++++++++ demos/declarative/flickr/common/Progress.qml | 35 +++ demos/declarative/flickr/common/ScrollBar.qml | 40 ++++ demos/declarative/flickr/common/Slider.qml | 36 +++ demos/declarative/flickr/common/Star.qml | 46 ++++ .../declarative/flickr/common/pics/background.png | Bin 0 -> 60504 bytes .../flickr/common/pics/button-pressed.png | Bin 0 -> 571 bytes .../flickr/common/pics/button-pressed.sci | 5 + demos/declarative/flickr/common/pics/button.png | Bin 0 -> 564 bytes demos/declarative/flickr/common/pics/button.sci | 5 + demos/declarative/flickr/common/pics/ghns_star.png | Bin 0 -> 891 bytes demos/declarative/flickr/common/pics/loading.png | Bin 0 -> 813 bytes .../declarative/flickr/common/pics/reflection.png | Bin 0 -> 4839 bytes .../flickr/common/pics/shadow-bottom.png | Bin 0 -> 656 bytes .../flickr/common/pics/shadow-corner.png | Bin 0 -> 405 bytes .../flickr/common/pics/shadow-right-screen.png | Bin 0 -> 227 bytes .../flickr/common/pics/shadow-right.png | Bin 0 -> 635 bytes demos/declarative/flickr/content/ImageDetails.qml | 160 ------------- demos/declarative/flickr/content/LikeOMeter.qml | 35 --- demos/declarative/flickr/content/Loading.qml | 8 - demos/declarative/flickr/content/MediaButton.qml | 41 ---- demos/declarative/flickr/content/MediaLineEdit.qml | 109 --------- demos/declarative/flickr/content/Progress.qml | 35 --- demos/declarative/flickr/content/ScrollBar.qml | 40 ---- demos/declarative/flickr/content/Slider.qml | 36 --- demos/declarative/flickr/content/Star.qml | 46 ---- .../declarative/flickr/content/pics/background.png | Bin 60504 -> 0 bytes .../flickr/content/pics/button-pressed.png | Bin 571 -> 0 bytes .../flickr/content/pics/button-pressed.sci | 5 - demos/declarative/flickr/content/pics/button.png | Bin 564 -> 0 bytes demos/declarative/flickr/content/pics/button.sci | 5 - .../declarative/flickr/content/pics/ghns_star.png | Bin 891 -> 0 bytes demos/declarative/flickr/content/pics/loading.png | Bin 813 -> 0 bytes .../declarative/flickr/content/pics/reflection.png | Bin 4839 -> 0 bytes .../flickr/content/pics/shadow-bottom.png | Bin 656 -> 0 bytes .../flickr/content/pics/shadow-corner.png | Bin 405 -> 0 bytes .../flickr/content/pics/shadow-right-screen.png | Bin 227 -> 0 bytes .../flickr/content/pics/shadow-right.png | Bin 635 -> 0 bytes demos/declarative/flickr/flickr-desktop.qml | 192 +++++++++++++++ demos/declarative/flickr/flickr-mobile.qml | 51 ++++ demos/declarative/flickr/flickr.qml | 211 ----------------- demos/declarative/flickr/flickr2.qml | 261 --------------------- demos/declarative/flickr/mobile/Button.qml | 41 ++++ demos/declarative/flickr/mobile/GridDelegate.qml | 74 ++++++ demos/declarative/flickr/mobile/ListDelegate.qml | 24 ++ demos/declarative/flickr/mobile/TitleBar.qml | 74 ++++++ demos/declarative/flickr/mobile/ToolBar.qml | 23 ++ demos/declarative/flickr/mobile/images/gloss.png | Bin 0 -> 1236 bytes .../declarative/flickr/mobile/images/lineedit.png | Bin 0 -> 1415 bytes .../declarative/flickr/mobile/images/lineedit.sci | 5 + demos/declarative/flickr/mobile/images/stripes.png | Bin 0 -> 257 bytes .../declarative/flickr/mobile/images/titlebar2.png | Bin 0 -> 1436 bytes .../declarative/flickr/mobile/images/titlebar2.sci | 5 + .../flickr/mobile/images/toolbutton2.png | Bin 0 -> 2619 bytes .../flickr/mobile/images/toolbutton2.sci | 5 + 59 files changed, 1014 insertions(+), 992 deletions(-) create mode 100644 demos/declarative/flickr/common/ImageDetails.qml create mode 100644 demos/declarative/flickr/common/LikeOMeter.qml create mode 100644 demos/declarative/flickr/common/Loading.qml create mode 100644 demos/declarative/flickr/common/MediaButton.qml create mode 100644 demos/declarative/flickr/common/MediaLineEdit.qml create mode 100644 demos/declarative/flickr/common/Progress.qml create mode 100644 demos/declarative/flickr/common/ScrollBar.qml create mode 100644 demos/declarative/flickr/common/Slider.qml create mode 100644 demos/declarative/flickr/common/Star.qml create mode 100644 demos/declarative/flickr/common/pics/background.png create mode 100644 demos/declarative/flickr/common/pics/button-pressed.png create mode 100644 demos/declarative/flickr/common/pics/button-pressed.sci create mode 100644 demos/declarative/flickr/common/pics/button.png create mode 100644 demos/declarative/flickr/common/pics/button.sci create mode 100644 demos/declarative/flickr/common/pics/ghns_star.png create mode 100644 demos/declarative/flickr/common/pics/loading.png create mode 100644 demos/declarative/flickr/common/pics/reflection.png create mode 100644 demos/declarative/flickr/common/pics/shadow-bottom.png create mode 100644 demos/declarative/flickr/common/pics/shadow-corner.png create mode 100644 demos/declarative/flickr/common/pics/shadow-right-screen.png create mode 100644 demos/declarative/flickr/common/pics/shadow-right.png delete mode 100644 demos/declarative/flickr/content/ImageDetails.qml delete mode 100644 demos/declarative/flickr/content/LikeOMeter.qml delete mode 100644 demos/declarative/flickr/content/Loading.qml delete mode 100644 demos/declarative/flickr/content/MediaButton.qml delete mode 100644 demos/declarative/flickr/content/MediaLineEdit.qml delete mode 100644 demos/declarative/flickr/content/Progress.qml delete mode 100644 demos/declarative/flickr/content/ScrollBar.qml delete mode 100644 demos/declarative/flickr/content/Slider.qml delete mode 100644 demos/declarative/flickr/content/Star.qml delete mode 100644 demos/declarative/flickr/content/pics/background.png delete mode 100644 demos/declarative/flickr/content/pics/button-pressed.png delete mode 100644 demos/declarative/flickr/content/pics/button-pressed.sci delete mode 100644 demos/declarative/flickr/content/pics/button.png delete mode 100644 demos/declarative/flickr/content/pics/button.sci delete mode 100644 demos/declarative/flickr/content/pics/ghns_star.png delete mode 100644 demos/declarative/flickr/content/pics/loading.png delete mode 100644 demos/declarative/flickr/content/pics/reflection.png delete mode 100644 demos/declarative/flickr/content/pics/shadow-bottom.png delete mode 100644 demos/declarative/flickr/content/pics/shadow-corner.png delete mode 100644 demos/declarative/flickr/content/pics/shadow-right-screen.png delete mode 100644 demos/declarative/flickr/content/pics/shadow-right.png create mode 100644 demos/declarative/flickr/flickr-desktop.qml create mode 100644 demos/declarative/flickr/flickr-mobile.qml delete mode 100644 demos/declarative/flickr/flickr.qml delete mode 100644 demos/declarative/flickr/flickr2.qml create mode 100644 demos/declarative/flickr/mobile/Button.qml create mode 100644 demos/declarative/flickr/mobile/GridDelegate.qml create mode 100644 demos/declarative/flickr/mobile/ListDelegate.qml create mode 100644 demos/declarative/flickr/mobile/TitleBar.qml create mode 100644 demos/declarative/flickr/mobile/ToolBar.qml create mode 100644 demos/declarative/flickr/mobile/images/gloss.png create mode 100644 demos/declarative/flickr/mobile/images/lineedit.png create mode 100644 demos/declarative/flickr/mobile/images/lineedit.sci create mode 100644 demos/declarative/flickr/mobile/images/stripes.png create mode 100644 demos/declarative/flickr/mobile/images/titlebar2.png create mode 100644 demos/declarative/flickr/mobile/images/titlebar2.sci create mode 100644 demos/declarative/flickr/mobile/images/toolbutton2.png create mode 100644 demos/declarative/flickr/mobile/images/toolbutton2.sci diff --git a/demos/declarative/flickr/common/ImageDetails.qml b/demos/declarative/flickr/common/ImageDetails.qml new file mode 100644 index 0000000..8098273 --- /dev/null +++ b/demos/declarative/flickr/common/ImageDetails.qml @@ -0,0 +1,160 @@ +import Qt 4.6 + +Flipable { + id: Container + + property var frontContainer: ContainerFront + property string photoTitle: "" + property string photoDescription: "" + property string photoTags: "" + property int photoWidth + property int photoHeight + property string photoType + property string photoAuthor + property string photoDate + property string photoUrl + property int rating: 2 + property var prevScale: 1.0 + + signal closed + + transform: Rotation { + id: Rotation + origin.x: Container.width / 2; + axis.y: 1; axis.z: 0 + } + + front: Item { + id: ContainerFront; anchors.fill: Container + + Rectangle { + anchors.fill: parent + color: "black"; opacity: 0.4 + border.color: "white"; border.width: 2 + } + + MediaButton { + id: BackButton; x: 630; y: 370; text: "Back" + onClicked: { Container.closed() } + } + + MediaButton { + id: MoreButton; x: 530; y: 370; text: "View..." + onClicked: { Container.state='Back' } + } + + Text { id: TitleText; style: "Raised"; styleColor: "black"; color: "white"; elide: "ElideRight" + x: 220; y: 30; width: parent.width - 240; text: Container.photoTitle; font.pointSize: 22 } + + LikeOMeter { x: 40; y: 250; rating: Container.rating } + + Flickable { id: Flickable; x: 220; width: 480; height: 210; y: 130; clip: true + viewportWidth: 480; viewportHeight: DescriptionText.height + + WebView { id: DescriptionText; width: parent.width + html: "" + Container.photoDescription } + } + + Text { id: Size; color: "white"; width: 300; x: 40; y: 300 + text: "Size: " + Container.photoWidth + 'x' + Container.photoHeight } + Text { id: Type; color: "white"; width: 300; x: 40; anchors.top: Size.bottom + text: "Type: " + Container.photoType } + + Text { id: Author; color: "white"; width: 300; x: 220; y: 80 + text: "Author: " + Container.photoAuthor } + Text { id: Date; color: "white"; width: 300; x: 220; anchors.top: Author.bottom + text: "Published: " + Container.photoDate } + Text { id: TagsLabel; color: "white"; x: 220; anchors.top: Date.bottom; + text: Container.photoTags == "" ? "" : "Tags: " } + Text { id: Tags; color: "white"; width: parent.width-x-20; + anchors.left: TagsLabel.right; anchors.top: Date.bottom; + elide: "ElideRight"; text: Container.photoTags } + + ScrollBar { id: ScrollBar; x: 720; y: Flickable.y; width: 7; height: Flickable.height; opacity: 0; + flickableArea: Flickable; clip: true } + } + + back: Item { + anchors.fill: Container + + Rectangle { anchors.fill: parent; color: "black"; opacity: 0.4; border.color: "white"; border.width: 2 } + + Progress { anchors.centerIn: parent; width: 200; height: 18; progress: BigImage.progress; visible: BigImage.status!=1 } + Flickable { + id: Flick; width: Container.width - 10; height: Container.height - 10 + x: 5; y: 5; clip: true; + viewportWidth: ImageContainer.width; viewportHeight: ImageContainer.height + + Item { + id: ImageContainer + width: Math.max(BigImage.width * BigImage.scale, Flick.width); + height: Math.max(BigImage.height * BigImage.scale, Flick.height); + + Image { + id: BigImage; source: Container.photoUrl; scale: Slider.value + // Center image if it is smaller than the flickable area. + x: ImageContainer.width > width*scale ? (ImageContainer.width - width*scale) / 2 : 0 + y: ImageContainer.height > height*scale ? (ImageContainer.height - height*scale) / 2 : 0 + smooth: !Flick.moving + onStatusChanged : { + // Default scale shows the entire image. + if (status == 1 && width != 0) { + Slider.minimum = Math.min(Flick.width / width, Flick.height / height); + prevScale = Math.min(Slider.minimum, 1); + Slider.value = prevScale; + } + } + } + } + } + + MediaButton { + id: BackButton2; x: 630; y: 370; text: "Back"; onClicked: { Container.state = '' } + } + Text { + text: "Image Unavailable" + visible: BigImage.status == 'Error' + anchors.centerIn: parent; color: "white"; font.bold: true + } + + Slider { + id: Slider; x: 25; y: 374; visible: { BigImage.status == 1 && maximum > minimum } + onValueChanged: { + if (BigImage.width * value > Flick.width) { + var xoff = (Flick.width/2 + Flick.xPosition) * value / prevScale; + Flick.xPosition = xoff - Flick.width/2; + } + if (BigImage.height * value > Flick.height) { + var yoff = (Flick.height/2 + Flick.yPosition) * value / prevScale; + Flick.yPosition = yoff - Flick.height/2; + } + prevScale = value; + } + } + } + + states: [ + State { + name: "Back" + PropertyChanges { target: Rotation; angle: 180 } + } + ] + + transitions: [ + Transition { + SequentialAnimation { + PropertyAction { + target: BigImage + property: "smooth" + value: false + } + NumberAnimation { easing: "easeInOutQuad"; properties: "angle"; duration: 500 } + PropertyAction { + target: BigImage + property: "smooth" + value: !Flick.moving + } + } + } + ] +} diff --git a/demos/declarative/flickr/common/LikeOMeter.qml b/demos/declarative/flickr/common/LikeOMeter.qml new file mode 100644 index 0000000..754dbb1 --- /dev/null +++ b/demos/declarative/flickr/common/LikeOMeter.qml @@ -0,0 +1,35 @@ +import Qt 4.6 + +Item { + id: Container + + property int rating: 2 + + Row { + Star { + rating: 0 + onClicked: { Container.rating = rating } + on: Container.rating >= 0 + } + Star { + rating: 1 + onClicked: { Container.rating = rating } + on: Container.rating >= 1 + } + Star { + rating: 2 + onClicked: { Container.rating = rating } + on: Container.rating >= 2 + } + Star { + rating: 3 + onClicked: { Container.rating = rating } + on: Container.rating >= 3 + } + Star { + rating: 4 + onClicked: { Container.rating = rating } + on: Container.rating >= 4 + } + } +} diff --git a/demos/declarative/flickr/common/Loading.qml b/demos/declarative/flickr/common/Loading.qml new file mode 100644 index 0000000..ff2c829 --- /dev/null +++ b/demos/declarative/flickr/common/Loading.qml @@ -0,0 +1,8 @@ +import Qt 4.6 + +Image { + id: Loading; source: "pics/loading.png"; transformOrigin: "Center" + rotation: NumberAnimation { + id: "RotationAnimation"; from: 0; to: 360; running: Loading.visible == true; repeat: true; duration: 900 + } +} diff --git a/demos/declarative/flickr/common/MediaButton.qml b/demos/declarative/flickr/common/MediaButton.qml new file mode 100644 index 0000000..0ffd596 --- /dev/null +++ b/demos/declarative/flickr/common/MediaButton.qml @@ -0,0 +1,41 @@ +import Qt 4.6 + +Item { + id: Container + + signal clicked + + property string text + + Image { + id: Image + source: "pics/button.png" + } + Image { + id: Pressed + source: "pics/button-pressed.png" + opacity: 0 + } + MouseRegion { + id: MouseRegion + anchors.fill: Image + onClicked: { Container.clicked(); } + } + Text { + font.bold: true + color: "white" + anchors.centerIn: Image + text: Container.text + } + width: Image.width + states: [ + State { + name: "Pressed" + when: MouseRegion.pressed == true + PropertyChanges { + target: Pressed + opacity: 1 + } + } + ] +} diff --git a/demos/declarative/flickr/common/MediaLineEdit.qml b/demos/declarative/flickr/common/MediaLineEdit.qml new file mode 100644 index 0000000..500a402 --- /dev/null +++ b/demos/declarative/flickr/common/MediaLineEdit.qml @@ -0,0 +1,109 @@ +import Qt 4.6 + +Item { + id: Container + + property string label + property string text + + width: Math.max(94,Label.width + Editor.width + 20) + height: Image.height + + states: [ + State { + name: "Edit" + PropertyChanges { + target: Label + text: Container.label + ": " + } + PropertyChanges { + target: Label + x: 10 + } + PropertyChanges { + target: Editor + cursorVisible: true + width: 100 + } + PropertyChanges { + target: Proxy + focus: true + } + StateChangeScript { + script:"Editor.selectAll()" + } + }, + State { + // When returning to default state, typed text is propagated + StateChangeScript { + script: "Container.text = Editor.text" + } + } + ] + transitions: [ + Transition { + NumberAnimation { properties: "x,width"; duration: 500; easing: "easeInOutQuad" } + } + ] + + + BorderImage { + id: Image + source: "pics/button.sci" + anchors.left: Container.left + anchors.right: Container.right + } + + BorderImage { + id: Pressed + source: "pics/button-pressed.sci" + opacity: 0 + anchors.left: Container.left + anchors.right: Container.right + } + + MouseRegion { + id: MouseRegion + anchors.fill: Image + onClicked: { Container.state = Container.state=="Edit" ? "" : "Edit" } + states: [ + State { + when: MouseRegion.pressed == true + PropertyChanges { + target: Pressed + opacity: 1 + } + } + ] + } + + Text { + id: Label + font.bold: true + color: "white" + anchors.verticalCenter: Container.verticalCenter + x: (Container.width - width)/2 + text: Container.label + "..." + } + + TextInput { + id: Editor + font.bold: true + color: "white" + highlightColor: "green" + width: 0 + clip: true + anchors.left: Label.right + anchors.verticalCenter: Container.verticalCenter + } + KeyProxy { + id: Proxy + anchors.left: Container.left + anchors.fill: Container + targets: [(ReturnKey), (Editor)] + } + Item { + id: ReturnKey + Keys.onReturnPressed: "Container.state = ''" + } +} diff --git a/demos/declarative/flickr/common/Progress.qml b/demos/declarative/flickr/common/Progress.qml new file mode 100644 index 0000000..00ef901 --- /dev/null +++ b/demos/declarative/flickr/common/Progress.qml @@ -0,0 +1,35 @@ +import Qt 4.6 + +Item { + id: Progress; + + property var progress: 0 + + Rectangle { + id: Container; anchors.fill: parent; smooth: true + border.color: "white"; border.width: 0; radius: height/2 - 2 + gradient: Gradient { + GradientStop { position: 0; color: "#66343434" } + GradientStop { position: 1.0; color: "#66000000" } + } + } + + Rectangle { + id: Fill + y: 2; height: parent.height-4; + x: 2; width: Math.max(parent.width * progress - 4, 0); + opacity: width < 1 ? 0 : 1; smooth: true + gradient: Gradient { + GradientStop { position: 0; color: "lightsteelblue" } + GradientStop { position: 1.0; color: "steelblue" } + } + radius: height/2 - 2 + } + + Text { + text: Math.round(progress * 100) + "%" + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + color: "white"; font.bold: true + } +} diff --git a/demos/declarative/flickr/common/ScrollBar.qml b/demos/declarative/flickr/common/ScrollBar.qml new file mode 100644 index 0000000..89d51e2 --- /dev/null +++ b/demos/declarative/flickr/common/ScrollBar.qml @@ -0,0 +1,40 @@ +import Qt 4.6 + +Item { + id: Container + + property var flickableArea + + Rectangle { + radius: 5 + color: "black" + opacity: 0.3 + border.color: "white" + border.width: 2 + x: 0 + y: flickableArea.pageYPosition * Container.height + width: parent.width + height: flickableArea.pageHeight * Container.height + } + states: [ + State { + name: "show" + when: flickableArea.moving + PropertyChanges { + target: Container + opacity: 1 + } + } + ] + transitions: [ + Transition { + from: "*" + to: "*" + NumberAnimation { + target: Container + properties: "opacity" + duration: 400 + } + } + ] +} diff --git a/demos/declarative/flickr/common/Slider.qml b/demos/declarative/flickr/common/Slider.qml new file mode 100644 index 0000000..b88636d --- /dev/null +++ b/demos/declarative/flickr/common/Slider.qml @@ -0,0 +1,36 @@ +import Qt 4.6 + +Item { + id: Slider; width: 400; height: 16 + + // value is read/write. + property real value + onValueChanged: { Handle.x = 2 + (value - minimum) * Slider.xMax / (maximum - minimum); } + property real maximum: 1 + property real minimum: 1 + property int xMax: Slider.width - Handle.width - 4 + + Rectangle { + id: Container; anchors.fill: parent + border.color: "white"; border.width: 0; radius: 8 + gradient: Gradient { + GradientStop { position: 0.0; color: "#66343434" } + GradientStop { position: 1.0; color: "#66000000" } + } + } + + Rectangle { + id: Handle; smooth: true + x: Slider.width / 2 - Handle.width / 2; y: 2; width: 30; height: Slider.height-4; radius: 6 + gradient: Gradient { + GradientStop { position: 0.0; color: "lightgray" } + GradientStop { position: 1.0; color: "gray" } + } + + MouseRegion { + anchors.fill: parent; drag.target: parent + drag.axis: "XAxis"; drag.minimumX: 2; drag.maximumX: Slider.xMax+2 + onPositionChanged: { value = (maximum - minimum) * (Handle.x-2) / Slider.xMax + minimum; } + } + } +} diff --git a/demos/declarative/flickr/common/Star.qml b/demos/declarative/flickr/common/Star.qml new file mode 100644 index 0000000..006e86ad --- /dev/null +++ b/demos/declarative/flickr/common/Star.qml @@ -0,0 +1,46 @@ +import Qt 4.6 + +Item { + id: Container + width: 24 + height: 24 + + property int rating + property bool on + + signal clicked + + Image { + id: Image + source: "pics/ghns_star.png" + x: 6 + y: 7 + opacity: 0.4 + scale: 0.5 + } + MouseRegion { + anchors.fill: Container + onClicked: { Container.clicked() } + } + states: [ + State { + name: "on" + when: Container.on == true + PropertyChanges { + target: Image + opacity: 1 + scale: 1 + x: 1 + y: 0 + } + } + ] + transitions: [ + Transition { + NumberAnimation { + properties: "opacity,scale,x,y" + easing: "easeOutBounce" + } + } + ] +} diff --git a/demos/declarative/flickr/common/pics/background.png b/demos/declarative/flickr/common/pics/background.png new file mode 100644 index 0000000..5b37072 Binary files /dev/null and b/demos/declarative/flickr/common/pics/background.png differ diff --git a/demos/declarative/flickr/common/pics/button-pressed.png b/demos/declarative/flickr/common/pics/button-pressed.png new file mode 100644 index 0000000..e434d32 Binary files /dev/null and b/demos/declarative/flickr/common/pics/button-pressed.png differ diff --git a/demos/declarative/flickr/common/pics/button-pressed.sci b/demos/declarative/flickr/common/pics/button-pressed.sci new file mode 100644 index 0000000..d3b16e2 --- /dev/null +++ b/demos/declarative/flickr/common/pics/button-pressed.sci @@ -0,0 +1,5 @@ +gridLeft: 8 +gridTop: 4 +gridBottom: 4 +gridRight: 8 +imageFile: button.png diff --git a/demos/declarative/flickr/common/pics/button.png b/demos/declarative/flickr/common/pics/button.png new file mode 100644 index 0000000..56a63ce Binary files /dev/null and b/demos/declarative/flickr/common/pics/button.png differ diff --git a/demos/declarative/flickr/common/pics/button.sci b/demos/declarative/flickr/common/pics/button.sci new file mode 100644 index 0000000..d3b16e2 --- /dev/null +++ b/demos/declarative/flickr/common/pics/button.sci @@ -0,0 +1,5 @@ +gridLeft: 8 +gridTop: 4 +gridBottom: 4 +gridRight: 8 +imageFile: button.png diff --git a/demos/declarative/flickr/common/pics/ghns_star.png b/demos/declarative/flickr/common/pics/ghns_star.png new file mode 100644 index 0000000..4ad43cc Binary files /dev/null and b/demos/declarative/flickr/common/pics/ghns_star.png differ diff --git a/demos/declarative/flickr/common/pics/loading.png b/demos/declarative/flickr/common/pics/loading.png new file mode 100644 index 0000000..47a1589 Binary files /dev/null and b/demos/declarative/flickr/common/pics/loading.png differ diff --git a/demos/declarative/flickr/common/pics/reflection.png b/demos/declarative/flickr/common/pics/reflection.png new file mode 100644 index 0000000..c143a48 Binary files /dev/null and b/demos/declarative/flickr/common/pics/reflection.png differ diff --git a/demos/declarative/flickr/common/pics/shadow-bottom.png b/demos/declarative/flickr/common/pics/shadow-bottom.png new file mode 100644 index 0000000..523f6e7 Binary files /dev/null and b/demos/declarative/flickr/common/pics/shadow-bottom.png differ diff --git a/demos/declarative/flickr/common/pics/shadow-corner.png b/demos/declarative/flickr/common/pics/shadow-corner.png new file mode 100644 index 0000000..ef8c856 Binary files /dev/null and b/demos/declarative/flickr/common/pics/shadow-corner.png differ diff --git a/demos/declarative/flickr/common/pics/shadow-right-screen.png b/demos/declarative/flickr/common/pics/shadow-right-screen.png new file mode 100644 index 0000000..9856c4f Binary files /dev/null and b/demos/declarative/flickr/common/pics/shadow-right-screen.png differ diff --git a/demos/declarative/flickr/common/pics/shadow-right.png b/demos/declarative/flickr/common/pics/shadow-right.png new file mode 100644 index 0000000..f534a35 Binary files /dev/null and b/demos/declarative/flickr/common/pics/shadow-right.png differ diff --git a/demos/declarative/flickr/content/ImageDetails.qml b/demos/declarative/flickr/content/ImageDetails.qml deleted file mode 100644 index 8098273..0000000 --- a/demos/declarative/flickr/content/ImageDetails.qml +++ /dev/null @@ -1,160 +0,0 @@ -import Qt 4.6 - -Flipable { - id: Container - - property var frontContainer: ContainerFront - property string photoTitle: "" - property string photoDescription: "" - property string photoTags: "" - property int photoWidth - property int photoHeight - property string photoType - property string photoAuthor - property string photoDate - property string photoUrl - property int rating: 2 - property var prevScale: 1.0 - - signal closed - - transform: Rotation { - id: Rotation - origin.x: Container.width / 2; - axis.y: 1; axis.z: 0 - } - - front: Item { - id: ContainerFront; anchors.fill: Container - - Rectangle { - anchors.fill: parent - color: "black"; opacity: 0.4 - border.color: "white"; border.width: 2 - } - - MediaButton { - id: BackButton; x: 630; y: 370; text: "Back" - onClicked: { Container.closed() } - } - - MediaButton { - id: MoreButton; x: 530; y: 370; text: "View..." - onClicked: { Container.state='Back' } - } - - Text { id: TitleText; style: "Raised"; styleColor: "black"; color: "white"; elide: "ElideRight" - x: 220; y: 30; width: parent.width - 240; text: Container.photoTitle; font.pointSize: 22 } - - LikeOMeter { x: 40; y: 250; rating: Container.rating } - - Flickable { id: Flickable; x: 220; width: 480; height: 210; y: 130; clip: true - viewportWidth: 480; viewportHeight: DescriptionText.height - - WebView { id: DescriptionText; width: parent.width - html: "" + Container.photoDescription } - } - - Text { id: Size; color: "white"; width: 300; x: 40; y: 300 - text: "Size: " + Container.photoWidth + 'x' + Container.photoHeight } - Text { id: Type; color: "white"; width: 300; x: 40; anchors.top: Size.bottom - text: "Type: " + Container.photoType } - - Text { id: Author; color: "white"; width: 300; x: 220; y: 80 - text: "Author: " + Container.photoAuthor } - Text { id: Date; color: "white"; width: 300; x: 220; anchors.top: Author.bottom - text: "Published: " + Container.photoDate } - Text { id: TagsLabel; color: "white"; x: 220; anchors.top: Date.bottom; - text: Container.photoTags == "" ? "" : "Tags: " } - Text { id: Tags; color: "white"; width: parent.width-x-20; - anchors.left: TagsLabel.right; anchors.top: Date.bottom; - elide: "ElideRight"; text: Container.photoTags } - - ScrollBar { id: ScrollBar; x: 720; y: Flickable.y; width: 7; height: Flickable.height; opacity: 0; - flickableArea: Flickable; clip: true } - } - - back: Item { - anchors.fill: Container - - Rectangle { anchors.fill: parent; color: "black"; opacity: 0.4; border.color: "white"; border.width: 2 } - - Progress { anchors.centerIn: parent; width: 200; height: 18; progress: BigImage.progress; visible: BigImage.status!=1 } - Flickable { - id: Flick; width: Container.width - 10; height: Container.height - 10 - x: 5; y: 5; clip: true; - viewportWidth: ImageContainer.width; viewportHeight: ImageContainer.height - - Item { - id: ImageContainer - width: Math.max(BigImage.width * BigImage.scale, Flick.width); - height: Math.max(BigImage.height * BigImage.scale, Flick.height); - - Image { - id: BigImage; source: Container.photoUrl; scale: Slider.value - // Center image if it is smaller than the flickable area. - x: ImageContainer.width > width*scale ? (ImageContainer.width - width*scale) / 2 : 0 - y: ImageContainer.height > height*scale ? (ImageContainer.height - height*scale) / 2 : 0 - smooth: !Flick.moving - onStatusChanged : { - // Default scale shows the entire image. - if (status == 1 && width != 0) { - Slider.minimum = Math.min(Flick.width / width, Flick.height / height); - prevScale = Math.min(Slider.minimum, 1); - Slider.value = prevScale; - } - } - } - } - } - - MediaButton { - id: BackButton2; x: 630; y: 370; text: "Back"; onClicked: { Container.state = '' } - } - Text { - text: "Image Unavailable" - visible: BigImage.status == 'Error' - anchors.centerIn: parent; color: "white"; font.bold: true - } - - Slider { - id: Slider; x: 25; y: 374; visible: { BigImage.status == 1 && maximum > minimum } - onValueChanged: { - if (BigImage.width * value > Flick.width) { - var xoff = (Flick.width/2 + Flick.xPosition) * value / prevScale; - Flick.xPosition = xoff - Flick.width/2; - } - if (BigImage.height * value > Flick.height) { - var yoff = (Flick.height/2 + Flick.yPosition) * value / prevScale; - Flick.yPosition = yoff - Flick.height/2; - } - prevScale = value; - } - } - } - - states: [ - State { - name: "Back" - PropertyChanges { target: Rotation; angle: 180 } - } - ] - - transitions: [ - Transition { - SequentialAnimation { - PropertyAction { - target: BigImage - property: "smooth" - value: false - } - NumberAnimation { easing: "easeInOutQuad"; properties: "angle"; duration: 500 } - PropertyAction { - target: BigImage - property: "smooth" - value: !Flick.moving - } - } - } - ] -} diff --git a/demos/declarative/flickr/content/LikeOMeter.qml b/demos/declarative/flickr/content/LikeOMeter.qml deleted file mode 100644 index 754dbb1..0000000 --- a/demos/declarative/flickr/content/LikeOMeter.qml +++ /dev/null @@ -1,35 +0,0 @@ -import Qt 4.6 - -Item { - id: Container - - property int rating: 2 - - Row { - Star { - rating: 0 - onClicked: { Container.rating = rating } - on: Container.rating >= 0 - } - Star { - rating: 1 - onClicked: { Container.rating = rating } - on: Container.rating >= 1 - } - Star { - rating: 2 - onClicked: { Container.rating = rating } - on: Container.rating >= 2 - } - Star { - rating: 3 - onClicked: { Container.rating = rating } - on: Container.rating >= 3 - } - Star { - rating: 4 - onClicked: { Container.rating = rating } - on: Container.rating >= 4 - } - } -} diff --git a/demos/declarative/flickr/content/Loading.qml b/demos/declarative/flickr/content/Loading.qml deleted file mode 100644 index ff2c829..0000000 --- a/demos/declarative/flickr/content/Loading.qml +++ /dev/null @@ -1,8 +0,0 @@ -import Qt 4.6 - -Image { - id: Loading; source: "pics/loading.png"; transformOrigin: "Center" - rotation: NumberAnimation { - id: "RotationAnimation"; from: 0; to: 360; running: Loading.visible == true; repeat: true; duration: 900 - } -} diff --git a/demos/declarative/flickr/content/MediaButton.qml b/demos/declarative/flickr/content/MediaButton.qml deleted file mode 100644 index 0ffd596..0000000 --- a/demos/declarative/flickr/content/MediaButton.qml +++ /dev/null @@ -1,41 +0,0 @@ -import Qt 4.6 - -Item { - id: Container - - signal clicked - - property string text - - Image { - id: Image - source: "pics/button.png" - } - Image { - id: Pressed - source: "pics/button-pressed.png" - opacity: 0 - } - MouseRegion { - id: MouseRegion - anchors.fill: Image - onClicked: { Container.clicked(); } - } - Text { - font.bold: true - color: "white" - anchors.centerIn: Image - text: Container.text - } - width: Image.width - states: [ - State { - name: "Pressed" - when: MouseRegion.pressed == true - PropertyChanges { - target: Pressed - opacity: 1 - } - } - ] -} diff --git a/demos/declarative/flickr/content/MediaLineEdit.qml b/demos/declarative/flickr/content/MediaLineEdit.qml deleted file mode 100644 index 500a402..0000000 --- a/demos/declarative/flickr/content/MediaLineEdit.qml +++ /dev/null @@ -1,109 +0,0 @@ -import Qt 4.6 - -Item { - id: Container - - property string label - property string text - - width: Math.max(94,Label.width + Editor.width + 20) - height: Image.height - - states: [ - State { - name: "Edit" - PropertyChanges { - target: Label - text: Container.label + ": " - } - PropertyChanges { - target: Label - x: 10 - } - PropertyChanges { - target: Editor - cursorVisible: true - width: 100 - } - PropertyChanges { - target: Proxy - focus: true - } - StateChangeScript { - script:"Editor.selectAll()" - } - }, - State { - // When returning to default state, typed text is propagated - StateChangeScript { - script: "Container.text = Editor.text" - } - } - ] - transitions: [ - Transition { - NumberAnimation { properties: "x,width"; duration: 500; easing: "easeInOutQuad" } - } - ] - - - BorderImage { - id: Image - source: "pics/button.sci" - anchors.left: Container.left - anchors.right: Container.right - } - - BorderImage { - id: Pressed - source: "pics/button-pressed.sci" - opacity: 0 - anchors.left: Container.left - anchors.right: Container.right - } - - MouseRegion { - id: MouseRegion - anchors.fill: Image - onClicked: { Container.state = Container.state=="Edit" ? "" : "Edit" } - states: [ - State { - when: MouseRegion.pressed == true - PropertyChanges { - target: Pressed - opacity: 1 - } - } - ] - } - - Text { - id: Label - font.bold: true - color: "white" - anchors.verticalCenter: Container.verticalCenter - x: (Container.width - width)/2 - text: Container.label + "..." - } - - TextInput { - id: Editor - font.bold: true - color: "white" - highlightColor: "green" - width: 0 - clip: true - anchors.left: Label.right - anchors.verticalCenter: Container.verticalCenter - } - KeyProxy { - id: Proxy - anchors.left: Container.left - anchors.fill: Container - targets: [(ReturnKey), (Editor)] - } - Item { - id: ReturnKey - Keys.onReturnPressed: "Container.state = ''" - } -} diff --git a/demos/declarative/flickr/content/Progress.qml b/demos/declarative/flickr/content/Progress.qml deleted file mode 100644 index 00ef901..0000000 --- a/demos/declarative/flickr/content/Progress.qml +++ /dev/null @@ -1,35 +0,0 @@ -import Qt 4.6 - -Item { - id: Progress; - - property var progress: 0 - - Rectangle { - id: Container; anchors.fill: parent; smooth: true - border.color: "white"; border.width: 0; radius: height/2 - 2 - gradient: Gradient { - GradientStop { position: 0; color: "#66343434" } - GradientStop { position: 1.0; color: "#66000000" } - } - } - - Rectangle { - id: Fill - y: 2; height: parent.height-4; - x: 2; width: Math.max(parent.width * progress - 4, 0); - opacity: width < 1 ? 0 : 1; smooth: true - gradient: Gradient { - GradientStop { position: 0; color: "lightsteelblue" } - GradientStop { position: 1.0; color: "steelblue" } - } - radius: height/2 - 2 - } - - Text { - text: Math.round(progress * 100) + "%" - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - color: "white"; font.bold: true - } -} diff --git a/demos/declarative/flickr/content/ScrollBar.qml b/demos/declarative/flickr/content/ScrollBar.qml deleted file mode 100644 index 89d51e2..0000000 --- a/demos/declarative/flickr/content/ScrollBar.qml +++ /dev/null @@ -1,40 +0,0 @@ -import Qt 4.6 - -Item { - id: Container - - property var flickableArea - - Rectangle { - radius: 5 - color: "black" - opacity: 0.3 - border.color: "white" - border.width: 2 - x: 0 - y: flickableArea.pageYPosition * Container.height - width: parent.width - height: flickableArea.pageHeight * Container.height - } - states: [ - State { - name: "show" - when: flickableArea.moving - PropertyChanges { - target: Container - opacity: 1 - } - } - ] - transitions: [ - Transition { - from: "*" - to: "*" - NumberAnimation { - target: Container - properties: "opacity" - duration: 400 - } - } - ] -} diff --git a/demos/declarative/flickr/content/Slider.qml b/demos/declarative/flickr/content/Slider.qml deleted file mode 100644 index b88636d..0000000 --- a/demos/declarative/flickr/content/Slider.qml +++ /dev/null @@ -1,36 +0,0 @@ -import Qt 4.6 - -Item { - id: Slider; width: 400; height: 16 - - // value is read/write. - property real value - onValueChanged: { Handle.x = 2 + (value - minimum) * Slider.xMax / (maximum - minimum); } - property real maximum: 1 - property real minimum: 1 - property int xMax: Slider.width - Handle.width - 4 - - Rectangle { - id: Container; anchors.fill: parent - border.color: "white"; border.width: 0; radius: 8 - gradient: Gradient { - GradientStop { position: 0.0; color: "#66343434" } - GradientStop { position: 1.0; color: "#66000000" } - } - } - - Rectangle { - id: Handle; smooth: true - x: Slider.width / 2 - Handle.width / 2; y: 2; width: 30; height: Slider.height-4; radius: 6 - gradient: Gradient { - GradientStop { position: 0.0; color: "lightgray" } - GradientStop { position: 1.0; color: "gray" } - } - - MouseRegion { - anchors.fill: parent; drag.target: parent - drag.axis: "XAxis"; drag.minimumX: 2; drag.maximumX: Slider.xMax+2 - onPositionChanged: { value = (maximum - minimum) * (Handle.x-2) / Slider.xMax + minimum; } - } - } -} diff --git a/demos/declarative/flickr/content/Star.qml b/demos/declarative/flickr/content/Star.qml deleted file mode 100644 index 006e86ad..0000000 --- a/demos/declarative/flickr/content/Star.qml +++ /dev/null @@ -1,46 +0,0 @@ -import Qt 4.6 - -Item { - id: Container - width: 24 - height: 24 - - property int rating - property bool on - - signal clicked - - Image { - id: Image - source: "pics/ghns_star.png" - x: 6 - y: 7 - opacity: 0.4 - scale: 0.5 - } - MouseRegion { - anchors.fill: Container - onClicked: { Container.clicked() } - } - states: [ - State { - name: "on" - when: Container.on == true - PropertyChanges { - target: Image - opacity: 1 - scale: 1 - x: 1 - y: 0 - } - } - ] - transitions: [ - Transition { - NumberAnimation { - properties: "opacity,scale,x,y" - easing: "easeOutBounce" - } - } - ] -} diff --git a/demos/declarative/flickr/content/pics/background.png b/demos/declarative/flickr/content/pics/background.png deleted file mode 100644 index 5b37072..0000000 Binary files a/demos/declarative/flickr/content/pics/background.png and /dev/null differ diff --git a/demos/declarative/flickr/content/pics/button-pressed.png b/demos/declarative/flickr/content/pics/button-pressed.png deleted file mode 100644 index e434d32..0000000 Binary files a/demos/declarative/flickr/content/pics/button-pressed.png and /dev/null differ diff --git a/demos/declarative/flickr/content/pics/button-pressed.sci b/demos/declarative/flickr/content/pics/button-pressed.sci deleted file mode 100644 index d3b16e2..0000000 --- a/demos/declarative/flickr/content/pics/button-pressed.sci +++ /dev/null @@ -1,5 +0,0 @@ -gridLeft: 8 -gridTop: 4 -gridBottom: 4 -gridRight: 8 -imageFile: button.png diff --git a/demos/declarative/flickr/content/pics/button.png b/demos/declarative/flickr/content/pics/button.png deleted file mode 100644 index 56a63ce..0000000 Binary files a/demos/declarative/flickr/content/pics/button.png and /dev/null differ diff --git a/demos/declarative/flickr/content/pics/button.sci b/demos/declarative/flickr/content/pics/button.sci deleted file mode 100644 index d3b16e2..0000000 --- a/demos/declarative/flickr/content/pics/button.sci +++ /dev/null @@ -1,5 +0,0 @@ -gridLeft: 8 -gridTop: 4 -gridBottom: 4 -gridRight: 8 -imageFile: button.png diff --git a/demos/declarative/flickr/content/pics/ghns_star.png b/demos/declarative/flickr/content/pics/ghns_star.png deleted file mode 100644 index 4ad43cc..0000000 Binary files a/demos/declarative/flickr/content/pics/ghns_star.png and /dev/null differ diff --git a/demos/declarative/flickr/content/pics/loading.png b/demos/declarative/flickr/content/pics/loading.png deleted file mode 100644 index 47a1589..0000000 Binary files a/demos/declarative/flickr/content/pics/loading.png and /dev/null differ diff --git a/demos/declarative/flickr/content/pics/reflection.png b/demos/declarative/flickr/content/pics/reflection.png deleted file mode 100644 index c143a48..0000000 Binary files a/demos/declarative/flickr/content/pics/reflection.png and /dev/null differ diff --git a/demos/declarative/flickr/content/pics/shadow-bottom.png b/demos/declarative/flickr/content/pics/shadow-bottom.png deleted file mode 100644 index 523f6e7..0000000 Binary files a/demos/declarative/flickr/content/pics/shadow-bottom.png and /dev/null differ diff --git a/demos/declarative/flickr/content/pics/shadow-corner.png b/demos/declarative/flickr/content/pics/shadow-corner.png deleted file mode 100644 index ef8c856..0000000 Binary files a/demos/declarative/flickr/content/pics/shadow-corner.png and /dev/null differ diff --git a/demos/declarative/flickr/content/pics/shadow-right-screen.png b/demos/declarative/flickr/content/pics/shadow-right-screen.png deleted file mode 100644 index 9856c4f..0000000 Binary files a/demos/declarative/flickr/content/pics/shadow-right-screen.png and /dev/null differ diff --git a/demos/declarative/flickr/content/pics/shadow-right.png b/demos/declarative/flickr/content/pics/shadow-right.png deleted file mode 100644 index f534a35..0000000 Binary files a/demos/declarative/flickr/content/pics/shadow-right.png and /dev/null differ diff --git a/demos/declarative/flickr/flickr-desktop.qml b/demos/declarative/flickr/flickr-desktop.qml new file mode 100644 index 0000000..5effc42 --- /dev/null +++ b/demos/declarative/flickr/flickr-desktop.qml @@ -0,0 +1,192 @@ +import Qt 4.6 + +import "common" + +Item { + id: MainWindow; width: 800; height: 450 + + property bool showPathView : false + + resources: [ + Component { + id: PhotoDelegate + Item { + id: Wrapper; width: 85; height: 85 + scale: Wrapper.PathView.scale; z: Wrapper.PathView.z + + transform: Rotation { + id: Rotation; origin.x: Wrapper.width/2; origin.y: Wrapper.height/2 + axis.y: 1; axis.z: 0; angle: Wrapper.PathView.angle + } + + Connection { + sender: ImageDetails; signal: "closed()" + script: { + if (Wrapper.state == 'Details') { + Wrapper.state = ''; + ImageDetails.photoUrl = ""; + } + } + } + + Script { + function photoClicked() { + ImageDetails.photoTitle = title; + ImageDetails.photoDescription = description; + ImageDetails.photoTags = tags; + ImageDetails.photoWidth = photoWidth; + ImageDetails.photoHeight = photoHeight; + ImageDetails.photoType = photoType; + ImageDetails.photoAuthor = photoAuthor; + ImageDetails.photoDate = photoDate; + ImageDetails.photoUrl = url; + ImageDetails.rating = 0; + Wrapper.state = "Details"; + } + } + + Rectangle { + id: WhiteRect; anchors.fill: parent; color: "white"; radius: 5 + + Loading { x: 26; y: 26; visible: Thumb.status!=1 } + Image { id: Thumb; source: imagePath; x: 5; y: 5 } + + Item { + id: Shadows + Image { source: "common/pics/shadow-right.png"; x: WhiteRect.width; height: WhiteRect.height } + Image { source: "common/pics/shadow-bottom.png"; y: WhiteRect.height; width: WhiteRect.width } + Image { id: Corner; source: "common/pics/shadow-corner.png"; x: WhiteRect.width; y: WhiteRect.height } + } + } + + MouseRegion { anchors.fill: Wrapper; onClicked: { photoClicked() } } + + states: [ + State { + name: "Details" + PropertyChanges { target: ImageDetails; z: 2 } + ParentChange { target: Wrapper; parent: ImageDetails.frontContainer } + PropertyChanges { target: Wrapper; x: 45; y: 35; scale: 1; z: 1000 } + PropertyChanges { target: Rotation; angle: 0 } + PropertyChanges { target: Shadows; opacity: 0 } + PropertyChanges { target: ImageDetails; y: 20 } + PropertyChanges { target: PhotoGridView; y: "-480" } + PropertyChanges { target: PhotoPathView; y: "-480" } + PropertyChanges { target: ViewModeButton; opacity: 0 } + PropertyChanges { target: TagsEdit; opacity: 0 } + PropertyChanges { target: FetchButton; opacity: 0 } + PropertyChanges { target: CategoryText; y: "-50" } + } + ] + + transitions: [ + Transition { + from: "*"; to: "Details" + ParentAction { } + NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" } + }, + Transition { + from: "Details"; to: "*" + SequentialAnimation { + ParentAction { } + NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" } + PropertyAction { target: Wrapper; properties: "z" } + } + } + ] + + } + } + ] + + Item { + id: Background + + anchors.fill: parent + + Image { source: "common/pics/background.png"; anchors.fill: parent } + RssModel { id: RssModel; tags : TagsEdit.text } + Loading { anchors.centerIn: parent; visible: RssModel.status } + + GridView { + id: PhotoGridView; model: RssModel; delegate: PhotoDelegate; cacheBuffer: 100 + cellWidth: 105; cellHeight: 105; x:32; y: 80; width: 800; height: 330; z: 1 + } + + PathView { + id: PhotoPathView; model: RssModel; delegate: PhotoDelegate + y: -380; width: 800; height: 330; pathItemCount: 10; z: 1 + path: Path { + startX: -50; startY: 40; + + PathAttribute { name: "scale"; value: 1 } + PathAttribute { name: "angle"; value: -45 } + + PathCubic { + x: 400; y: 220 + control1X: 140; control1Y: 40 + control2X: 210; control2Y: 220 + } + + PathAttribute { name: "scale"; value: 1.2 } + PathAttribute { name: "z"; value: 1 } + PathAttribute { name: "angle"; value: 0 } + + PathCubic { + x: 850; y: 40 + control2X: 660; control2Y: 40 + control1X: 590; control1Y: 220 + } + + PathAttribute { name: "scale"; value: 1 } + PathAttribute { name: "angle"; value: 45 } + } + + } + + ImageDetails { id: ImageDetails; width: 750; x: 25; y: 500; height: 410 } + + MediaButton { + id: ViewModeButton; x: 680; y: 410; text: "View Mode" + onClicked: { if (MainWindow.showPathView == true) MainWindow.showPathView = false; else MainWindow.showPathView = true } + } + + MediaButton { + id: FetchButton + text: "Update" + anchors.right: ViewModeButton.left; anchors.rightMargin: 5 + anchors.top: ViewModeButton.top + onClicked: { RssModel.reload(); } + } + + MediaLineEdit { + id: TagsEdit; + label: "Tags" + anchors.right: FetchButton.left; anchors.rightMargin: 5 + anchors.top: ViewModeButton.top + } + + states: [ + State { + name: "PathView" + when: MainWindow.showPathView == true + PropertyChanges { target: PhotoPathView; y: 80 } + PropertyChanges { target: PhotoGridView; y: -380 } + } + ] + + transitions: [ + Transition { + from: "*"; to: "*" + NumberAnimation { properties: "y"; duration: 1000; easing: "easeOutBounce(amplitude:0.5)" } + } + ] + } + + Text { + id: CategoryText; anchors.horizontalCenter: parent.horizontalCenter; y: 15; + text: "Flickr - " + + (RssModel.tags=="" ? "Uploads from everyone" : "Recent Uploads tagged " + RssModel.tags) + font.pointSize: 20; font.bold: true; color: "white"; style: "Raised"; styleColor: "black" + } +} diff --git a/demos/declarative/flickr/flickr-mobile.qml b/demos/declarative/flickr/flickr-mobile.qml new file mode 100644 index 0000000..a4692a3 --- /dev/null +++ b/demos/declarative/flickr/flickr-mobile.qml @@ -0,0 +1,51 @@ +import Qt 4.6 +import "common" as Common +import "mobile" as Mobile + +Item { + id: Screen; width: 320; height: 480 + property bool inListView : false + + Rectangle { + id: Background + anchors.fill: parent; color: "#343434"; + + Image { source: "mobile/images/stripes.png"; fillMode: "Tile"; anchors.fill: parent; opacity: 0.3 } + + Common.RssModel { id: RssModel } + Common.Loading { anchors.centerIn: parent; visible: RssModel.status } + + Item { + id: Views + x: 2; width: parent.width - 4 + anchors.top: TitleBar.bottom; anchors.bottom: ToolBar.top + + Mobile.GridDelegate { id: GridDelegate } + GridView { + id: PhotoGridView; model: RssModel; delegate: GridDelegate; cacheBuffer: 100 + cellWidth: 79; cellHeight: 79; width: parent.width; height: parent.height - 1 + } + + Mobile.ListDelegate { id: ListDelegate } + ListView { + id: PhotoListView; model: RssModel; delegate: ListDelegate + width: parent.width; height: parent.height; x: -(parent.width * 1.5); cacheBuffer: 100; + } + } + + Common.ImageDetails { id: ImageDetails; width: parent.width; x: parent.width; height: parent.height } + Mobile.TitleBar { id: TitleBar; width: parent.width; height: 40; opacity: 0.9 } + Mobile.ToolBar { id: ToolBar; height: 40; anchors.bottom: parent.bottom; width: parent.width; opacity: 0.9 } + + states: [ + State { + name: "ListView"; when: Screen.inListView == true + PropertyChanges { target: PhotoListView; x: 0 } + PropertyChanges { target: PhotoGridView; x: -(parent.width * 1.5) } + } + ] + transitions: [ + Transition { NumberAnimation { properties: "x"; duration: 500; easing: "easeInOutQuad" } } + ] + } +} diff --git a/demos/declarative/flickr/flickr.qml b/demos/declarative/flickr/flickr.qml deleted file mode 100644 index d8a27d5..0000000 --- a/demos/declarative/flickr/flickr.qml +++ /dev/null @@ -1,211 +0,0 @@ -import Qt 4.6 - -import "content" - -Item { - id: MainWindow; width: 800; height: 450 - - property bool showPathView : false - - resources: [ - XmlListModel { - id: FeedModel - property string tags : TagsEdit.text - source: "http://api.flickr.com/services/feeds/photos_public.gne?"+(tags ? "tags="+tags+"&" : "")+"format=rss2" - query: "/rss/channel/item" - namespaceDeclarations: "declare namespace media=\"http://search.yahoo.com/mrss/\";" - - XmlRole { name: "title"; query: "title/string()" } - XmlRole { name: "imagePath"; query: "media:thumbnail/@url/string()" } - XmlRole { name: "url"; query: "media:content/@url/string()" } - XmlRole { name: "description"; query: "description/string()" } - XmlRole { name: "tags"; query: "media:category/string()" } - XmlRole { name: "photoWidth"; query: "media:content/@width/string()" } - XmlRole { name: "photoHeight"; query: "media:content/@height/string()" } - XmlRole { name: "photoType"; query: "media:content/@type/string()" } - XmlRole { name: "photoAuthor"; query: "author/string()" } - XmlRole { name: "photoDate"; query: "pubDate/string()" } - }, - - Component { - id: PhotoDelegate - Item { - id: Wrapper; width: 85; height: 85 - scale: Wrapper.PathView.scale; z: Wrapper.PathView.z - - transform: Rotation { - id: Rotation; origin.x: Wrapper.width/2; origin.y: Wrapper.height/2 - axis.y: 1; axis.z: 0; angle: Wrapper.PathView.angle - } - - Connection { - sender: ImageDetails; signal: "closed()" - script: { - if (Wrapper.state == 'Details') { - Wrapper.state = ''; - ImageDetails.photoUrl = ""; - } - } - } - - Script { - function photoClicked() { - ImageDetails.photoTitle = title; - ImageDetails.photoDescription = description; - ImageDetails.photoTags = tags; - ImageDetails.photoWidth = photoWidth; - ImageDetails.photoHeight = photoHeight; - ImageDetails.photoType = photoType; - ImageDetails.photoAuthor = photoAuthor; - ImageDetails.photoDate = photoDate; - ImageDetails.photoUrl = url; - ImageDetails.rating = 0; - Wrapper.state = "Details"; - } - } - - Rectangle { - id: WhiteRect; anchors.fill: parent; color: "white"; radius: 5 - - Loading { x: 26; y: 26; visible: Thumb.status!=1 } - Image { id: Thumb; source: imagePath; x: 5; y: 5 } - - Item { - id: Shadows - Image { source: "content/pics/shadow-right.png"; x: WhiteRect.width; height: WhiteRect.height } - Image { source: "content/pics/shadow-bottom.png"; y: WhiteRect.height; width: WhiteRect.width } - Image { id: Corner; source: "content/pics/shadow-corner.png"; x: WhiteRect.width; y: WhiteRect.height } - } - } - - MouseRegion { anchors.fill: Wrapper; onClicked: { photoClicked() } } - - states: [ - State { - name: "Details" - PropertyChanges { target: ImageDetails; z: 2 } - ParentChange { target: Wrapper; parent: ImageDetails.frontContainer } - PropertyChanges { target: Wrapper; x: 45; y: 35; scale: 1; z: 1000 } - PropertyChanges { target: Rotation; angle: 0 } - PropertyChanges { target: Shadows; opacity: 0 } - PropertyChanges { target: ImageDetails; y: 20 } - PropertyChanges { target: PhotoGridView; y: "-480" } - PropertyChanges { target: PhotoPathView; y: "-480" } - PropertyChanges { target: ViewModeButton; opacity: 0 } - PropertyChanges { target: TagsEdit; opacity: 0 } - PropertyChanges { target: FetchButton; opacity: 0 } - PropertyChanges { target: CategoryText; y: "-50" } - } - ] - - transitions: [ - Transition { - from: "*"; to: "Details" - ParentAction { } - NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" } - }, - Transition { - from: "Details"; to: "*" - SequentialAnimation { - ParentAction { } - NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" } - PropertyAction { target: Wrapper; properties: "z" } - } - } - ] - - } - } - ] - - Item { - id: Background - - anchors.fill: parent - - Image { source: "content/pics/background.png"; anchors.fill: parent } - - Loading { anchors.centerIn: parent; visible: FeedModel.status } - - GridView { - id: PhotoGridView; model: FeedModel; delegate: PhotoDelegate; cacheBuffer: 100 - cellWidth: 105; cellHeight: 105; x:32; y: 80; width: 800; height: 330; z: 1 - } - - PathView { - id: PhotoPathView; model: FeedModel; delegate: PhotoDelegate - y: -380; width: 800; height: 330; pathItemCount: 10; z: 1 - path: Path { - startX: -50; startY: 40; - - PathAttribute { name: "scale"; value: 1 } - PathAttribute { name: "angle"; value: -45 } - - PathCubic { - x: 400; y: 220 - control1X: 140; control1Y: 40 - control2X: 210; control2Y: 220 - } - - PathAttribute { name: "scale"; value: 1.2 } - PathAttribute { name: "z"; value: 1 } - PathAttribute { name: "angle"; value: 0 } - - PathCubic { - x: 850; y: 40 - control2X: 660; control2Y: 40 - control1X: 590; control1Y: 220 - } - - PathAttribute { name: "scale"; value: 1 } - PathAttribute { name: "angle"; value: 45 } - } - - } - - ImageDetails { id: ImageDetails; width: 750; x: 25; y: 500; height: 410 } - - MediaButton { - id: ViewModeButton; x: 680; y: 410; text: "View Mode" - onClicked: { if (MainWindow.showPathView == true) MainWindow.showPathView = false; else MainWindow.showPathView = true } - } - - MediaButton { - id: FetchButton - text: "Update" - anchors.right: ViewModeButton.left; anchors.rightMargin: 5 - anchors.top: ViewModeButton.top - onClicked: { FeedModel.reload(); } - } - - MediaLineEdit { - id: TagsEdit; - label: "Tags" - anchors.right: FetchButton.left; anchors.rightMargin: 5 - anchors.top: ViewModeButton.top - } - - states: [ - State { - name: "PathView" - when: MainWindow.showPathView == true - PropertyChanges { target: PhotoPathView; y: 80 } - PropertyChanges { target: PhotoGridView; y: -380 } - } - ] - - transitions: [ - Transition { - from: "*"; to: "*" - NumberAnimation { properties: "y"; duration: 1000; easing: "easeOutBounce(amplitude:0.5)" } - } - ] - } - - Text { - id: CategoryText; anchors.horizontalCenter: parent.horizontalCenter; y: 15; - text: "Flickr - " + - (FeedModel.tags=="" ? "Uploads from everyone" : "Recent Uploads tagged " + FeedModel.tags) - font.pointSize: 20; font.bold: true; color: "white"; style: "Raised"; styleColor: "black" - } -} diff --git a/demos/declarative/flickr/flickr2.qml b/demos/declarative/flickr/flickr2.qml deleted file mode 100644 index d9b1f60..0000000 --- a/demos/declarative/flickr/flickr2.qml +++ /dev/null @@ -1,261 +0,0 @@ -import Qt 4.6 - -import "content" - -Item { - id: MainWindow; width: 800; height: 450 - - property bool showPathView : false - - VisualModel { - id: MyVisualModel - model: - XmlListModel { - id: FeedModel - property string tags : TagsEdit.text - source: "http://api.flickr.com/services/feeds/photos_public.gne?"+(tags ? "tags="+tags+"&" : "")+"format=rss2" - query: "/rss/channel/item" - namespaceDeclarations: "declare namespace media=\"http://search.yahoo.com/mrss/\";" - - XmlRole { name: "title"; query: "title/string()" } - XmlRole { name: "imagePath"; query: "media:thumbnail/@url/string()" } - XmlRole { name: "url"; query: "media:content/@url/string()" } - XmlRole { name: "description"; query: "description/string()" } - XmlRole { name: "tags"; query: "media:category/string()" } - XmlRole { name: "photoWidth"; query: "media:content/@width/string()" } - XmlRole { name: "photoHeight"; query: "media:content/@height/string()" } - XmlRole { name: "photoType"; query: "media:content/@type/string()" } - XmlRole { name: "photoAuthor"; query: "author/string()" } - XmlRole { name: "photoDate"; query: "pubDate/string()" } - } - - delegate: Package { - Item { - id: Wrapper; width: 85; height: 85; scale: {1.0} - z: PathViewPackage.PathView.z - property real angle: 0 * 0 - - transform: [ - Rotation { - id: Rotation; origin.x: 30; axis.x: 30; axis.y: 60; axis.z: 0 - angle: Wrapper.angle - } - ] - - Connection { - sender: Background.imageDetails; signal: "closed()" - script: { if (Wrapper.state == 'Details') Wrapper.state = '' } - } - - Script { - function photoClicked() { - Background.imageDetails.photoTitle = title; - Background.imageDetails.photoDescription = description; - Background.imageDetails.photoTags = tags; - Background.imageDetails.photoWidth = photoWidth; - Background.imageDetails.photoHeight = photoHeight; - Background.imageDetails.photoType = photoType; - Background.imageDetails.photoAuthor = photoAuthor; - Background.imageDetails.photoDate = photoDate; - Background.imageDetails.photoUrl = url; - Background.imageDetails.rating = 0; - Wrapper.state = "Details"; - } - } - - Rectangle { - id: WhiteRect; anchors.fill: parent; color: "white"; radius: 5 - - Loading { x: 26; y: 26; visible: Thumb.status!=1 } - Image { id: Thumb; source: imagePath; x: 5; y: 5 } - - Item { - id: Shadows - Image { source: "content/pics/shadow-right.png"; x: WhiteRect.width; height: WhiteRect.height } - Image { source: "content/pics/shadow-bottom.png"; y: WhiteRect.height; width: WhiteRect.width } - Image { id: Corner; source: "content/pics/shadow-corner.png"; x: WhiteRect.width; y: WhiteRect.height } - } - } - - MouseRegion { anchors.fill: Wrapper; onClicked: { photoClicked() } } - - states: [ - State { - name: "Details" - PropertyChanges { target: Background.imageDetails; z: 2 } - ParentChange { target: Wrapper; parent: Background.imageDetails.frontContainer } - PropertyChanges { target: Wrapper; x: 45; y: 35; scale: 1; z: 1000 } - PropertyChanges { target: Rotation; angle: 0 } - PropertyChanges { target: Shadows; opacity: 0 } - PropertyChanges { target: Background.imageDetails; y: 20 } - PropertyChanges { target: PhotoGridView; y: "-480" } - PropertyChanges { target: PhotoPathView; y: "-480" } - PropertyChanges { target: ViewModeButton; opacity: 0 } - PropertyChanges { target: TagsEdit; opacity: 0 } - PropertyChanges { target: FetchButton; opacity: 0 } - PropertyChanges { target: CategoryText; y: "-50" } - } - ] - - transitions: [ - Transition { - from: "*"; to: "Details" - ParentAction { } - NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" } - }, - Transition { - from: "Details"; to: "*" - SequentialAnimation { - ParentAction { } - NumberAnimation { properties: "x,y,scale,opacity,angle"; duration: 500; easing: "easeInOutQuad" } - PropertyAction { target: Wrapper; properties: "z" } - } - } - ] - } - - Item { - Package.name: "pathView" - id: PathViewPackage; width: 85; height: 85 - } - - Item { - Package.name: "gridView" - id: GridViewPackage; width: 85; height: 85 - } - - Item { - id: MyItem - state: MainWindow.showPathView ? "pathView" : "gridView" - states: [ - State { - name: "gridView" - PropertyChanges { target: Wrapper; explicit: true; property: "moveToParent"; value: GridViewPackage } - }, - State { - name: "pathView" - PropertyChanges { target: Wrapper; scale: PathViewPackage.PathView.scale; angle: PathViewPackage.PathView.angle; } - PropertyChanges { target: Wrapper; explicit: true; moveToParent: PathViewPackage } - } - ] - transitions: [ - Transition { - to: "pathView" - SequentialAnimation { - PropertyAction { target: Wrapper; property: "moveToParent" } - ParallelAnimation { - NumberAnimation { - target: Wrapper - properties: "x,y" - to: 0 - easing: "easeOutQuad" - duration: 350 - } - NumberAnimation { target: Wrapper; properties: "scale,angle"; duration: 350 } - } - } - }, - Transition { - to: "gridView" - SequentialAnimation { - PauseAnimation { duration: Math.floor(index/7)*100 } - PropertyAction { target: Wrapper; property: "moveToParent" } - ParallelAnimation { - NumberAnimation { - target: Wrapper - properties: "x,y" - to: 0 - easing: "easeOutQuad" - duration: 250 - } - NumberAnimation { target: Wrapper; properties: "scale,angle"; duration: 250 } - } - } - } - ] - } - } - } - - - Item { - id: Background - property var imageDetails: ImageDetails - - Image { source: "content/pics/background.png" } - - GridView { - id: PhotoGridView; model: MyVisualModel.parts.gridView - cellWidth: 105; cellHeight: 105; x:32; y: 80; width: 800; height: 330; z: 1 - cacheBuffer: 100 - } - - PathView { - id: PhotoPathView; model: MyVisualModel.parts.pathView - y: 80; width: 800; height: 330; z: 1 - pathItemCount: 10; snapPosition: 0.001 - path: Path { - startX: -150; startY: 40; - - PathAttribute { name: "scale"; value: 0.9 } - PathAttribute { name: "angle"; value: -45 } - PathPercent { value: 0 } - PathLine { x: -50; y: 40 } - - PathPercent { value: 0.001 } - - PathCubic { - x: 400; y: 220 - control1X: 140; control1Y: 40 - control2X: 210; control2Y: 220 - } - - PathAttribute { name: "scale"; value: 1.2 } - PathAttribute { name: "z"; value: 1 } - PathAttribute { name: "angle"; value: 0 } - - PathCubic { - x: 850; y: 40 - control2X: 660; control2Y: 40 - control1X: 590; control1Y: 220 - } - - PathPercent { value: 0.999 } - PathLine { x: 950; y: 40 } - PathPercent { value: 1.0 } - PathAttribute { name: "scale"; value: 0.9 } - PathAttribute { name: "angle"; value: 45 } - } - } - - ImageDetails { id: ImageDetails; width: 750; x: 25; y: 500; height: 410 } - - MediaButton { - id: ViewModeButton; x: 680; y: 410; text: "View Mode" - onClicked: { if (MainWindow.showPathView == true) MainWindow.showPathView = false; else MainWindow.showPathView = true } - } - - MediaButton { - id: FetchButton - text: "Update" - anchors.right: ViewModeButton.left; anchors.rightMargin: 5 - anchors.top: ViewModeButton.top - onClicked: { FeedModel.reload(); } - } - - MediaLineEdit { - id: TagsEdit; - label: "Tags" - anchors.right: FetchButton.left; anchors.rightMargin: 5 - anchors.top: ViewModeButton.top - } - - } - - Text { - id: CategoryText; anchors.horizontalCenter: parent.horizontalCenter; y: 15; - text: "Flickr - " + - (FeedModel.tags=="" ? "Uploads from everyone" : "Recent Uploads tagged " + FeedModel.tags) - font.pointSize: 16; font.bold: true; color: "white"; style: "Raised"; styleColor: "black" - } -} diff --git a/demos/declarative/flickr/mobile/Button.qml b/demos/declarative/flickr/mobile/Button.qml new file mode 100644 index 0000000..275408c --- /dev/null +++ b/demos/declarative/flickr/mobile/Button.qml @@ -0,0 +1,41 @@ +import Qt 4.6 + +Item { + id: Container + + signal clicked + + property string text + + BorderImage { + id: Image + source: "images/toolbutton2.sci" + width: Container.width; height: Container.height + } + BorderImage { + id: Pressed + opacity: 0 + source: "images/toolbutton2.sci" + width: Container.width; height: Container.height + } + MouseRegion { + id: MouseRegion + anchors.fill: Image + onClicked: { Container.clicked(); } + } + Text { + color: "white" + anchors.centerIn: Image; font.bold: true + text: Container.text; style: "Raised"; styleColor: "black" + } + states: [ + State { + name: "Pressed" + when: MouseRegion.pressed == true + PropertyChanges { + target: Pressed + opacity: 1 + } + } + ] +} diff --git a/demos/declarative/flickr/mobile/GridDelegate.qml b/demos/declarative/flickr/mobile/GridDelegate.qml new file mode 100644 index 0000000..8090cd4 --- /dev/null +++ b/demos/declarative/flickr/mobile/GridDelegate.qml @@ -0,0 +1,74 @@ + import Qt 4.6 + + Component { + id: PhotoDelegate + Item { + id: Wrapper; width: 79; height: 79 + + Script { + function photoClicked() { + ImageDetails.photoTitle = title; + ImageDetails.photoDescription = description; + ImageDetails.photoTags = tags; + ImageDetails.photoWidth = photoWidth; + ImageDetails.photoHeight = photoHeight; + ImageDetails.photoType = photoType; + ImageDetails.photoAuthor = photoAuthor; + ImageDetails.photoDate = photoDate; + ImageDetails.photoUrl = url; + ImageDetails.rating = 0; + ScaleMe.state = "Details"; + } + } + + Item { + anchors.centerIn: parent + scale: 0.0 + scale: Behavior { NumberAnimation { easing: "easeInOutQuad"} } + id: ScaleMe + + Rectangle { height: 79; width: 79; id: BlackRect; anchors.centerIn: parent; color: "black"; smooth: true } + Rectangle { + id: WhiteRect; width: 77; height: 77; anchors.centerIn: parent; color: "#dddddd"; smooth: true + Image { id: Thumb; source: imagePath; x: 1; y: 1; smooth: true} + Image { source: "mobile/images/gloss.png"; smooth: true} + } + + Connection { + sender: ToolBar.button2; signal: "clicked()" + script: if (ScaleMe.state == 'Details' ) ScaleMe.state = 'Show'; + } + + states: [ + State { + name: "Show"; when: Thumb.status == 1 + PropertyChanges { target: ScaleMe; scale: 1 } + }, + State { + name: "Details"; extend: "Show" + ParentChange { target: Wrapper; parent: ImageDetails.frontContainer } + PropertyChanges { target: Wrapper; x: 20; y: 60 } + PropertyChanges { target: ImageDetails; x: 0 } + PropertyChanges { target: Views; x: -parent.width } + PropertyChanges { target: ToolBar.button2; text: "Back" } + } + ] + transitions: [ + Transition { + from: "Show"; to: "Details" + ParentAction { } + NumberAnimation { properties: "x,y,opacity,angle"; duration: 500; easing: "easeInOutQuad" } + }, + Transition { + from: "Details"; to: "Show" + SequentialAnimation { + ParentAction { } + NumberAnimation { properties: "x,y,opacity,angle"; duration: 500; easing: "easeInOutQuad" } + PropertyAction { target: Wrapper; properties: "z" } + } + } + ] + } + MouseRegion { anchors.fill: Wrapper; onClicked: { photoClicked() } } + } + } diff --git a/demos/declarative/flickr/mobile/ListDelegate.qml b/demos/declarative/flickr/mobile/ListDelegate.qml new file mode 100644 index 0000000..b9ec7f2 --- /dev/null +++ b/demos/declarative/flickr/mobile/ListDelegate.qml @@ -0,0 +1,24 @@ +import Qt 4.6 + +Component { + id: ListDelegate + Item { + id: Wrapper; width: Wrapper.ListView.view.width; height: 86 + Item { + id: MoveMe + Rectangle { color: "black"; opacity: Wrapper.ListView.index % 2 ? 0.2 : 0.3; height: 84; width: Wrapper.width; y: 1 } + Rectangle { + id: WhiteRect; x: 6; y: 4; width: 77; height: 77; color: "white"; smooth: true + + Image { id: Thumb; source: imagePath; x: 1; y: 1 } + Image { source: "images/gloss.png" } + } + Column { + x: 92; width: Wrapper.ListView.view.width - 95; y: 15; spacing: 2 + Text { text: title; color: "white"; width: parent.width; font.bold: true; elide: "ElideRight"; style: "Raised"; styleColor: "black" } + Text { text: photoAuthor; color: "white"; width: parent.width; elide: "ElideLeft"; color: "#cccccc"; style: "Raised"; styleColor: "black" } + Text { text: photoDate; color: "white"; width: parent.width; elide: "ElideRight"; color: "#cccccc"; style: "Raised"; styleColor: "black" } + } + } + } +} diff --git a/demos/declarative/flickr/mobile/TitleBar.qml b/demos/declarative/flickr/mobile/TitleBar.qml new file mode 100644 index 0000000..59b8365 --- /dev/null +++ b/demos/declarative/flickr/mobile/TitleBar.qml @@ -0,0 +1,74 @@ +import Qt 4.6 + +Item { + id: TitleBar + + BorderImage { source: "images/titlebar2.sci"; width: parent.width; height: parent.height + 14; y: -7 } + + Item { + id: Container + width: (parent.width * 2) - 55 ; height: parent.height + + Script { + function accept() { + RssModel.tags = Editor.text + TitleBar.state = "" + } + } + + Text { + id: CategoryText + anchors.left: parent.left; anchors.right: TagButton.left + anchors.leftMargin: 10; anchors.rightMargin: 10 + anchors.verticalCenter: parent.verticalCenter + elide: "ElideLeft" + text: (RssModel.tags=="" ? "Uploads from everyone" : "Recent Uploads tagged " + RssModel.tags) + font.pointSize: 10; font.bold: true; color: "white"; style: "Raised"; styleColor: "black" + } + + Button { + id: TagButton; x: TitleBar.width - 50; y: 3; width: 45; height: 32; text: "..." + onClicked: if (TitleBar.state == "Tags") accept(); else TitleBar.state = "Tags" + } + + Item { + id: LineEdit + anchors.left: TagButton.right; anchors.leftMargin: 5; y: 4 + anchors.right: parent.right; anchors.rightMargin: 5; height: parent.height - 9 + BorderImage { source: "images/lineedit.sci"; anchors.fill: parent } + + TextInput { + id: Editor + anchors.left: parent.left; anchors.right: parent.right + anchors.leftMargin: 10; anchors.rightMargin: 10 + anchors.verticalCenter: parent.verticalCenter + cursorVisible: true; font.bold: true + color: "#151515"; highlightColor: "green" + } + KeyProxy { + id: Proxy + anchors.fill: parent + targets: [(ReturnKey), (Editor)] + } + Item { + id: ReturnKey + Keys.onReturnPressed: accept() + Keys.onEscapePressed: TitleBar.state = "" + } + } + } + states: [ + State { + name: "Tags" + PropertyChanges { target: Container; x: -TagButton.x + 5 } + PropertyChanges { target: TagButton; text: "OK" } + PropertyChanges { target: Proxy; focus: true } + } + ] + transitions: [ + Transition { + from: "*"; to: "*" + NumberAnimation { properties: "x"; easing: "easeInOutQuad" } + } + ] +} diff --git a/demos/declarative/flickr/mobile/ToolBar.qml b/demos/declarative/flickr/mobile/ToolBar.qml new file mode 100644 index 0000000..aa78c52 --- /dev/null +++ b/demos/declarative/flickr/mobile/ToolBar.qml @@ -0,0 +1,23 @@ +import Qt 4.6 + +Item { + id: Toolbar + property var button2: Button2 + + BorderImage { source: "images/titlebar2.sci"; width: parent.width; height: parent.height + 14; y: -7 } + + Button { anchors.left: parent.left; anchors.leftMargin: 5; y: 3; width: 140; height: 32; text: "Update"; onClicked: RssModel.reload() } + + Button { + id: Button2 + anchors.right: parent.right; anchors.rightMargin: 5; y: 3; width: 140; height: 32; text: "View mode" + onClicked: { + if (Button2.text == "View mode") { + if (Screen.inListView == true) + Screen.inListView = false; + else + Screen.inListView = true + } + } + } +} diff --git a/demos/declarative/flickr/mobile/images/gloss.png b/demos/declarative/flickr/mobile/images/gloss.png new file mode 100644 index 0000000..5d370cd Binary files /dev/null and b/demos/declarative/flickr/mobile/images/gloss.png differ diff --git a/demos/declarative/flickr/mobile/images/lineedit.png b/demos/declarative/flickr/mobile/images/lineedit.png new file mode 100644 index 0000000..2cc38dc Binary files /dev/null and b/demos/declarative/flickr/mobile/images/lineedit.png differ diff --git a/demos/declarative/flickr/mobile/images/lineedit.sci b/demos/declarative/flickr/mobile/images/lineedit.sci new file mode 100644 index 0000000..7c5ec6c --- /dev/null +++ b/demos/declarative/flickr/mobile/images/lineedit.sci @@ -0,0 +1,5 @@ +gridLeft: 10 +gridTop: 10 +gridBottom: 10 +gridRight: 10 +imageFile: lineedit.png diff --git a/demos/declarative/flickr/mobile/images/stripes.png b/demos/declarative/flickr/mobile/images/stripes.png new file mode 100644 index 0000000..9f36727 Binary files /dev/null and b/demos/declarative/flickr/mobile/images/stripes.png differ diff --git a/demos/declarative/flickr/mobile/images/titlebar2.png b/demos/declarative/flickr/mobile/images/titlebar2.png new file mode 100644 index 0000000..51c9008 Binary files /dev/null and b/demos/declarative/flickr/mobile/images/titlebar2.png differ diff --git a/demos/declarative/flickr/mobile/images/titlebar2.sci b/demos/declarative/flickr/mobile/images/titlebar2.sci new file mode 100644 index 0000000..e8fc2d1 --- /dev/null +++ b/demos/declarative/flickr/mobile/images/titlebar2.sci @@ -0,0 +1,5 @@ +gridLeft: 22 +gridTop: 10 +gridBottom: 10 +gridRight: 22 +imageFile: titlebar2.png diff --git a/demos/declarative/flickr/mobile/images/toolbutton2.png b/demos/declarative/flickr/mobile/images/toolbutton2.png new file mode 100644 index 0000000..8862898 Binary files /dev/null and b/demos/declarative/flickr/mobile/images/toolbutton2.png differ diff --git a/demos/declarative/flickr/mobile/images/toolbutton2.sci b/demos/declarative/flickr/mobile/images/toolbutton2.sci new file mode 100644 index 0000000..e3118b0 --- /dev/null +++ b/demos/declarative/flickr/mobile/images/toolbutton2.sci @@ -0,0 +1,5 @@ +gridLeft: 15 +gridTop: 4 +gridBottom: 4 +gridRight: 15 +imageFile: toolbutton2.png -- cgit v0.12 From f69d8805291ee46856b21d9091693cdc139765b8 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 25 Aug 2009 11:22:16 +1000 Subject: Implement QFxKeyNavigationAttached class Documentation is missing until we fix up focus behaviour --- src/declarative/fx/qfxitem.cpp | 172 +++++++++++++++++++++++++++++++++-------- src/declarative/fx/qfxitem.h | 5 -- src/declarative/fx/qfxitem_p.h | 4 +- 3 files changed, 142 insertions(+), 39 deletions(-) diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 772449e..7938dc9 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -299,6 +299,50 @@ void QFxContents::setItem(QFxItem *item) calcWidth(); } +/* + Key filters can be installed on a QFxItem, but not removed. Currently they + are only used by attached objects (which are only destroyed on Item + destruction), so this isn't a problem. If in future this becomes any form + of public API, they will have to support removal too. +*/ +class QFxItemKeyFilter +{ +public: + QFxItemKeyFilter(QFxItem * = 0); + virtual ~QFxItemKeyFilter(); + + virtual void keyPressed(QKeyEvent *event); + virtual void keyReleased(QKeyEvent *event); + +private: + QFxItemKeyFilter *m_next; +}; + +QFxItemKeyFilter::QFxItemKeyFilter(QFxItem *item) +: m_next(0) +{ + QFxItemPrivate *p = + item?static_cast(QGraphicsItemPrivate::get(item)):0; + if (p) { + m_next = p->keyHandler; + p->keyHandler = this; + } +} + +QFxItemKeyFilter::~QFxItemKeyFilter() +{ +} + +void QFxItemKeyFilter::keyPressed(QKeyEvent *event) +{ + if (m_next) m_next->keyPressed(event); +} + +void QFxItemKeyFilter::keyReleased(QKeyEvent *event) +{ + if (m_next) m_next->keyReleased(event); +} + class QFxKeyNavigationAttachedPrivate : public QObjectPrivate { public: @@ -311,7 +355,7 @@ public: QFxItem *down; }; -class QFxKeyNavigationAttached : public QObject +class QFxKeyNavigationAttached : public QObject, public QFxItemKeyFilter { Q_OBJECT Q_DECLARE_PRIVATE(QFxKeyNavigationAttached); @@ -333,10 +377,18 @@ public: void setDown(QFxItem *); static QFxKeyNavigationAttached *qmlAttachedProperties(QObject *); + +signals: + void changed(); + +private: + virtual void keyPressed(QKeyEvent *event); + virtual void keyReleased(QKeyEvent *event); }; QFxKeyNavigationAttached::QFxKeyNavigationAttached(QObject *parent) -: QObject(*(new QFxKeyNavigationAttachedPrivate), parent) +: QObject(*(new QFxKeyNavigationAttachedPrivate), parent), + QFxItemKeyFilter(qobject_cast(parent)) { } @@ -356,6 +408,7 @@ void QFxKeyNavigationAttached::setLeft(QFxItem *i) { Q_D(QFxKeyNavigationAttached); d->left = i; + emit changed(); } QFxItem *QFxKeyNavigationAttached::right() const @@ -368,6 +421,7 @@ void QFxKeyNavigationAttached::setRight(QFxItem *i) { Q_D(QFxKeyNavigationAttached); d->right = i; + emit changed(); } QFxItem *QFxKeyNavigationAttached::up() const @@ -380,6 +434,7 @@ void QFxKeyNavigationAttached::setUp(QFxItem *i) { Q_D(QFxKeyNavigationAttached); d->up = i; + emit changed(); } QFxItem *QFxKeyNavigationAttached::down() const @@ -392,6 +447,79 @@ void QFxKeyNavigationAttached::setDown(QFxItem *i) { Q_D(QFxKeyNavigationAttached); d->down = i; + emit changed(); +} + +void QFxKeyNavigationAttached::keyPressed(QKeyEvent *event) +{ + Q_D(QFxKeyNavigationAttached); + + event->ignore(); + + switch(event->key()) { + case Qt::Key_Left: + if (d->left) { + d->left->setFocus(true); + event->accept(); + } + break; + case Qt::Key_Right: + if (d->right) { + d->right->setFocus(true); + event->accept(); + } + break; + case Qt::Key_Up: + if (d->up) { + d->up->setFocus(true); + event->accept(); + } + break; + case Qt::Key_Down: + if (d->down) { + d->down->setFocus(true); + event->accept(); + } + break; + default: + break; + } + + if (!event->isAccepted()) QFxItemKeyFilter::keyPressed(event); +} + +void QFxKeyNavigationAttached::keyReleased(QKeyEvent *event) +{ + Q_D(QFxKeyNavigationAttached); + + event->ignore(); + + switch(event->key()) { + case Qt::Key_Left: + if (d->left) { + event->accept(); + } + break; + case Qt::Key_Right: + if (d->right) { + event->accept(); + } + break; + case Qt::Key_Up: + if (d->up) { + event->accept(); + } + break; + case Qt::Key_Down: + if (d->down) { + event->accept(); + } + break; + default: + break; + } + + if (!event->isAccepted()) QFxItemKeyFilter::keyReleased(event); } /*! @@ -711,7 +839,7 @@ public: bool enabled; }; -class QFxKeysAttached : public QObject +class QFxKeysAttached : public QObject, public QFxItemKeyFilter { Q_OBJECT Q_DECLARE_PRIVATE(QFxKeysAttached); @@ -776,8 +904,8 @@ signals: void volumeDownPressed(QFxKeyEvent *event); private: - void keyPressed(QKeyEvent *event); - void keyReleased(QKeyEvent *event); + virtual void keyPressed(QKeyEvent *event); + virtual void keyReleased(QKeyEvent *event); const char *keyToSignal(int key) { QByteArray keySignal; @@ -799,7 +927,6 @@ private: }; static const SigMap sigMap[]; - friend class QFxItem; }; const QFxKeysAttached::SigMap QFxKeysAttached::sigMap[] = { @@ -838,16 +965,13 @@ bool QFxKeysAttachedPrivate::isConnected(const char *signalName) } QFxKeysAttached::QFxKeysAttached(QObject *parent) -: QObject(*(new QFxKeysAttachedPrivate), parent) +: QObject(*(new QFxKeysAttachedPrivate), parent), + QFxItemKeyFilter(qobject_cast(parent)) { - if (QFxItem *item = qobject_cast(parent)) - item->setKeyHandler(this); } QFxKeysAttached::~QFxKeysAttached() { - if (QFxItem *item = qobject_cast(parent())) - item->setKeyHandler(0); } void QFxKeysAttached::keyPressed(QKeyEvent *event) @@ -872,6 +996,8 @@ void QFxKeysAttached::keyPressed(QKeyEvent *event) if (!ke.isAccepted()) emit pressed(&ke); event->setAccepted(ke.isAccepted()); + + if (!event->isAccepted()) QFxItemKeyFilter::keyPressed(event); } void QFxKeysAttached::keyReleased(QKeyEvent *event) @@ -884,21 +1010,15 @@ void QFxKeysAttached::keyReleased(QKeyEvent *event) QFxKeyEvent ke(*event); emit released(&ke); event->setAccepted(ke.isAccepted()); + + if (!event->isAccepted()) QFxItemKeyFilter::keyReleased(event); } QFxKeysAttached *QFxKeysAttached::qmlAttachedProperties(QObject *obj) { - QFxKeysAttached *rv = 0; - QFxItem *item = qobject_cast(obj); - if (item) { - rv = item->keyHandler(); - if (!rv) - rv = new QFxKeysAttached(obj); - } - return rv; + return new QFxKeysAttached(obj); } - /*! \qmlclass Item QFxItem \brief The Item is the most basic of all visual items in QML. @@ -1517,18 +1637,6 @@ void QFxItem::geometryChanged(const QRectF &newGeometry, } } -QFxKeysAttached *QFxItem::keyHandler() -{ - Q_D(QFxItem); - return d->keyHandler; -} - -void QFxItem::setKeyHandler(QFxKeysAttached *handler) -{ - Q_D(QFxItem); - d->keyHandler = handler; -} - /*! \reimp */ diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index 222677c..cb2d97a 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -63,7 +63,6 @@ class QmlTransition; class QFxKeyEvent; class QFxAnchors; class QFxItemPrivate; -class QFxKeysAttached; class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserStatus { Q_OBJECT @@ -197,12 +196,8 @@ private: QFxAnchorLine verticalCenter() const; QFxAnchorLine baseline() const; - QFxKeysAttached *keyHandler(); - void setKeyHandler(QFxKeysAttached *); - friend class QmlStatePrivate; friend class QFxAnchors; - friend class QFxKeysAttached; Q_DISABLE_COPY(QFxItem) Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxItem) }; diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h index 1d4bef3..d30e324 100644 --- a/src/declarative/fx/qfxitem_p.h +++ b/src/declarative/fx/qfxitem_p.h @@ -67,7 +67,7 @@ QT_BEGIN_NAMESPACE class QNetworkReply; -class QFxKeysAttached; +class QFxItemKeyFilter; //### merge into private? class QFxContents : public QObject @@ -209,7 +209,7 @@ public: bool _keepMouse:1; bool smooth:1; - QFxKeysAttached *keyHandler; + QFxItemKeyFilter *keyHandler; qreal width; qreal height; -- cgit v0.12 From de9bcc414c230fa7af1828d938c59fe2d139b968 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 25 Aug 2009 12:42:59 +1000 Subject: Revert cb81a637c8ef041cff2e96c6065763084776d75a Programming error to call with ns==0. --- src/declarative/qml/qmlengine.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index b3e08ea..faac8cd 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -1362,9 +1362,6 @@ bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& typ */ void QmlEnginePrivate::resolveTypeInNamespace(ImportedNamespace* ns, const QByteArray& type, QmlType** type_return, QUrl* url_return, int *vmaj, int *vmin ) const { - if (!ns) - return; - if (type_return) { *type_return = ns->findBuiltin(type,vmaj,vmin); } -- cgit v0.12 From 15e37128223c9438be9372c35fac5981a440c94b Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 25 Aug 2009 13:46:34 +1000 Subject: Add support for prefixed attached properties at compile time To reduce possible confusion, an id used within a component may not conflict with namespace prefixes. --- src/declarative/qml/qmlcompiler.cpp | 60 ++++++++++++++++++++-- src/declarative/qml/qmlcompiler_p.h | 5 ++ src/declarative/qml/qmlengine_p.h | 12 +++-- .../declarative/qmlparser/invalidID.5.errors.txt | 1 + tests/auto/declarative/qmlparser/invalidID.5.qml | 6 +++ tests/auto/declarative/qmlparser/tst_qmlparser.cpp | 2 + 6 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 tests/auto/declarative/qmlparser/invalidID.5.errors.txt create mode 100644 tests/auto/declarative/qmlparser/invalidID.5.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 1771cb4..3dcc448 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -1176,11 +1176,19 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, } QmlType *type = 0; - QmlEnginePrivate::get(engine)->resolveType(unit->imports, prop->name, &type, 0); - // 0: attached properties not supported in QML component files - - if (!type || !type->attachedPropertiesType()) + QmlEnginePrivate::ImportedNamespace *typeNamespace = 0; + QmlEnginePrivate::get(engine)->resolveType(unit->imports, prop->name, + &type, 0, &typeNamespace); + + if (typeNamespace) { + // ### We might need to indicate that this property is a namespace + // for the DOM API + COMPILE_CHECK(buildPropertyInNamespace(typeNamespace, prop, obj, + ctxt)); + return true; + } else if (!type || !type->attachedPropertiesType()) { COMPILE_EXCEPTION(prop, "Non-existant attached object"); + } if (!prop->value) COMPILE_EXCEPTION(prop, "Invalid attached object assignment"); @@ -1265,6 +1273,40 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop, return true; } +bool +QmlCompiler::buildPropertyInNamespace(QmlEnginePrivate::ImportedNamespace *ns, + QmlParser::Property *nsProp, + QmlParser::Object *obj, + const BindingContext &ctxt) +{ + if (!nsProp->value) + COMPILE_EXCEPTION(nsProp, "Invalid use of namespace"); + + foreach (Property *prop, nsProp->value->properties) { + + if (!isAttachedPropertyName(prop->name)) + COMPILE_EXCEPTION(prop, "Not an attached property name"); + + // Setup attached property data + + QmlType *type = 0; + QmlEnginePrivate::get(engine)->resolveTypeInNamespace(ns, prop->name, + &type, 0); + + if (!type || !type->attachedPropertiesType()) + COMPILE_EXCEPTION(prop, "Non-existant attached object"); + + if (!prop->value) + COMPILE_EXCEPTION(prop, "Invalid attached object assignment"); + + Q_ASSERT(type->attachedPropertiesFunction()); + prop->index = type->index(); + prop->value->metatype = type->attachedPropertiesType(); + + COMPILE_CHECK(buildAttachedProperty(prop, obj, ctxt)); + } +} + void QmlCompiler::genValueProperty(QmlParser::Property *prop, QmlParser::Object *obj) { @@ -1407,11 +1449,19 @@ bool QmlCompiler::buildIdProperty(QmlParser::Property *prop, prop->values.at(0)->object) COMPILE_EXCEPTION(prop, "Invalid use of id property"); - QString val = prop->values.at(0)->primitive(); + QmlParser::Value *idValue = prop->values.at(0); + QString val = idValue->primitive(); if (!isValidId(val)) COMPILE_EXCEPTION(prop, val << "is not a valid object id"); + // We disallow id's that conflict with import prefixes + QmlEnginePrivate::ImportedNamespace *ns = 0; + QmlEnginePrivate::get(engine)->resolveType(unit->imports, val.toUtf8(), + 0, 0, &ns); + if (ns) + COMPILE_EXCEPTION(idValue, "id conflicts with namespace prefix"); + if (compileState.ids.contains(val)) COMPILE_EXCEPTION(prop, "id is not unique"); diff --git a/src/declarative/qml/qmlcompiler_p.h b/src/declarative/qml/qmlcompiler_p.h index 58279c4..c42c2d9 100644 --- a/src/declarative/qml/qmlcompiler_p.h +++ b/src/declarative/qml/qmlcompiler_p.h @@ -60,6 +60,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -165,6 +166,10 @@ private: const BindingContext &); bool buildProperty(QmlParser::Property *prop, QmlParser::Object *obj, const BindingContext &); + bool buildPropertyInNamespace(QmlEnginePrivate::ImportedNamespace *ns, + QmlParser::Property *prop, + QmlParser::Object *obj, + const BindingContext &); bool buildIdProperty(QmlParser::Property *prop, QmlParser::Object *obj); bool buildAttachedProperty(QmlParser::Property *prop, QmlParser::Object *obj, diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index c84b3b5..18e3765 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -209,10 +209,14 @@ public: bool addToImport(Imports*, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const; - bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, ImportedNamespace** ns_return=0) const; - - void resolveNamespace(const Imports& imports, const QByteArray &type, ImportedNamespace **s, QByteArray *unqualifiedType) const; - bool resolveTypeInNamespace(ImportedNamespace*, const QByteArray& type, QmlType** type_return, QUrl* url_return ) const; + bool resolveType(const Imports&, const QByteArray& type, + QmlType** type_return, QUrl* url_return, + ImportedNamespace** ns_return=0) const; + void resolveNamespace(const Imports& imports, const QByteArray &type, + ImportedNamespace **s, + QByteArray *unqualifiedType) const; + bool resolveTypeInNamespace(ImportedNamespace*, const QByteArray& type, + QmlType** type_return, QUrl* url_return ) const; static QScriptValue qmlScriptObject(QObject*, QmlEngine*); diff --git a/tests/auto/declarative/qmlparser/invalidID.5.errors.txt b/tests/auto/declarative/qmlparser/invalidID.5.errors.txt new file mode 100644 index 0000000..b0a63a0 --- /dev/null +++ b/tests/auto/declarative/qmlparser/invalidID.5.errors.txt @@ -0,0 +1 @@ +4:9:id conflicts with namespace prefix diff --git a/tests/auto/declarative/qmlparser/invalidID.5.qml b/tests/auto/declarative/qmlparser/invalidID.5.qml new file mode 100644 index 0000000..0545b0d --- /dev/null +++ b/tests/auto/declarative/qmlparser/invalidID.5.qml @@ -0,0 +1,6 @@ +import Test 1.0 +import Test 1.0 as Hello +MyQmlObject { + id: Hello +} + diff --git a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp index a9c4351..3047bb0 100644 --- a/tests/auto/declarative/qmlparser/tst_qmlparser.cpp +++ b/tests/auto/declarative/qmlparser/tst_qmlparser.cpp @@ -135,6 +135,8 @@ void tst_qmlparser::errors_data() QTest::newRow("invalidID.2") << "invalidID.2.qml" << "invalidID.2.errors.txt" << false; QTest::newRow("invalidID.3") << "invalidID.3.qml" << "invalidID.3.errors.txt" << false; QTest::newRow("invalidID.4") << "invalidID.4.qml" << "invalidID.4.errors.txt" << false; + QTest::newRow("invalidID.5") << "invalidID.5.qml" << "invalidID.5.errors.txt" << false; + QTest::newRow("unsupportedProperty") << "unsupportedProperty.qml" << "unsupportedProperty.errors.txt" << false; QTest::newRow("nullDotProperty") << "nullDotProperty.qml" << "nullDotProperty.errors.txt" << true; -- cgit v0.12 From 4e31d0e5161c31b609652ad151b44b57c5b4ab28 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 25 Aug 2009 13:53:47 +1000 Subject: Fixup test --- tests/auto/declarative/qmlparser/failingComponent.errors.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qmlparser/failingComponent.errors.txt b/tests/auto/declarative/qmlparser/failingComponent.errors.txt index 388fa76..190a649 100644 --- a/tests/auto/declarative/qmlparser/failingComponent.errors.txt +++ b/tests/auto/declarative/qmlparser/failingComponent.errors.txt @@ -1,2 +1,2 @@ --1:-1:Unable to create type FailingComponent +3:5:Unable to create type FailingComponent 4:5:Cannot assign to non-existant property "a" -- cgit v0.12 From 0cde5e06acfe8895e563e195f4fc3b16a18db486 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 25 Aug 2009 14:01:28 +1000 Subject: Forgot to commit RssModel.qml --- demos/declarative/flickr/common/RssModel.qml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 demos/declarative/flickr/common/RssModel.qml diff --git a/demos/declarative/flickr/common/RssModel.qml b/demos/declarative/flickr/common/RssModel.qml new file mode 100644 index 0000000..ed9fd5c --- /dev/null +++ b/demos/declarative/flickr/common/RssModel.qml @@ -0,0 +1,20 @@ +import Qt 4.6 + +XmlListModel { + property string tags : "" + + source: "http://api.flickr.com/services/feeds/photos_public.gne?"+(tags ? "tags="+tags+"&" : "")+"format=rss2" + query: "/rss/channel/item" + namespaceDeclarations: "declare namespace media=\"http://search.yahoo.com/mrss/\";" + + XmlRole { name: "title"; query: "title/string()" } + XmlRole { name: "imagePath"; query: "media:thumbnail/@url/string()" } + XmlRole { name: "url"; query: "media:content/@url/string()" } + XmlRole { name: "description"; query: "description/string()" } + XmlRole { name: "tags"; query: "media:category/string()" } + XmlRole { name: "photoWidth"; query: "media:content/@width/string()" } + XmlRole { name: "photoHeight"; query: "media:content/@height/string()" } + XmlRole { name: "photoType"; query: "media:content/@type/string()" } + XmlRole { name: "photoAuthor"; query: "author/string()" } + XmlRole { name: "photoDate"; query: "pubDate/string()" } +} -- cgit v0.12 From 49b7d16486b5a0629b8d46a4803c858a51676f69 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 25 Aug 2009 14:16:10 +1000 Subject: SameGame small cosmetic changes --- demos/declarative/samegame/SameGame.qml | 67 ++++++++++++++++++--------- demos/declarative/samegame/content/Button.qml | 26 +++++++---- 2 files changed, 62 insertions(+), 31 deletions(-) diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml index d476e8b..a9d8140 100644 --- a/demos/declarative/samegame/SameGame.qml +++ b/demos/declarative/samegame/SameGame.qml @@ -1,34 +1,57 @@ import Qt 4.6 - import "content" Rectangle { - id: page; width: 460; height: 700; color: activePalette.window + id: Screen + width: 460; height: 700 + Script { source: "content/samegame.js" } + SystemPalette { id: activePalette; colorGroup: Qt.Active } - Rectangle { - id: gameCanvas - property int score: 0 - z:20; y:20; color: "white"; border.width: 1 - width:parent.width - tileSize - (parent.width % tileSize); - height:parent.height - tileSize - (parent.height % tileSize); - anchors.horizontalCenter: parent.horizontalCenter - Image { id:background; - source: "content/pics/background.png" - anchors.fill: parent + + Item { + width: parent.width; anchors.top: parent.top; anchors.bottom: ToolBar.top + + Image { + id: background + anchors.fill: parent; source: "content/pics/background.png" + fillMode: "PreserveAspectCrop" } - MouseRegion { id: gameMR - anchors.fill: parent; onClicked: handleClick(mouse.x,mouse.y); + + Item { + id: gameCanvas + property int score: 0 + + z: 20; anchors.centerIn: parent + width: parent.width - tileSize - (parent.width % tileSize); + height: parent.height - tileSize - (parent.height % tileSize); + + MouseRegion { + id: gameMR + anchors.fill: parent; onClicked: handleClick(mouse.x,mouse.y); + } } } - Dialog { id: dialog; anchors.centerIn: parent; z: 21} - Button { - id: btnA; text: "New Game"; onClicked: {initBoard();} - anchors.top: gameCanvas.bottom; anchors.topMargin: 4; anchors.left: gameCanvas.left; - } - Text { - text: "Score: " + gameCanvas.score; width:100; font.pointSize:14 - anchors.top: gameCanvas.bottom; anchors.topMargin: 4; anchors.right: gameCanvas.right; + Dialog { id: dialog; anchors.centerIn: parent; z: 21 } + + Rectangle { + id: ToolBar + color: activePalette.window + height: Score.height + 10; width: parent.width + anchors.bottom: Screen.bottom + + Button { + id: btnA; text: "New Game"; onClicked: {initBoard();} + anchors.left: parent.left; anchors.leftMargin: 3 + anchors.verticalCenter: parent.verticalCenter + } + + Text { + id: Score + text: "Score: " + gameCanvas.score; font.pointSize: 11 + anchors.right: parent.right; anchors.rightMargin: 3 + anchors.verticalCenter: parent.verticalCenter + } } } diff --git a/demos/declarative/samegame/content/Button.qml b/demos/declarative/samegame/content/Button.qml index 70b175c..208c502 100644 --- a/demos/declarative/samegame/content/Button.qml +++ b/demos/declarative/samegame/content/Button.qml @@ -1,18 +1,26 @@ import Qt 4.6 -Rectangle { - id: page; color: activePalette.button; width: txtItem.width+20; height: txtItem.height+4 - border.width: 1; border.color: activePalette.mid; radius: 10; +Rectangle { + id: Container + signal clicked property string text: "Button" - gradient: Gradient { - GradientStop { id:topGrad; position: 0.0; - color: if(mr.pressed){activePalette.dark;}else{activePalette.light;}} + + color: activePalette.button; smooth: true + width: txtItem.width + 20; height: txtItem.height + 6 + border.width: 1; border.color: activePalette.darker(activePalette.button); radius: 8; + + gradient: Gradient { + GradientStop { + id: topGrad; position: 0.0 + color: if (mr.pressed) { activePalette.dark } else { activePalette.light } } GradientStop { position: 1.0; color: activePalette.button } } - MouseRegion { id:mr; anchors.fill: parent; onClicked: page.clicked() } + + MouseRegion { id: mr; anchors.fill: parent; onClicked: Container.clicked() } + Text { - id: txtItem; text: page.text; anchors.centerIn: page; color: activePalette.buttonText - font.pointSize: 14; + id: txtItem; text: Container.text; anchors.centerIn: Container; color: activePalette.buttonText + font.pointSize: 10; } } -- cgit v0.12 From 271904ca7806abfe3c4a9004831658803e18737c Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 25 Aug 2009 14:17:22 +1000 Subject: Dialog width is dependent on text --- demos/declarative/samegame/content/Dialog.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demos/declarative/samegame/content/Dialog.qml b/demos/declarative/samegame/content/Dialog.qml index a3c5f33..72c7900 100644 --- a/demos/declarative/samegame/content/Dialog.qml +++ b/demos/declarative/samegame/content/Dialog.qml @@ -2,7 +2,7 @@ import Qt 4.6 Rectangle { id: page - color: "white"; border.width: 1; width: 200; height: 60; + color: "white"; border.width: 1; width: MyText.width + 20; height: 60; property string text: "Hello World!" opacity: 0 opacity: Behavior { @@ -11,5 +11,5 @@ Rectangle { NumberAnimation {property: "opacity"; to: 0; duration: 1500 } } } - Text { anchors.centerIn: parent; text: parent.text } + Text { id: MyText; anchors.centerIn: parent; text: parent.text } } -- cgit v0.12 From d6f0db181ab35250ee53c9b9d0210a80c69382ac Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 25 Aug 2009 14:29:54 +1000 Subject: Remove excessive margins in SameGame Reviewed-by: Yann Bodson --- demos/declarative/samegame/SameGame.qml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml index a9d8140..c0a1b2a 100644 --- a/demos/declarative/samegame/SameGame.qml +++ b/demos/declarative/samegame/SameGame.qml @@ -3,7 +3,7 @@ import "content" Rectangle { id: Screen - width: 460; height: 700 + width: 490; height: 720 Script { source: "content/samegame.js" } @@ -23,8 +23,8 @@ Rectangle { property int score: 0 z: 20; anchors.centerIn: parent - width: parent.width - tileSize - (parent.width % tileSize); - height: parent.height - tileSize - (parent.height % tileSize); + width: parent.width - (parent.width % tileSize); + height: parent.height - (parent.height % tileSize); MouseRegion { id: gameMR -- cgit v0.12 From 29b028b156b190718ecdb223c08f2fdcfc07b3e6 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 25 Aug 2009 14:34:56 +1000 Subject: Fix the size of the button --- demos/declarative/samegame/SameGame.qml | 4 ++-- demos/declarative/samegame/content/Button.qml | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml index a9d8140..37ccff7 100644 --- a/demos/declarative/samegame/SameGame.qml +++ b/demos/declarative/samegame/SameGame.qml @@ -38,7 +38,7 @@ Rectangle { Rectangle { id: ToolBar color: activePalette.window - height: Score.height + 10; width: parent.width + height: 32; width: parent.width anchors.bottom: Screen.bottom Button { @@ -49,7 +49,7 @@ Rectangle { Text { id: Score - text: "Score: " + gameCanvas.score; font.pointSize: 11 + text: "Score: " + gameCanvas.score; font.bold: true anchors.right: parent.right; anchors.rightMargin: 3 anchors.verticalCenter: parent.verticalCenter } diff --git a/demos/declarative/samegame/content/Button.qml b/demos/declarative/samegame/content/Button.qml index 208c502..2354218 100644 --- a/demos/declarative/samegame/content/Button.qml +++ b/demos/declarative/samegame/content/Button.qml @@ -21,6 +21,5 @@ Rectangle { Text { id: txtItem; text: Container.text; anchors.centerIn: Container; color: activePalette.buttonText - font.pointSize: 10; } } -- cgit v0.12 From 7c1eaa4ec5d78ccf7770c09e12afb497daa4b90e Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 25 Aug 2009 17:13:52 +1000 Subject: Make QmlEnginePrivate::Imports a stack type. Also fixes memleak. --- src/declarative/qml/qmlengine.cpp | 44 ++++++++++++++++++++++++++++++++++++--- src/declarative/qml/qmlengine_p.h | 9 ++++++-- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index faac8cd..7923eda 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -1141,6 +1141,16 @@ struct QmlEnginePrivate::ImportedNamespace { class QmlImportsPrivate { public: + QmlImportsPrivate() : ref(1) + { + } + + ~QmlImportsPrivate() + { + foreach (QmlEnginePrivate::ImportedNamespace* s, set.values()) + delete s; + } + bool add(const QUrl& base, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType, const QStringList& importPath) { QmlEnginePrivate::ImportedNamespace *s; @@ -1237,11 +1247,29 @@ public: return set.value(type); } + QUrl base; + int ref; + private: QmlEnginePrivate::ImportedNamespace unqualifiedset; QHash set; }; +QmlEnginePrivate::Imports::Imports(const Imports ©) : + d(copy.d) +{ + ++d->ref; +} + +QmlEnginePrivate::Imports &QmlEnginePrivate::Imports::operator =(const Imports ©) +{ + ++copy.d->ref; + if (--d->ref == 0) + delete d; + d = copy.d; + return *this; +} + QmlEnginePrivate::Imports::Imports() : d(new QmlImportsPrivate) { @@ -1249,6 +1277,8 @@ QmlEnginePrivate::Imports::Imports() : QmlEnginePrivate::Imports::~Imports() { + if (--d->ref == 0) + delete d; } /*! @@ -1256,7 +1286,15 @@ QmlEnginePrivate::Imports::~Imports() */ void QmlEnginePrivate::Imports::setBaseUrl(const QUrl& url) { - base = url; + d->base = url; +} + +/*! + Returns the base URL to be used for all relative file imports added. +*/ +QUrl QmlEnginePrivate::Imports::baseUrl() const +{ + return d->base; } /*! @@ -1293,7 +1331,7 @@ void QmlEngine::addImportPath(const QString& path) */ bool QmlEnginePrivate::addToImport(Imports* imports, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const { - bool ok = imports->d->add(imports->base,uri,prefix,vmaj,vmin,importType,fileImportPath); + bool ok = imports->d->add(imports->d->base,uri,prefix,vmaj,vmin,importType,fileImportPath); if (qmlImportTrace()) qDebug() << "QmlEngine::addToImport(" << imports << uri << prefix << vmaj << "." << vmin << (importType==QmlScriptParser::Import::Library? "Library" : "File") << ": " << ok; return ok; @@ -1336,7 +1374,7 @@ bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& typ if (url_return) { QUrl url = imports.d->find(QLatin1String(type)); if (!url.isValid()) - url = imports.base.resolved(QUrl(QLatin1String(type + ".qml"))); + url = imports.d->base.resolved(QUrl(QLatin1String(type + ".qml"))); if (url.isValid()) { if (url_return) *url_return = url; diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 4be5a98..3f0c03c 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -188,13 +188,17 @@ public: struct Imports { Imports(); ~Imports(); + Imports(const Imports ©); + Imports &operator =(const Imports ©); + void setBaseUrl(const QUrl& url); - QUrl baseUrl() const { return base; } + QUrl baseUrl() const; + private: friend class QmlEnginePrivate; - QUrl base; QmlImportsPrivate *d; }; + struct ImportedNamespace; bool addToImport(Imports*, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const; bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, int *version_major, int *version_minor, ImportedNamespace** ns_return=0) const; @@ -210,6 +214,7 @@ public: static QmlEnginePrivate *get(QmlEngine *e) { return e->d_func(); } }; + class QmlScriptClass : public QScriptClass { public: -- cgit v0.12 From 48e8644b148fbd6942a44e7492ba9fd7cde703c1 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 25 Aug 2009 17:50:36 +1000 Subject: Update. --- tests/auto/declarative/qmlparser/FailingComponent.qml | 5 +++++ tests/auto/declarative/qmlparser/failingComponent.qml | 5 ----- tests/auto/declarative/qmlparser/unregisteredObject.errors.txt | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 tests/auto/declarative/qmlparser/FailingComponent.qml delete mode 100644 tests/auto/declarative/qmlparser/failingComponent.qml diff --git a/tests/auto/declarative/qmlparser/FailingComponent.qml b/tests/auto/declarative/qmlparser/FailingComponent.qml new file mode 100644 index 0000000..1c01e3d --- /dev/null +++ b/tests/auto/declarative/qmlparser/FailingComponent.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +Object { + a: 10 +} diff --git a/tests/auto/declarative/qmlparser/failingComponent.qml b/tests/auto/declarative/qmlparser/failingComponent.qml deleted file mode 100644 index 1c01e3d..0000000 --- a/tests/auto/declarative/qmlparser/failingComponent.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Qt 4.6 - -Object { - a: 10 -} diff --git a/tests/auto/declarative/qmlparser/unregisteredObject.errors.txt b/tests/auto/declarative/qmlparser/unregisteredObject.errors.txt index 11e4e16..bc4f7f4 100644 --- a/tests/auto/declarative/qmlparser/unregisteredObject.errors.txt +++ b/tests/auto/declarative/qmlparser/unregisteredObject.errors.txt @@ -1 +1 @@ --1:-1:Type UnregisteredObject unavailable +2:1:Type UnregisteredObject unavailable -- cgit v0.12 From 55863a42d80af8f1d8f35e7f43d0171d7f0e9b79 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 25 Aug 2009 11:49:02 +0200 Subject: Don't crash for QFxWebView::setUrl(QUrl) --- src/declarative/fx/qfxwebview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp index 347c9c2..7247837 100644 --- a/src/declarative/fx/qfxwebview.cpp +++ b/src/declarative/fx/qfxwebview.cpp @@ -333,7 +333,7 @@ void QFxWebView::setUrl(const QUrl &url) d->idealwidth>0 ? d->idealwidth : width(), d->idealheight>0 ? d->idealheight : height())); - Q_ASSERT(!url.isRelative()); + Q_ASSERT(url.isEmpty() || !url.isRelative()); if (isComponentComplete()) page()->mainFrame()->load(url); -- cgit v0.12 From ecd37a35adc4008b105b8bc9fcf55450da1dd949 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 25 Aug 2009 12:05:21 +0200 Subject: QVector3D: missing implicit conversion to QVariant --- src/gui/math3d/qvector3d.cpp | 8 ++++++++ src/gui/math3d/qvector3d.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/gui/math3d/qvector3d.cpp b/src/gui/math3d/qvector3d.cpp index 0e3f4e1..63fda09 100644 --- a/src/gui/math3d/qvector3d.cpp +++ b/src/gui/math3d/qvector3d.cpp @@ -282,6 +282,14 @@ void QVector3D::normalize() */ /*! + Returns the vector as a QVariant +*/ +QVector3D::operator QVariant () const +{ + return QVariant(QVariant::Vector3D, this); +} + +/*! Returns the dot product of \a v1 and \a v2. */ qreal QVector3D::dotProduct(const QVector3D& v1, const QVector3D& v2) diff --git a/src/gui/math3d/qvector3d.h b/src/gui/math3d/qvector3d.h index 36292d2..b625946 100644 --- a/src/gui/math3d/qvector3d.h +++ b/src/gui/math3d/qvector3d.h @@ -95,6 +95,8 @@ public: QVector3D &operator*=(const QVector3D& vector); QVector3D &operator/=(qreal divisor); + operator QVariant() const; + static qreal dotProduct(const QVector3D& v1, const QVector3D& v2); static QVector3D crossProduct(const QVector3D& v1, const QVector3D& v2); static QVector3D normal(const QVector3D& v1, const QVector3D& v2); -- cgit v0.12 From 430e8577845e7722bf8397ce5b37dd83f5de1b2e Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 25 Aug 2009 12:06:18 +0200 Subject: Reading and writing of QVariant for QmlValueType This is very useful for Bauhaus and avoids code duplication Reviewed-by: Aaron Kennedy --- src/declarative/qml/qmlvaluetype.cpp | 81 ++++++++++++++++++++++++++++++++++++ src/declarative/qml/qmlvaluetype_p.h | 18 ++++++++ 2 files changed, 99 insertions(+) diff --git a/src/declarative/qml/qmlvaluetype.cpp b/src/declarative/qml/qmlvaluetype.cpp index 7af3c56..4ae2070 100644 --- a/src/declarative/qml/qmlvaluetype.cpp +++ b/src/declarative/qml/qmlvaluetype.cpp @@ -103,6 +103,16 @@ void QmlPointFValueType::write(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); } +QVariant QmlPointFValueType::value() +{ + return QVariant(point); +} + +void QmlPointFValueType::setValue(QVariant value) +{ + point = qvariant_cast(value); +} + qreal QmlPointFValueType::x() const { return point.x(); @@ -140,6 +150,16 @@ void QmlPointValueType::write(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); } +QVariant QmlPointValueType::value() +{ + return QVariant(point); +} + +void QmlPointValueType::setValue(QVariant value) +{ + point = qvariant_cast(value); +} + int QmlPointValueType::x() const { return point.x(); @@ -177,6 +197,16 @@ void QmlSizeFValueType::write(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); } +QVariant QmlSizeFValueType::value() +{ + return QVariant(size); +} + +void QmlSizeFValueType::setValue(QVariant value) +{ + size = qvariant_cast(value); +} + qreal QmlSizeFValueType::width() const { return size.width(); @@ -214,6 +244,16 @@ void QmlSizeValueType::write(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); } +QVariant QmlSizeValueType::value() +{ + return QVariant(size); +} + +void QmlSizeValueType::setValue(QVariant value) +{ + size = qvariant_cast(value); +} + int QmlSizeValueType::width() const { return size.width(); @@ -251,6 +291,16 @@ void QmlRectFValueType::write(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); } +QVariant QmlRectFValueType::value() +{ + return QVariant(rect); +} + +void QmlRectFValueType::setValue(QVariant value) +{ + rect = qvariant_cast(value); +} + qreal QmlRectFValueType::x() const { return rect.x(); @@ -308,6 +358,16 @@ void QmlRectValueType::write(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); } +QVariant QmlRectValueType::value() +{ + return QVariant(rect); +} + +void QmlRectValueType::setValue(QVariant value) +{ + rect = qvariant_cast(value); +} + int QmlRectValueType::x() const { return rect.x(); @@ -365,6 +425,16 @@ void QmlVector3DValueType::write(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); } +QVariant QmlVector3DValueType::value() +{ + return QVariant(vector); +} + +void QmlVector3DValueType::setValue(QVariant value) +{ + vector = qvariant_cast(value); +} + qreal QmlVector3DValueType::x() const { return vector.x(); @@ -412,6 +482,17 @@ void QmlFontValueType::write(QObject *obj, int idx) QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); } +QVariant QmlFontValueType::value() +{ + return QVariant(font); +} + +void QmlFontValueType::setValue(QVariant value) +{ + font = qvariant_cast(value); +} + + QString QmlFontValueType::family() const { return font.family(); diff --git a/src/declarative/qml/qmlvaluetype_p.h b/src/declarative/qml/qmlvaluetype_p.h index 7a3620c..a56feec 100644 --- a/src/declarative/qml/qmlvaluetype_p.h +++ b/src/declarative/qml/qmlvaluetype_p.h @@ -68,6 +68,8 @@ public: QmlValueType(QObject *parent = 0); virtual void read(QObject *, int) = 0; virtual void write(QObject *, int) = 0; + virtual QVariant value() = 0; + virtual void setValue(QVariant) = 0; }; class QmlValueTypeFactory @@ -91,6 +93,8 @@ public: virtual void read(QObject *, int); virtual void write(QObject *, int); + virtual QVariant value(); + virtual void setValue(QVariant value); qreal x() const; qreal y() const; @@ -111,6 +115,8 @@ public: virtual void read(QObject *, int); virtual void write(QObject *, int); + virtual QVariant value(); + virtual void setValue(QVariant value); int x() const; int y() const; @@ -131,6 +137,8 @@ public: virtual void read(QObject *, int); virtual void write(QObject *, int); + virtual QVariant value(); + virtual void setValue(QVariant value); qreal width() const; qreal height() const; @@ -151,6 +159,8 @@ public: virtual void read(QObject *, int); virtual void write(QObject *, int); + virtual QVariant value(); + virtual void setValue(QVariant value); int width() const; int height() const; @@ -173,6 +183,8 @@ public: virtual void read(QObject *, int); virtual void write(QObject *, int); + virtual QVariant value(); + virtual void setValue(QVariant value); qreal x() const; qreal y() const; @@ -200,6 +212,8 @@ public: virtual void read(QObject *, int); virtual void write(QObject *, int); + virtual QVariant value(); + virtual void setValue(QVariant value); int x() const; int y() const; @@ -226,6 +240,8 @@ public: virtual void read(QObject *, int); virtual void write(QObject *, int); + virtual QVariant value(); + virtual void setValue(QVariant value); qreal x() const; qreal y() const; @@ -252,6 +268,8 @@ public: virtual void read(QObject *, int); virtual void write(QObject *, int); + virtual QVariant value(); + virtual void setValue(QVariant value); QString family() const; void setFamily(const QString &); -- cgit v0.12 From 0094735947164aef8f8e6539c535199b29ed6f4e Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 25 Aug 2009 12:43:44 +0200 Subject: Fix compilation (missing include) --- src/gui/math3d/qvector3d.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/math3d/qvector3d.cpp b/src/gui/math3d/qvector3d.cpp index 63fda09..15d7e76 100644 --- a/src/gui/math3d/qvector3d.cpp +++ b/src/gui/math3d/qvector3d.cpp @@ -44,6 +44,7 @@ #include "qvector4d.h" #include #include +#include QT_BEGIN_NAMESPACE -- cgit v0.12