1 // checksum 0x7895 version 0x4000b
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)
21 #include <qt_private/qdeclarativedebughelper_p.h>
24 #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
25 #include <jsdebuggeragent.h>
27 #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
28 #include <qdeclarativeviewobserver.h>
31 #if defined(QMLJSDEBUGGER)
33 // Enable debugging before any QDeclarativeEngine is created
34 struct QmlJsDebuggingEnabler
36 QmlJsDebuggingEnabler()
38 QDeclarativeDebugHelper::enableDebugging();
42 // Execute code in constructor before first QDeclarativeEngine is instantiated
43 static QmlJsDebuggingEnabler enableDebuggingHelper;
45 #endif // QMLJSDEBUGGER
47 class QmlApplicationViewerPrivate
50 friend class QmlApplicationViewer;
51 static QString adjustPath(const QString &path);
54 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
58 if (!QDir::isAbsolutePath(path))
59 return QCoreApplication::applicationDirPath()
60 + QLatin1String("/../Resources/") + path;
62 const QString pathInInstallDir = QCoreApplication::applicationDirPath()
63 + QLatin1String("/../") + path;
64 if (pathInInstallDir.contains(QLatin1String("opt"))
65 && pathInInstallDir.contains(QLatin1String("bin"))
66 && QFileInfo(pathInInstallDir).exists()) {
67 return pathInInstallDir;
74 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
75 QDeclarativeView(parent),
76 m_d(new QmlApplicationViewerPrivate)
78 connect(engine(), SIGNAL(quit()), SLOT(close()));
79 setResizeMode(QDeclarativeView::SizeRootObjectToView);
80 #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
81 new QmlJSDebugger::JSDebuggerAgent(engine());
83 #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
84 new QmlJSDebugger::QDeclarativeViewObserver(this, this);
88 QmlApplicationViewer::~QmlApplicationViewer()
93 void QmlApplicationViewer::setMainQmlFile(const QString &file)
95 m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
96 setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
99 void QmlApplicationViewer::addImportPath(const QString &path)
101 engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
104 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
106 #if defined(Q_OS_SYMBIAN)
107 // If the version of Qt on the device is < 4.7.2, that attribute won't work
108 if (orientation != ScreenOrientationAuto) {
109 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
110 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
111 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
115 #endif // Q_OS_SYMBIAN
117 Qt::WidgetAttribute attribute;
118 switch (orientation) {
119 #if QT_VERSION < 0x040702
120 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
121 case ScreenOrientationLockPortrait:
122 attribute = static_cast<Qt::WidgetAttribute>(128);
124 case ScreenOrientationLockLandscape:
125 attribute = static_cast<Qt::WidgetAttribute>(129);
128 case ScreenOrientationAuto:
129 attribute = static_cast<Qt::WidgetAttribute>(130);
131 #else // QT_VERSION < 0x040702
132 case ScreenOrientationLockPortrait:
133 attribute = Qt::WA_LockPortraitOrientation;
135 case ScreenOrientationLockLandscape:
136 attribute = Qt::WA_LockLandscapeOrientation;
139 case ScreenOrientationAuto:
140 attribute = Qt::WA_AutoOrientation;
142 #endif // QT_VERSION < 0x040702
144 setAttribute(attribute, true);
147 void QmlApplicationViewer::showExpanded()
151 #elif defined(Q_WS_MAEMO_5)