diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-04-16 01:29:47 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-04-16 01:29:47 (GMT) |
commit | 140a96d0b860b045c18d53c1ac96e77b3893d31c (patch) | |
tree | 3dc9885e18c8d37955e073d415c02ac1656e0f30 /tools/qml/qmlruntime.cpp | |
parent | 07f724cd5abd0548fb32ed3469bde113daf028c4 (diff) | |
parent | fc399f2cd81772fed179d59a6f53abe69a81083a (diff) | |
download | Qt-140a96d0b860b045c18d53c1ac96e77b3893d31c.zip Qt-140a96d0b860b045c18d53c1ac96e77b3893d31c.tar.gz Qt-140a96d0b860b045c18d53c1ac96e77b3893d31c.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: (32 commits)
Correctly support translation in QDeclarativePixmapCache
Improve warning for non-Item delegates.
Correctly support translation in QDeclarativeCompiler
Small calculator fix.
Improve declarative calculator example.
Update examples autotest to use the runtime directly
Support valuetypes as method return values
Compile without Qt3 support.
Doc
Simplify dynamic resource loading to avoid cluttering Text API.
Add Component.onDestruction attached property
Use qmlInfo for image loading errors, not qWarning().
Visual test updates.
Rename section so that it's not linked to by references to "JavaScript"
Doc improvements
Comments
Remove unused parameter
Correctly resolve, and load, IMG tags in Text element.
Rename "sql" test so autotester doesn't get confused.
Should work now, don't skip.
...
Diffstat (limited to 'tools/qml/qmlruntime.cpp')
-rw-r--r-- | tools/qml/qmlruntime.cpp | 140 |
1 files changed, 22 insertions, 118 deletions
diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index df29294..53409c1 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -55,11 +55,6 @@ #include <QAbstractAnimation> #include "deviceskin.h" -#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 3)) -#include <private/qzipreader_p.h> -#define QDECLARATIVEVIEWER_ZIP_SUPPORT -#endif - #include <QSettings> #include <QXmlStreamReader> #include <QBuffer> @@ -470,6 +465,8 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) , portraitOrientation(0), landscapeOrientation(0) , m_scriptOptions(0), tester(0), useQmlFileBrowser(true) { + QDeclarativeViewer::registerTypes(); + devicemode = false; skin = 0; canvas = 0; @@ -553,6 +550,11 @@ QMenuBar *QDeclarativeViewer::menuBar() const return mb; } +QDeclarativeView *QDeclarativeViewer::view() const +{ + return canvas; +} + void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu) { QObject *parent = flatmenu ? (QObject*)flatmenu : (QObject*)menu; @@ -891,120 +893,19 @@ void QDeclarativeViewer::addPluginPath(const QString& plugin) void QDeclarativeViewer::reload() { - openQml(currentFileOrUrl); -} - -void QDeclarativeViewer::open(const QString& doc) -{ -#ifdef QDECLARATIVEVIEWER_ZIP_SUPPORT - if (doc.endsWith(".wgt",Qt::CaseInsensitive) - || doc.endsWith(".wgz",Qt::CaseInsensitive) - || doc.endsWith(".zip",Qt::CaseInsensitive)) - openWgt(doc); - else -#endif - openQml(doc); -} - -void QDeclarativeViewer::openWgt(const QString& doc) -{ -#ifdef QDECLARATIVEVIEWER_ZIP_SUPPORT - // XXX This functionality could be migrated to QDeclarativeView once refined - - QUrl url(doc); - if (url.isRelative()) - url = QUrl::fromLocalFile(doc); - delete canvas->rootObject(); - canvas->engine()->clearComponentCache(); - QNetworkAccessManager * nam = canvas->engine()->networkAccessManager(); - wgtreply = nam->get(QNetworkRequest(url)); - connect(wgtreply,SIGNAL(finished()),this,SLOT(unpackWgt())); -#endif -} - -#ifdef QDECLARATIVEVIEWER_ZIP_SUPPORT -static void removeRecursive(const QString& dirname) -{ - QDir dir(dirname); - QFileInfoList entries(dir.entryInfoList(QDir::Dirs|QDir::Files|QDir::NoDotAndDotDot)); - for (int i = 0; i < entries.count(); ++i) - if (entries[i].isDir()) - removeRecursive(entries[i].filePath()); - else - dir.remove(entries[i].fileName()); - QDir().rmdir(dirname); -} -#endif - -void QDeclarativeViewer::unpackWgt() -{ -#ifdef QDECLARATIVEVIEWER_ZIP_SUPPORT - QByteArray all = wgtreply->readAll(); - QBuffer buf(&all); - buf.open(QIODevice::ReadOnly); - QZipReader zip(&buf); - /* - for (int i=0; i<zip.count(); ++i) { - QZipReader::FileInfo info = zip.entryInfoAt(i); - qDebug() << "zip:" << info.filePath; - } - */ - wgtdir = QDir::tempPath()+QDir::separator()+QLatin1String("qml-wgt"); - removeRecursive(wgtdir); - QDir().mkpath(wgtdir); - zip.extractAll(wgtdir); - - QString rootfile; - - if (wgtreply->header(QNetworkRequest::ContentTypeHeader).toString() == "application/widget" || wgtreply->url().path().endsWith(".wgt",Qt::CaseInsensitive)) { - // W3C Draft http://www.w3.org/TR/2009/CR-widgets-20091201 - QFile configfile(wgtdir+QDir::separator()+"config.xml"); - if (configfile.open(QIODevice::ReadOnly)) { - QXmlStreamReader config(&configfile); - if (config.readNextStartElement() && config.name() == "widget") { - while (config.readNextStartElement()) { - if (config.name() == "content") { - rootfile = wgtdir + QDir::separator(); - rootfile += config.attributes().value(QLatin1String("src")); - } - // XXX process other config - - config.skipCurrentElement(); - } - } - } else { - qWarning("No config.xml found - non-standard WGT file"); - } - if (rootfile.isEmpty()) { - QString def = wgtdir+QDir::separator()+"index.qml"; - if (QFile::exists(def)) - rootfile = def; - } - } else { - // Just find index.qml, preferably at the root - for (int i=0; i<zip.count(); ++i) { - QZipReader::FileInfo info = zip.entryInfoAt(i); - if (info.filePath.compare(QLatin1String("index.qml"),Qt::CaseInsensitive)==0) - rootfile = wgtdir+QDir::separator()+info.filePath; - if (rootfile.isEmpty() && info.filePath.endsWith("/index.qml",Qt::CaseInsensitive)) - rootfile = wgtdir+QDir::separator()+info.filePath; - } - } - - openQml(rootfile); -#endif + open(currentFileOrUrl); } void QDeclarativeViewer::openFile() { QString cur = canvas->source().toLocalFile(); if (useQmlFileBrowser) { - openQml("qrc:/content/Browser.qml"); + open("qrc:/content/Browser.qml"); } else { QString fileName = QFileDialog::getOpenFileName(this, tr("Open QML file"), cur, tr("QML Files (*.qml)")); if (!fileName.isEmpty()) { QFileInfo fi(fileName); - openQml(fi.absoluteFilePath()); + open(fi.absoluteFilePath()); } } } @@ -1034,10 +935,10 @@ void QDeclarativeViewer::statusChanged() void QDeclarativeViewer::launch(const QString& file_or_url) { - QMetaObject::invokeMethod(this, "openQml", Qt::QueuedConnection, Q_ARG(QString, file_or_url)); + QMetaObject::invokeMethod(this, "open", Qt::QueuedConnection, Q_ARG(QString, file_or_url)); } -void QDeclarativeViewer::openQml(const QString& file_or_url) +bool QDeclarativeViewer::open(const QString& file_or_url) { currentFileOrUrl = file_or_url; @@ -1070,7 +971,7 @@ void QDeclarativeViewer::openQml(const QString& file_or_url) if (fi.exists()) { if (fi.suffix().toLower() != QLatin1String("qml")) { qWarning() << "qml cannot open non-QML file" << fileName; - return; + return false; } QDir dir(fi.path()+"/dummydata", "*.qml"); @@ -1101,7 +1002,7 @@ void QDeclarativeViewer::openQml(const QString& file_or_url) } } else { qWarning() << "qml cannot find file:" << fileName; - return; + return false; } } @@ -1112,9 +1013,7 @@ void QDeclarativeViewer::openQml(const QString& file_or_url) qWarning() << "Wall startup time:" << t.elapsed(); -#ifdef QTOPIA - show(); -#endif + return true; } void QDeclarativeViewer::startNetwork() @@ -1500,8 +1399,13 @@ void QDeclarativeViewer::setUseNativeFileBrowser(bool use) void QDeclarativeViewer::registerTypes() { - // registering only for exposing the DeviceOrientation::Orientation enum - qmlRegisterUncreatableType<DeviceOrientation>("Qt",4,6,"Orientation"); + static bool registered = false; + + if (!registered) { + // registering only for exposing the DeviceOrientation::Orientation enum + qmlRegisterUncreatableType<DeviceOrientation>("Qt",4,6,"Orientation"); + registered = true; + } } QT_END_NAMESPACE |