|
| 1 | +// checksum 0x4f6f version 0x90005 |
| 2 | +/* |
| 3 | + This file was generated by the Qt Quick 2 Application wizard of Qt Creator. |
| 4 | + QtQuick2ApplicationViewer is a convenience class containing mobile device specific |
| 5 | + code such as screen orientation handling. Also QML paths and debugging are |
| 6 | + handled here. |
| 7 | + It is recommended not to modify this file, since newer versions of Qt Creator |
| 8 | + may offer an updated version of it. |
| 9 | +*/ |
| 10 | + |
| 11 | +#include "qtquick2applicationviewer.h" |
| 12 | + |
| 13 | +#include <QtCore/QCoreApplication> |
| 14 | +#include <QtCore/QDir> |
| 15 | +#include <QtQml/QQmlEngine> |
| 16 | + |
| 17 | +class QtQuick2ApplicationViewerPrivate |
| 18 | +{ |
| 19 | + QString mainQmlFile; |
| 20 | + friend class QtQuick2ApplicationViewer; |
| 21 | + static QString adjustPath(const QString &path); |
| 22 | +}; |
| 23 | + |
| 24 | +QString QtQuick2ApplicationViewerPrivate::adjustPath(const QString &path) |
| 25 | +{ |
| 26 | +#if defined(Q_OS_MAC) |
| 27 | + if (!QDir::isAbsolutePath(path)) |
| 28 | + return QString::fromLatin1("%1/../Resources/%2") |
| 29 | + .arg(QCoreApplication::applicationDirPath(), path); |
| 30 | +#elif defined(Q_OS_BLACKBERRY) |
| 31 | + if (!QDir::isAbsolutePath(path)) |
| 32 | + return QString::fromLatin1("app/native/%1").arg(path); |
| 33 | +#elif !defined(Q_OS_ANDROID) |
| 34 | + QString pathInInstallDir = |
| 35 | + QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path); |
| 36 | + if (QFileInfo(pathInInstallDir).exists()) |
| 37 | + return pathInInstallDir; |
| 38 | + pathInInstallDir = |
| 39 | + QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), path); |
| 40 | + if (QFileInfo(pathInInstallDir).exists()) |
| 41 | + return pathInInstallDir; |
| 42 | +#endif |
| 43 | + return path; |
| 44 | +} |
| 45 | + |
| 46 | +QtQuick2ApplicationViewer::QtQuick2ApplicationViewer(QWindow *parent) |
| 47 | + : QQuickView(parent) |
| 48 | + , d(new QtQuick2ApplicationViewerPrivate()) |
| 49 | +{ |
| 50 | + connect(engine(), SIGNAL(quit()), SLOT(close())); |
| 51 | + setResizeMode(QQuickView::SizeRootObjectToView); |
| 52 | +} |
| 53 | + |
| 54 | +QtQuick2ApplicationViewer::~QtQuick2ApplicationViewer() |
| 55 | +{ |
| 56 | + delete d; |
| 57 | +} |
| 58 | + |
| 59 | +void QtQuick2ApplicationViewer::setMainQmlFile(const QString &file) |
| 60 | +{ |
| 61 | + d->mainQmlFile = QtQuick2ApplicationViewerPrivate::adjustPath(file); |
| 62 | +#ifdef Q_OS_ANDROID |
| 63 | + setSource(QUrl(QLatin1String("assets:/")+d->mainQmlFile)); |
| 64 | +#else |
| 65 | + setSource(QUrl::fromLocalFile(d->mainQmlFile)); |
| 66 | +#endif |
| 67 | +} |
| 68 | + |
| 69 | +void QtQuick2ApplicationViewer::addImportPath(const QString &path) |
| 70 | +{ |
| 71 | + engine()->addImportPath(QtQuick2ApplicationViewerPrivate::adjustPath(path)); |
| 72 | +} |
| 73 | + |
| 74 | +void QtQuick2ApplicationViewer::showExpanded() |
| 75 | +{ |
| 76 | +#if defined(Q_WS_SIMULATOR) || defined(Q_OS_QNX) |
| 77 | + showFullScreen(); |
| 78 | +#else |
| 79 | + show(); |
| 80 | +#endif |
| 81 | +} |
0 commit comments