1 // checksum 0xee24 version 0x70013
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/QDir>
14 #include <QtCore/QFileInfo>
15 #include <QtGui/QApplication>
16 #include <QtDeclarative/QDeclarativeComponent>
17 #include <QtDeclarative/QDeclarativeEngine>
18 #include <QtDeclarative/QDeclarativeContext>
20 #include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
22 #ifdef HARMATTAN_BOOSTER
23 #include <MDeclarativeCache>
26 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
28 #include <qt_private/qdeclarativedebughelper_p.h>
30 #if !defined(NO_JSDEBUGGER)
31 #include <jsdebuggeragent.h>
33 #if !defined(NO_QMLOBSERVER)
34 #include <qdeclarativeviewobserver.h>
37 // Enable debugging before any QDeclarativeEngine is created
38 struct QmlJsDebuggingEnabler
40 QmlJsDebuggingEnabler()
42 QDeclarativeDebugHelper::enableDebugging();
46 // Execute code in constructor before first QDeclarativeEngine is instantiated
47 static QmlJsDebuggingEnabler enableDebuggingHelper;
49 #endif // QMLJSDEBUGGER
51 class QmlApplicationViewerPrivate
54 friend class QmlApplicationViewer;
55 static QString adjustPath(const QString &path);
58 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
62 if (!QDir::isAbsolutePath(path))
63 return QString::fromLatin1("%1/../Resources/%2")
64 .arg(QCoreApplication::applicationDirPath(), path);
66 const QString pathInInstallDir =
67 QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path);
68 if (QFileInfo(pathInInstallDir).exists())
69 return pathInInstallDir;
75 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
76 : QDeclarativeView(parent)
77 , d(new QmlApplicationViewerPrivate())
79 connect(engine(), SIGNAL(quit()), SLOT(close()));
80 setResizeMode(QDeclarativeView::SizeRootObjectToView);
81 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
82 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
83 #if !defined(NO_JSDEBUGGER)
84 new QmlJSDebugger::JSDebuggerAgent(engine());
86 #if !defined(NO_QMLOBSERVER)
87 new QmlJSDebugger::QDeclarativeViewObserver(this, this);
92 QmlApplicationViewer::~QmlApplicationViewer()
97 QmlApplicationViewer *QmlApplicationViewer::create()
99 return new QmlApplicationViewer();
102 void QmlApplicationViewer::setMainQmlFile(const QString &file)
104 d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
105 setSource(QUrl::fromLocalFile(d->mainQmlFile));
108 void QmlApplicationViewer::addImportPath(const QString &path)
110 engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
113 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
115 #if defined(Q_OS_SYMBIAN)
116 // If the version of Qt on the device is < 4.7.2, that attribute won't work
117 if (orientation != ScreenOrientationAuto) {
118 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
119 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
120 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
124 #endif // Q_OS_SYMBIAN
126 Qt::WidgetAttribute attribute;
127 switch (orientation) {
128 #if QT_VERSION < 0x040702
129 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
130 case ScreenOrientationLockPortrait:
131 attribute = static_cast<Qt::WidgetAttribute>(128);
133 case ScreenOrientationLockLandscape:
134 attribute = static_cast<Qt::WidgetAttribute>(129);
137 case ScreenOrientationAuto:
138 attribute = static_cast<Qt::WidgetAttribute>(130);
140 #else // QT_VERSION < 0x040702
141 case ScreenOrientationLockPortrait:
142 attribute = Qt::WA_LockPortraitOrientation;
144 case ScreenOrientationLockLandscape:
145 attribute = Qt::WA_LockLandscapeOrientation;
148 case ScreenOrientationAuto:
149 attribute = Qt::WA_AutoOrientation;
151 #endif // QT_VERSION < 0x040702
153 setAttribute(attribute, true);
156 void QmlApplicationViewer::showExpanded()
158 #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
160 #elif defined(Q_WS_MAEMO_5)
167 QApplication *createApplication(int &argc, char **argv)
169 #ifdef HARMATTAN_BOOSTER
170 return MDeclarativeCache::qApplication(argc, argv);
172 return new QApplication(argc, argv);