00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "qmlapplicationviewer.h"
00012
00013 #include <QtCore/QCoreApplication>
00014 #include <QtCore/QDir>
00015 #include <QtCore/QFileInfo>
00016 #include <QtDeclarative/QDeclarativeComponent>
00017 #include <QtDeclarative/QDeclarativeEngine>
00018 #include <QtDeclarative/QDeclarativeContext>
00019
00020 #if defined(QMLJSDEBUGGER)
00021 #include <qt_private/qdeclarativedebughelper_p.h>
00022 #endif
00023
00024 #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
00025 #include <jsdebuggeragent.h>
00026 #endif
00027 #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
00028 #include <qdeclarativeviewobserver.h>
00029 #endif
00030
00031 #if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK)
00032 #include <eikenv.h>
00033 #include <eikappui.h>
00034 #include <aknenv.h>
00035 #include <aknappui.h>
00036 #endif // Q_OS_SYMBIAN && ORIENTATIONLOCK
00037
00038 #if defined(QMLJSDEBUGGER)
00039
00040
00041 struct QmlJsDebuggingEnabler
00042 {
00043 QmlJsDebuggingEnabler()
00044 {
00045 QDeclarativeDebugHelper::enableDebugging();
00046 }
00047 };
00048
00049
00050 static QmlJsDebuggingEnabler enableDebuggingHelper;
00051
00052 #endif // QMLJSDEBUGGER
00053
00054 class QmlApplicationViewerPrivate
00055 {
00056 QString mainQmlFile;
00057 friend class QmlApplicationViewer;
00058 static QString adjustPath(const QString &path);
00059 };
00060
00061 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
00062 {
00063 #ifdef Q_OS_UNIX
00064 #ifdef Q_OS_MAC
00065 if (!QDir::isAbsolutePath(path))
00066 return QCoreApplication::applicationDirPath()
00067 + QLatin1String("/../Resources/") + path;
00068 #else
00069 const QString pathInShareDir = QCoreApplication::applicationDirPath()
00070 + QLatin1String("/../share/")
00071 + QFileInfo(QCoreApplication::applicationFilePath()).fileName()
00072 + QLatin1Char('/') + path;
00073 if (QFileInfo(pathInShareDir).exists())
00074 return pathInShareDir;
00075 #endif
00076 #endif
00077 return path;
00078 }
00079
00080 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
00081 QDeclarativeView(parent),
00082 m_d(new QmlApplicationViewerPrivate)
00083 {
00084 connect(engine(), SIGNAL(quit()), SLOT(close()));
00085 setResizeMode(QDeclarativeView::SizeRootObjectToView);
00086 #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
00087 new QmlJSDebugger::JSDebuggerAgent(engine());
00088 #endif
00089 #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
00090 new QmlJSDebugger::QDeclarativeViewObserver(this, parent);
00091 #endif
00092 }
00093
00094 QmlApplicationViewer::~QmlApplicationViewer()
00095 {
00096 delete m_d;
00097 }
00098
00099 void QmlApplicationViewer::setMainQmlFile(const QString &file)
00100 {
00101 m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
00102 setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
00103 }
00104
00105 void QmlApplicationViewer::addImportPath(const QString &path)
00106 {
00107 engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
00108 }
00109
00110 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
00111 {
00112 #ifdef Q_OS_SYMBIAN
00113 if (orientation != ScreenOrientationAuto) {
00114 #if defined(ORIENTATIONLOCK)
00115 const CAknAppUiBase::TAppUiOrientation uiOrientation =
00116 (orientation == ScreenOrientationLockPortrait) ? CAknAppUi::EAppUiOrientationPortrait
00117 : CAknAppUi::EAppUiOrientationLandscape;
00118 CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
00119 TRAPD(error,
00120 if (appUi)
00121 appUi->SetOrientationL(uiOrientation);
00122 );
00123 Q_UNUSED(error)
00124 #else // ORIENTATIONLOCK
00125 qWarning("'ORIENTATIONLOCK' needs to be defined on Symbian when locking the orientation.");
00126 #endif // ORIENTATIONLOCK
00127 }
00128 #elif defined(Q_WS_MAEMO_5)
00129 Qt::WidgetAttribute attribute;
00130 switch (orientation) {
00131 case ScreenOrientationLockPortrait:
00132 attribute = Qt::WA_Maemo5PortraitOrientation;
00133 break;
00134 case ScreenOrientationLockLandscape:
00135 attribute = Qt::WA_Maemo5LandscapeOrientation;
00136 break;
00137 case ScreenOrientationAuto:
00138 default:
00139 attribute = Qt::WA_Maemo5AutoOrientation;
00140 break;
00141 }
00142 setAttribute(attribute, true);
00143 #else // Q_OS_SYMBIAN
00144 Q_UNUSED(orientation);
00145 #endif // Q_OS_SYMBIAN
00146 }
00147
00148 void QmlApplicationViewer::showExpanded()
00149 {
00150 #ifdef Q_OS_SYMBIAN
00151 showFullScreen();
00152 #elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
00153 showMaximized();
00154 #else
00155 show();
00156 #endif
00157 }