1 // checksum 0xfe24 version 0x6000e
3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 QmlApplicationViewer is a convenience class containing mobile device specific
5 code such as screen orientation handling. Also QML paths and debugging are
7 It is recommended not to modify this file, since newer versions of Qt Creator
8 may offer an updated version of it.
11 #include "qmlapplicationviewer.h"
13 #include <QtCore/QCoreApplication>
14 #include <QtCore/QDir>
15 #include <QtCore/QFileInfo>
16 #include <QtDeclarative/QDeclarativeComponent>
17 #include <QtDeclarative/QDeclarativeEngine>
18 #include <QtDeclarative/QDeclarativeContext>
20 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
22 #include <qt_private/qdeclarativedebughelper_p.h>
24 #if !defined(NO_JSDEBUGGER)
25 #include <jsdebuggeragent.h>
27 #if !defined(NO_QMLOBSERVER)
28 #include <qdeclarativeviewobserver.h>
31 // Enable debugging before any QDeclarativeEngine is created
32 struct QmlJsDebuggingEnabler
34 QmlJsDebuggingEnabler()
36 QDeclarativeDebugHelper::enableDebugging();
40 // Execute code in constructor before first QDeclarativeEngine is instantiated
41 static QmlJsDebuggingEnabler enableDebuggingHelper;
43 #endif // QMLJSDEBUGGER
45 class QmlApplicationViewerPrivate
48 friend class QmlApplicationViewer;
49 static QString adjustPath(const QString &path);
52 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
56 if (!QDir::isAbsolutePath(path))
57 return QCoreApplication::applicationDirPath()
58 + QLatin1String("/../Resources/") + path;
60 const QString pathInInstallDir = QCoreApplication::applicationDirPath()
61 + QLatin1String("/../") + path;
62 if (pathInInstallDir.contains(QLatin1String("opt"))
63 && pathInInstallDir.contains(QLatin1String("bin"))
64 && QFileInfo(pathInInstallDir).exists()) {
65 return pathInInstallDir;
72 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
73 QDeclarativeView(parent),
74 m_d(new QmlApplicationViewerPrivate)
76 connect(engine(), SIGNAL(quit()), SLOT(close()));
77 setResizeMode(QDeclarativeView::SizeRootObjectToView);
78 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
79 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
80 #if !defined(NO_JSDEBUGGER)
81 new QmlJSDebugger::JSDebuggerAgent(engine());
83 #if !defined(NO_QMLOBSERVER)
84 new QmlJSDebugger::QDeclarativeViewObserver(this, this);
89 QmlApplicationViewer::~QmlApplicationViewer()
94 void QmlApplicationViewer::setMainQmlFile(const QString &file)
96 m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
97 setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
100 void QmlApplicationViewer::addImportPath(const QString &path)
102 engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
105 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
107 #if defined(Q_OS_SYMBIAN)
108 // If the version of Qt on the device is < 4.7.2, that attribute won't work
109 if (orientation != ScreenOrientationAuto) {
110 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
111 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
112 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
116 #endif // Q_OS_SYMBIAN
118 Qt::WidgetAttribute attribute;
119 switch (orientation) {
120 #if QT_VERSION < 0x040702
121 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
122 case ScreenOrientationLockPortrait:
123 attribute = static_cast<Qt::WidgetAttribute>(128);
125 case ScreenOrientationLockLandscape:
126 attribute = static_cast<Qt::WidgetAttribute>(129);
129 case ScreenOrientationAuto:
130 attribute = static_cast<Qt::WidgetAttribute>(130);
132 #else // QT_VERSION < 0x040702
133 case ScreenOrientationLockPortrait:
134 attribute = Qt::WA_LockPortraitOrientation;
136 case ScreenOrientationLockLandscape:
137 attribute = Qt::WA_LockLandscapeOrientation;
140 case ScreenOrientationAuto:
141 attribute = Qt::WA_AutoOrientation;
143 #endif // QT_VERSION < 0x040702
145 setAttribute(attribute, true);
148 void QmlApplicationViewer::showExpanded()
150 #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
152 #elif defined(Q_WS_MAEMO_5)