michael@0: // checksum 0x7895 version 0x4000b michael@0: /* michael@0: This file was generated by the Qt Quick Application wizard of Qt Creator. michael@0: QmlApplicationViewer is a convenience class containing mobile device specific michael@0: code such as screen orientation handling. Also QML paths and debugging are michael@0: handled here. michael@0: It is recommended not to modify this file, since newer versions of Qt Creator michael@0: may offer an updated version of it. michael@0: */ michael@0: michael@0: #include "qmlapplicationviewer.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #if defined(QMLJSDEBUGGER) michael@0: #include michael@0: #endif michael@0: michael@0: #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER) michael@0: #include michael@0: #endif michael@0: #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER) michael@0: #include michael@0: #endif michael@0: michael@0: #if defined(QMLJSDEBUGGER) michael@0: michael@0: // Enable debugging before any QDeclarativeEngine is created michael@0: struct QmlJsDebuggingEnabler michael@0: { michael@0: QmlJsDebuggingEnabler() michael@0: { michael@0: QDeclarativeDebugHelper::enableDebugging(); michael@0: } michael@0: }; michael@0: michael@0: // Execute code in constructor before first QDeclarativeEngine is instantiated michael@0: static QmlJsDebuggingEnabler enableDebuggingHelper; michael@0: michael@0: #endif // QMLJSDEBUGGER michael@0: michael@0: class QmlApplicationViewerPrivate michael@0: { michael@0: QString mainQmlFile; michael@0: friend class QmlApplicationViewer; michael@0: static QString adjustPath(const QString &path); michael@0: }; michael@0: michael@0: QString QmlApplicationViewerPrivate::adjustPath(const QString &path) michael@0: { michael@0: #ifdef Q_OS_UNIX michael@0: #ifdef Q_OS_MAC michael@0: if (!QDir::isAbsolutePath(path)) michael@0: return QCoreApplication::applicationDirPath() michael@0: + QLatin1String("/../Resources/") + path; michael@0: #else michael@0: const QString pathInInstallDir = QCoreApplication::applicationDirPath() michael@0: + QLatin1String("/../") + path; michael@0: if (pathInInstallDir.contains(QLatin1String("opt")) michael@0: && pathInInstallDir.contains(QLatin1String("bin")) michael@0: && QFileInfo(pathInInstallDir).exists()) { michael@0: return pathInInstallDir; michael@0: } michael@0: #endif michael@0: #endif michael@0: return path; michael@0: } michael@0: michael@0: QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) : michael@0: QDeclarativeView(parent), michael@0: m_d(new QmlApplicationViewerPrivate) michael@0: { michael@0: connect(engine(), SIGNAL(quit()), SLOT(close())); michael@0: setResizeMode(QDeclarativeView::SizeRootObjectToView); michael@0: #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER) michael@0: new QmlJSDebugger::JSDebuggerAgent(engine()); michael@0: #endif michael@0: #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER) michael@0: new QmlJSDebugger::QDeclarativeViewObserver(this, this); michael@0: #endif michael@0: } michael@0: michael@0: QmlApplicationViewer::~QmlApplicationViewer() michael@0: { michael@0: delete m_d; michael@0: } michael@0: michael@0: void QmlApplicationViewer::setMainQmlFile(const QString &file) michael@0: { michael@0: m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file); michael@0: setSource(QUrl::fromLocalFile(m_d->mainQmlFile)); michael@0: } michael@0: michael@0: void QmlApplicationViewer::addImportPath(const QString &path) michael@0: { michael@0: engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path)); michael@0: } michael@0: michael@0: void QmlApplicationViewer::setOrientation(ScreenOrientation orientation) michael@0: { michael@0: #if defined(Q_OS_SYMBIAN) michael@0: // If the version of Qt on the device is < 4.7.2, that attribute won't work michael@0: if (orientation != ScreenOrientationAuto) { michael@0: const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.')); michael@0: if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) { michael@0: qWarning("Screen orientation locking only supported with Qt 4.7.2 and above"); michael@0: return; michael@0: } michael@0: } michael@0: #endif // Q_OS_SYMBIAN michael@0: michael@0: Qt::WidgetAttribute attribute; michael@0: switch (orientation) { michael@0: #if QT_VERSION < 0x040702 michael@0: // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes michael@0: case ScreenOrientationLockPortrait: michael@0: attribute = static_cast(128); michael@0: break; michael@0: case ScreenOrientationLockLandscape: michael@0: attribute = static_cast(129); michael@0: break; michael@0: default: michael@0: case ScreenOrientationAuto: michael@0: attribute = static_cast(130); michael@0: break; michael@0: #else // QT_VERSION < 0x040702 michael@0: case ScreenOrientationLockPortrait: michael@0: attribute = Qt::WA_LockPortraitOrientation; michael@0: break; michael@0: case ScreenOrientationLockLandscape: michael@0: attribute = Qt::WA_LockLandscapeOrientation; michael@0: break; michael@0: default: michael@0: case ScreenOrientationAuto: michael@0: attribute = Qt::WA_AutoOrientation; michael@0: break; michael@0: #endif // QT_VERSION < 0x040702 michael@0: }; michael@0: setAttribute(attribute, true); michael@0: } michael@0: michael@0: void QmlApplicationViewer::showExpanded() michael@0: { michael@0: #ifdef Q_OS_SYMBIAN michael@0: showFullScreen(); michael@0: #elif defined(Q_WS_MAEMO_5) michael@0: showMaximized(); michael@0: #else michael@0: show(); michael@0: #endif michael@0: }