00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "qmlapplicationviewer.h"
00041 #if defined(Q_OS_SYMBIAN)
00042 #include "mifimageprovider.h"
00043 #endif
00044
00045 #include <QtCore/QCoreApplication>
00046 #include <QtCore/QDir>
00047 #include <QtCore/QFileInfo>
00048 #include <QtDeclarative/QDeclarativeComponent>
00049 #include <QtDeclarative/QDeclarativeEngine>
00050 #include <QtDeclarative/QDeclarativeContext>
00051
00052 #if defined(QMLJSDEBUGGER)
00053 #include <qt_private/qdeclarativedebughelper_p.h>
00054 #endif
00055
00056 #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
00057 #include <jsdebuggeragent.h>
00058 #endif
00059 #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
00060 #include <qdeclarativeviewobserver.h>
00061 #endif
00062
00063 #if defined(QMLJSDEBUGGER)
00064
00065
00066 struct QmlJsDebuggingEnabler
00067 {
00068 QmlJsDebuggingEnabler()
00069 {
00070 QDeclarativeDebugHelper::enableDebugging();
00071 }
00072 };
00073
00074
00075 static QmlJsDebuggingEnabler enableDebuggingHelper;
00076
00077 #endif // QMLJSDEBUGGER
00078
00079 class QmlApplicationViewerPrivate
00080 {
00081 QString mainQmlFile;
00082 friend class QmlApplicationViewer;
00083 static QString adjustPath(const QString &path);
00084 };
00085
00086 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
00087 {
00088 #ifdef Q_OS_UNIX
00089 #ifdef Q_OS_MAC
00090 if (!QDir::isAbsolutePath(path))
00091 return QCoreApplication::applicationDirPath()
00092 + QLatin1String("/../Resources/") + path;
00093 #else
00094 const QString pathInInstallDir = QCoreApplication::applicationDirPath()
00095 + QLatin1String("/../") + path;
00096 if (pathInInstallDir.contains(QLatin1String("opt"))
00097 && pathInInstallDir.contains(QLatin1String("bin"))
00098 && QFileInfo(pathInInstallDir).exists()) {
00099 return pathInInstallDir;
00100 }
00101 #endif
00102 #endif
00103 return path;
00104 }
00105
00106 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
00107 QDeclarativeView(parent),
00108 m_d(new QmlApplicationViewerPrivate)
00109 {
00110 connect(engine(), SIGNAL(quit()), SLOT(close()));
00111 setResizeMode(QDeclarativeView::SizeRootObjectToView);
00112 #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
00113 new QmlJSDebugger::JSDebuggerAgent(engine());
00114 #endif
00115 #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
00116 new QmlJSDebugger::QDeclarativeViewObserver(this, this);
00117 #endif
00118
00119 #if defined(Q_OS_SYMBIAN)
00120 engine()->addImageProvider(QLatin1String("mifprovider"), new MifImageProvider());
00121 #endif
00122 }
00123
00124 QmlApplicationViewer::~QmlApplicationViewer()
00125 {
00126 delete m_d;
00127 }
00128
00129 void QmlApplicationViewer::setMainQmlFile(const QString &file)
00130 {
00131 m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
00132 setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
00133 }
00134
00135 void QmlApplicationViewer::addImportPath(const QString &path)
00136 {
00137 engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
00138 }
00139
00140 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
00141 {
00142 #if defined(Q_OS_SYMBIAN)
00143
00144 if (orientation != ScreenOrientationAuto) {
00145 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
00146 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
00147 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
00148 return;
00149 }
00150 }
00151 #endif // Q_OS_SYMBIAN
00152
00153 Qt::WidgetAttribute attribute;
00154 switch (orientation) {
00155 #if QT_VERSION < 0x040702
00156
00157 case ScreenOrientationLockPortrait:
00158 attribute = static_cast<Qt::WidgetAttribute>(128);
00159 break;
00160 case ScreenOrientationLockLandscape:
00161 attribute = static_cast<Qt::WidgetAttribute>(129);
00162 break;
00163 default:
00164 case ScreenOrientationAuto:
00165 attribute = static_cast<Qt::WidgetAttribute>(130);
00166 break;
00167 #else // QT_VERSION < 0x040702
00168 case ScreenOrientationLockPortrait:
00169 attribute = Qt::WA_LockPortraitOrientation;
00170 break;
00171 case ScreenOrientationLockLandscape:
00172 attribute = Qt::WA_LockLandscapeOrientation;
00173 break;
00174 default:
00175 case ScreenOrientationAuto:
00176 attribute = Qt::WA_AutoOrientation;
00177 break;
00178 #endif // QT_VERSION < 0x040702
00179 };
00180 setAttribute(attribute, true);
00181 }
00182
00183 void QmlApplicationViewer::showExpanded()
00184 {
00185 #ifdef Q_OS_SYMBIAN
00186 showFullScreen();
00187 #elif defined(Q_WS_MAEMO_5)
00188 showMaximized();
00189 #else
00190 show();
00191 #endif
00192 }