diff options
Diffstat (limited to 'Common/QtQuick2ApplicationViewer.cpp')
-rwxr-xr-x | Common/QtQuick2ApplicationViewer.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/Common/QtQuick2ApplicationViewer.cpp b/Common/QtQuick2ApplicationViewer.cpp new file mode 100755 index 00000000..f2efdf3d --- /dev/null +++ b/Common/QtQuick2ApplicationViewer.cpp @@ -0,0 +1,104 @@ +/* + This file was generated by the Qt Quick 2 Application wizard of Qt Creator. + QtQuick2ApplicationViewer is a convenience class containing mobile device specific + code such as screen orientation handling. Also QML paths and debugging are + handled here. + It is recommended not to modify this file, since newer versions of Qt Creator + may offer an updated version of it. +*/ + +#include "QtQuick2ApplicationViewer.h" + +#include <QApplication> +#include <QtCore/QDir> +#include <QtQml/QQmlEngine> + +class QtQuick2ApplicationViewerPrivate +{ + QString mainQmlFile; + friend class QtQuick2ApplicationViewer; + static QString adjustPath(const QString &path); +}; + +QString QtQuick2ApplicationViewerPrivate::adjustPath(const QString &path) +{ + if (path.startsWith(QLatin1String("qrc:"))) + return path; +#if defined(Q_OS_IOS) + if (!QDir::isAbsolutePath(path)) + return QString::fromLatin1("%1/%2") + .arg(QCoreApplication::applicationDirPath(), path); +#elif defined(Q_OS_MAC) + if (!QDir::isAbsolutePath(path)) + return QString::fromLatin1("%1/../Resources/%2") + .arg(QCoreApplication::applicationDirPath(), path); +#elif defined(Q_OS_BLACKBERRY) + if (!QDir::isAbsolutePath(path)) + return QString::fromLatin1("app/native/%1").arg(path); +#elif !defined(Q_OS_ANDROID) + QString pathInInstallDir = + QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path); + if (QFileInfo(pathInInstallDir).exists()) + return pathInInstallDir; + pathInInstallDir = + QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), path); + if (QFileInfo(pathInInstallDir).exists()) + return pathInInstallDir; +#elif defined(Q_OS_ANDROID_NO_SDK) + return QLatin1String("/data/user/qt/") + path; +#endif + return path; +} + +QtQuick2ApplicationViewer::QtQuick2ApplicationViewer(QWindow *parent) + : QQuickView(parent) + , d(new QtQuick2ApplicationViewerPrivate()) +{ + connect(engine(), SIGNAL(quit()), SLOT(close())); + setResizeMode(QQuickView::SizeRootObjectToView); +} + +QtQuick2ApplicationViewer::~QtQuick2ApplicationViewer() +{ + delete d; +} + +void QtQuick2ApplicationViewer::setMainQmlFile(const QString &file) +{ + if (file.startsWith(QLatin1String("qrc:"))) { + d->mainQmlFile = file; + setSource(QUrl(d->mainQmlFile)); + return; + } + d->mainQmlFile = QtQuick2ApplicationViewerPrivate::adjustPath(file); +#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) + QUrl qmlUrl(QUrl(QLatin1String("assets:/")+d->mainQmlFile)); +#else + QUrl qmlUrl(QUrl::fromLocalFile(d->mainQmlFile)); +#endif + if (d->mainQmlFile.startsWith(QLatin1String("qrc:/"))) { + qmlUrl = QUrl(d->mainQmlFile); + } + setSource(qmlUrl); +} + +void QtQuick2ApplicationViewer::addImportPath(const QString &path) +{ + engine()->addImportPath(QtQuick2ApplicationViewerPrivate::adjustPath(path)); +} + +void QtQuick2ApplicationViewer::showExpanded() +{ + if (QApplication::platformName() == QLatin1String("qnx") || + QApplication::platformName() == QLatin1String("eglfs")) { + showFullScreen(); + } else { + show(); + } + return; +#if defined(Q_OS_QNX) //|| defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(Q_OS_MAEMO) + showFullScreen(); +#else + show(); +#endif +} |