1 // checksum 0x78c version 0x60010
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 <QtDeclarative/QDeclarativeComponent>
16 #include <QtDeclarative/QDeclarativeEngine>
17 #include <QtDeclarative/QDeclarativeContext>
18 #include <QtGui/QApplication>
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
53 QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {}
56 QDeclarativeView *view;
57 friend class QmlApplicationViewer;
58 QString adjustPath(const QString &path);
61 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
65 if (!QDir::isAbsolutePath(path))
66 return QCoreApplication::applicationDirPath()
67 + QLatin1String("/../Resources/") + path;
69 QString pathInInstallDir;
70 const QString applicationDirPath = QCoreApplication::applicationDirPath();
71 pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path);
73 if (QFileInfo(pathInInstallDir).exists())
74 return pathInInstallDir;
80 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
81 : QDeclarativeView(parent)
82 , d(new QmlApplicationViewerPrivate(this))
84 connect(engine(), SIGNAL(quit()), SLOT(close()));
85 setResizeMode(QDeclarativeView::SizeRootObjectToView);
86 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
87 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
88 #if !defined(NO_JSDEBUGGER)
89 new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
91 #if !defined(NO_QMLOBSERVER)
92 new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
97 QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, QWidget *parent)
98 : QDeclarativeView(parent)
99 , d(new QmlApplicationViewerPrivate(view))
101 connect(view->engine(), SIGNAL(quit()), view, SLOT(close()));
102 view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
103 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
104 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
105 #if !defined(NO_JSDEBUGGER)
106 new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
108 #if !defined(NO_QMLOBSERVER)
109 new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
114 QmlApplicationViewer::~QmlApplicationViewer()
119 QmlApplicationViewer *QmlApplicationViewer::create()
121 #ifdef HARMATTAN_BOOSTER
122 return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0);
124 return new QmlApplicationViewer();
128 void QmlApplicationViewer::setMainQmlFile(const QString &file)
130 d->mainQmlFile = d->adjustPath(file);
131 d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile));
134 void QmlApplicationViewer::addImportPath(const QString &path)
136 d->view->engine()->addImportPath(d->adjustPath(path));
139 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
141 #if defined(Q_OS_SYMBIAN)
142 // If the version of Qt on the device is < 4.7.2, that attribute won't work
143 if (orientation != ScreenOrientationAuto) {
144 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
145 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
146 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
150 #endif // Q_OS_SYMBIAN
152 Qt::WidgetAttribute attribute;
153 switch (orientation) {
154 #if QT_VERSION < 0x040702
155 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
156 case ScreenOrientationLockPortrait:
157 attribute = static_cast<Qt::WidgetAttribute>(128);
159 case ScreenOrientationLockLandscape:
160 attribute = static_cast<Qt::WidgetAttribute>(129);
163 case ScreenOrientationAuto:
164 attribute = static_cast<Qt::WidgetAttribute>(130);
166 #else // QT_VERSION < 0x040702
167 case ScreenOrientationLockPortrait:
168 attribute = Qt::WA_LockPortraitOrientation;
170 case ScreenOrientationLockLandscape:
171 attribute = Qt::WA_LockLandscapeOrientation;
174 case ScreenOrientationAuto:
175 attribute = Qt::WA_AutoOrientation;
177 #endif // QT_VERSION < 0x040702
179 setAttribute(attribute, true);
182 void QmlApplicationViewer::showExpanded()
184 #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
185 d->view->showFullScreen();
186 #elif defined(Q_WS_MAEMO_5)
187 d->view->showMaximized();
193 QApplication *createApplication(int &argc, char **argv)
195 #ifdef HARMATTAN_BOOSTER
196 return MDeclarativeCache::qApplication(argc, argv);
198 return new QApplication(argc, argv);