|
1 // checksum 0xdf1f version 0x10008 |
|
2 #include "qmlapplicationviewer.h" |
|
3 |
|
4 #include <QtCore/QCoreApplication> |
|
5 #include <QtCore/QDir> |
|
6 #include <QtCore/QFileInfo> |
|
7 #include <QtDeclarative/QDeclarativeComponent> |
|
8 #include <QtDeclarative/QDeclarativeEngine> |
|
9 #include <QtDeclarative/QDeclarativeContext> |
|
10 |
|
11 #if defined(QMLJSDEBUGGER) |
|
12 #include <jsdebuggeragent.h> |
|
13 #endif |
|
14 #if defined(QMLOBSERVER) |
|
15 #include <qdeclarativeviewobserver.h> |
|
16 #endif |
|
17 |
|
18 #if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK) |
|
19 #include <eikenv.h> |
|
20 #include <eikappui.h> |
|
21 #include <aknenv.h> |
|
22 #include <aknappui.h> |
|
23 #endif // Q_OS_SYMBIAN && ORIENTATIONLOCK |
|
24 |
|
25 class QmlApplicationViewerPrivate |
|
26 { |
|
27 QString mainQmlFile; |
|
28 friend class QmlApplicationViewer; |
|
29 static QString adjustPath(const QString &path); |
|
30 }; |
|
31 |
|
32 QString QmlApplicationViewerPrivate::adjustPath(const QString &path) |
|
33 { |
|
34 #ifdef Q_OS_UNIX |
|
35 #ifdef Q_OS_MAC |
|
36 if (!QDir::isAbsolutePath(path)) |
|
37 return QCoreApplication::applicationDirPath() |
|
38 + QLatin1String("/../Resources/") + path; |
|
39 #else |
|
40 const QString pathInShareDir = QCoreApplication::applicationDirPath() |
|
41 + QLatin1String("/../share/") |
|
42 + QFileInfo(QCoreApplication::applicationFilePath()).fileName() |
|
43 + QLatin1Char('/') + path; |
|
44 if (QFileInfo(pathInShareDir).exists()) |
|
45 return pathInShareDir; |
|
46 #endif |
|
47 #endif |
|
48 return path; |
|
49 } |
|
50 |
|
51 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) : |
|
52 QDeclarativeView(parent), |
|
53 m_d(new QmlApplicationViewerPrivate) |
|
54 { |
|
55 connect(engine(), SIGNAL(quit()), SLOT(close())); |
|
56 setResizeMode(QDeclarativeView::SizeRootObjectToView); |
|
57 #ifdef QMLJSDEBUGGER |
|
58 new QmlJSDebugger::JSDebuggerAgent(engine()); |
|
59 #endif |
|
60 #ifdef QMLOBSERVER |
|
61 new QmlJSDebugger::QDeclarativeViewObserver(this, parent); |
|
62 #endif |
|
63 } |
|
64 |
|
65 QmlApplicationViewer::~QmlApplicationViewer() |
|
66 { |
|
67 delete m_d; |
|
68 } |
|
69 |
|
70 void QmlApplicationViewer::setMainQmlFile(const QString &file) |
|
71 { |
|
72 m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file); |
|
73 setSource(QUrl::fromLocalFile(m_d->mainQmlFile)); |
|
74 } |
|
75 |
|
76 void QmlApplicationViewer::addImportPath(const QString &path) |
|
77 { |
|
78 engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path)); |
|
79 } |
|
80 |
|
81 void QmlApplicationViewer::setOrientation(Orientation orientation) |
|
82 { |
|
83 #ifdef Q_OS_SYMBIAN |
|
84 if (orientation != Auto) { |
|
85 #if defined(ORIENTATIONLOCK) |
|
86 const CAknAppUiBase::TAppUiOrientation uiOrientation = |
|
87 (orientation == LockPortrait) ? CAknAppUi::EAppUiOrientationPortrait |
|
88 : CAknAppUi::EAppUiOrientationLandscape; |
|
89 CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi()); |
|
90 TRAPD(error, |
|
91 if (appUi) |
|
92 appUi->SetOrientationL(uiOrientation); |
|
93 ); |
|
94 #else // ORIENTATIONLOCK |
|
95 qWarning("'ORIENTATIONLOCK' needs to be defined on Symbian when locking the orientation."); |
|
96 #endif // ORIENTATIONLOCK |
|
97 } |
|
98 #elif defined(Q_WS_MAEMO_5) |
|
99 Qt::WidgetAttribute attribute; |
|
100 switch (orientation) { |
|
101 case LockPortrait: |
|
102 attribute = Qt::WA_Maemo5PortraitOrientation; |
|
103 break; |
|
104 case LockLandscape: |
|
105 attribute = Qt::WA_Maemo5LandscapeOrientation; |
|
106 break; |
|
107 case Auto: |
|
108 default: |
|
109 attribute = Qt::WA_Maemo5AutoOrientation; |
|
110 break; |
|
111 } |
|
112 setAttribute(attribute, true); |
|
113 #else // Q_OS_SYMBIAN |
|
114 Q_UNUSED(orientation); |
|
115 #endif // Q_OS_SYMBIAN |
|
116 } |
|
117 |
|
118 void QmlApplicationViewer::show() |
|
119 { |
|
120 #ifdef Q_OS_SYMBIAN |
|
121 showFullScreen(); |
|
122 #elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6) |
|
123 showMaximized(); |
|
124 #else |
|
125 QDeclarativeView::show(); |
|
126 #endif |
|
127 } |