1 // checksum 0x28c7 version 0x2000a
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(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK)
36 #endif // Q_OS_SYMBIAN && ORIENTATIONLOCK
38 #if defined(QMLJSDEBUGGER)
40 // Enable debugging before any QDeclarativeEngine is created
41 struct QmlJsDebuggingEnabler
43 QmlJsDebuggingEnabler()
45 QDeclarativeDebugHelper::enableDebugging();
49 // Execute code in constructor before first QDeclarativeEngine is instantiated
50 static QmlJsDebuggingEnabler enableDebuggingHelper;
52 #endif // QMLJSDEBUGGER
54 class QmlApplicationViewerPrivate
57 friend class QmlApplicationViewer;
58 static 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 const QString pathInShareDir = QCoreApplication::applicationDirPath()
70 + QLatin1String("/../share/")
71 + QFileInfo(QCoreApplication::applicationFilePath()).fileName()
72 + QLatin1Char('/') + path;
73 if (QFileInfo(pathInShareDir).exists())
74 return pathInShareDir;
80 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
81 QDeclarativeView(parent),
82 m_d(new QmlApplicationViewerPrivate)
84 connect(engine(), SIGNAL(quit()), SLOT(close()));
85 setResizeMode(QDeclarativeView::SizeRootObjectToView);
86 #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
87 new QmlJSDebugger::JSDebuggerAgent(engine());
89 #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
90 new QmlJSDebugger::QDeclarativeViewObserver(this, parent);
94 QmlApplicationViewer::~QmlApplicationViewer()
99 void QmlApplicationViewer::setMainQmlFile(const QString &file)
101 m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
102 setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
105 void QmlApplicationViewer::addImportPath(const QString &path)
107 engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
110 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
113 if (orientation != ScreenOrientationAuto) {
114 #if defined(ORIENTATIONLOCK)
115 const CAknAppUiBase::TAppUiOrientation uiOrientation =
116 (orientation == ScreenOrientationLockPortrait) ? CAknAppUi::EAppUiOrientationPortrait
117 : CAknAppUi::EAppUiOrientationLandscape;
118 CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
121 appUi->SetOrientationL(uiOrientation);
124 #else // ORIENTATIONLOCK
125 qWarning("'ORIENTATIONLOCK' needs to be defined on Symbian when locking the orientation.");
126 #endif // ORIENTATIONLOCK
128 #elif defined(Q_WS_MAEMO_5)
129 Qt::WidgetAttribute attribute;
130 switch (orientation) {
131 case ScreenOrientationLockPortrait:
132 attribute = Qt::WA_Maemo5PortraitOrientation;
134 case ScreenOrientationLockLandscape:
135 attribute = Qt::WA_Maemo5LandscapeOrientation;
137 case ScreenOrientationAuto:
139 attribute = Qt::WA_Maemo5AutoOrientation;
142 setAttribute(attribute, true);
143 #else // Q_OS_SYMBIAN
144 Q_UNUSED(orientation);
145 #endif // Q_OS_SYMBIAN
148 void QmlApplicationViewer::showExpanded()
152 #elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)