2010-11-01 17:03:46 +01:00
|
|
|
/*
|
|
|
|
|
This file was generated by the Qt Quick Application wizard of Qt Creator.
|
|
|
|
|
QmlApplicationViewer is a convenience class containing mobile device specific
|
|
|
|
|
code such as screen orientation handling. Also QML paths and debugging are
|
|
|
|
|
handled here.
|
|
|
|
|
It is recommended not to modify this file, since newer versions of Qt Creator
|
|
|
|
|
may offer an updated version of it.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-08-25 19:07:50 +02:00
|
|
|
#include "qmlapplicationviewer.h"
|
2010-07-15 11:58:37 +02:00
|
|
|
|
2010-07-30 10:49:11 +02:00
|
|
|
#include <QtCore/QCoreApplication>
|
2010-07-15 11:58:37 +02:00
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
#include <QtDeclarative/QDeclarativeComponent>
|
|
|
|
|
#include <QtDeclarative/QDeclarativeEngine>
|
|
|
|
|
#include <QtDeclarative/QDeclarativeContext>
|
|
|
|
|
|
2010-11-03 10:44:40 +01:00
|
|
|
#if defined(QMLJSDEBUGGER)
|
|
|
|
|
#include <qt_private/qdeclarativedebughelper_p.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-10-09 21:20:15 +02:00
|
|
|
#if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
|
2010-09-22 13:03:37 +02:00
|
|
|
#include <jsdebuggeragent.h>
|
|
|
|
|
#endif
|
2010-10-09 21:20:15 +02:00
|
|
|
#if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
|
2010-09-16 14:41:39 +02:00
|
|
|
#include <qdeclarativeviewobserver.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-07-15 11:58:37 +02:00
|
|
|
#if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK)
|
|
|
|
|
#include <eikenv.h>
|
|
|
|
|
#include <eikappui.h>
|
|
|
|
|
#include <aknenv.h>
|
|
|
|
|
#include <aknappui.h>
|
|
|
|
|
#endif // Q_OS_SYMBIAN && ORIENTATIONLOCK
|
|
|
|
|
|
2010-11-03 10:44:40 +01:00
|
|
|
#if defined(QMLJSDEBUGGER)
|
|
|
|
|
|
|
|
|
|
// Enable debugging before any QDeclarativeEngine is created
|
|
|
|
|
struct QmlJsDebuggingEnabler
|
|
|
|
|
{
|
|
|
|
|
QmlJsDebuggingEnabler()
|
|
|
|
|
{
|
|
|
|
|
QDeclarativeDebugHelper::enableDebugging();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Execute code in constructor before first QDeclarativeEngine is instantiated
|
|
|
|
|
static QmlJsDebuggingEnabler enableDebuggingHelper;
|
|
|
|
|
|
|
|
|
|
#endif // QMLJSDEBUGGER
|
|
|
|
|
|
2010-08-25 19:07:50 +02:00
|
|
|
class QmlApplicationViewerPrivate
|
2010-07-15 11:58:37 +02:00
|
|
|
{
|
|
|
|
|
QString mainQmlFile;
|
2010-08-25 19:07:50 +02:00
|
|
|
friend class QmlApplicationViewer;
|
2010-08-16 20:27:30 +02:00
|
|
|
static QString adjustPath(const QString &path);
|
2010-07-15 11:58:37 +02:00
|
|
|
};
|
|
|
|
|
|
2010-08-25 19:07:50 +02:00
|
|
|
QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
|
2010-08-16 20:27:30 +02:00
|
|
|
{
|
2010-09-08 16:50:47 +02:00
|
|
|
#ifdef Q_OS_UNIX
|
2010-08-16 20:27:30 +02:00
|
|
|
#ifdef Q_OS_MAC
|
2010-08-16 22:02:20 +02:00
|
|
|
if (!QDir::isAbsolutePath(path))
|
2010-08-16 20:27:30 +02:00
|
|
|
return QCoreApplication::applicationDirPath()
|
|
|
|
|
+ QLatin1String("/../Resources/") + path;
|
2010-09-08 16:50:47 +02:00
|
|
|
#else
|
|
|
|
|
const QString pathInShareDir = QCoreApplication::applicationDirPath()
|
|
|
|
|
+ QLatin1String("/../share/")
|
|
|
|
|
+ QFileInfo(QCoreApplication::applicationFilePath()).fileName()
|
|
|
|
|
+ QLatin1Char('/') + path;
|
|
|
|
|
if (QFileInfo(pathInShareDir).exists())
|
|
|
|
|
return pathInShareDir;
|
|
|
|
|
#endif
|
2010-08-16 20:27:30 +02:00
|
|
|
#endif
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 19:07:50 +02:00
|
|
|
QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
|
2010-09-16 14:41:39 +02:00
|
|
|
QDeclarativeView(parent),
|
|
|
|
|
m_d(new QmlApplicationViewerPrivate)
|
2010-07-15 11:58:37 +02:00
|
|
|
{
|
|
|
|
|
connect(engine(), SIGNAL(quit()), SLOT(close()));
|
|
|
|
|
setResizeMode(QDeclarativeView::SizeRootObjectToView);
|
2010-10-09 21:20:15 +02:00
|
|
|
#if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
|
2010-09-22 13:03:37 +02:00
|
|
|
new QmlJSDebugger::JSDebuggerAgent(engine());
|
|
|
|
|
#endif
|
2010-10-09 21:20:15 +02:00
|
|
|
#if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
|
2010-09-22 09:59:18 +02:00
|
|
|
new QmlJSDebugger::QDeclarativeViewObserver(this, parent);
|
2010-09-16 14:41:39 +02:00
|
|
|
#endif
|
2010-07-15 11:58:37 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-25 19:07:50 +02:00
|
|
|
QmlApplicationViewer::~QmlApplicationViewer()
|
2010-07-15 11:58:37 +02:00
|
|
|
{
|
|
|
|
|
delete m_d;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 19:07:50 +02:00
|
|
|
void QmlApplicationViewer::setMainQmlFile(const QString &file)
|
2010-08-16 20:27:30 +02:00
|
|
|
{
|
2010-08-25 19:07:50 +02:00
|
|
|
m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
|
2010-08-16 20:27:30 +02:00
|
|
|
setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-25 19:07:50 +02:00
|
|
|
void QmlApplicationViewer::addImportPath(const QString &path)
|
2010-07-15 11:58:37 +02:00
|
|
|
{
|
2010-08-25 19:07:50 +02:00
|
|
|
engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
|
2010-07-15 11:58:37 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-01 17:03:46 +01:00
|
|
|
void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
|
2010-07-15 11:58:37 +02:00
|
|
|
{
|
2010-09-10 13:54:31 +02:00
|
|
|
#ifdef Q_OS_SYMBIAN
|
2010-11-01 17:03:46 +01:00
|
|
|
if (orientation != ScreenOrientationAuto) {
|
2010-07-15 11:58:37 +02:00
|
|
|
#if defined(ORIENTATIONLOCK)
|
|
|
|
|
const CAknAppUiBase::TAppUiOrientation uiOrientation =
|
2010-11-01 17:03:46 +01:00
|
|
|
(orientation == ScreenOrientationLockPortrait) ? CAknAppUi::EAppUiOrientationPortrait
|
2010-07-15 11:58:37 +02:00
|
|
|
: CAknAppUi::EAppUiOrientationLandscape;
|
|
|
|
|
CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
|
|
|
|
|
TRAPD(error,
|
|
|
|
|
if (appUi)
|
|
|
|
|
appUi->SetOrientationL(uiOrientation);
|
|
|
|
|
);
|
2010-11-01 19:25:19 +01:00
|
|
|
Q_UNUSED(error)
|
2010-07-15 11:58:37 +02:00
|
|
|
#else // ORIENTATIONLOCK
|
|
|
|
|
qWarning("'ORIENTATIONLOCK' needs to be defined on Symbian when locking the orientation.");
|
|
|
|
|
#endif // ORIENTATIONLOCK
|
|
|
|
|
}
|
2010-09-10 13:54:31 +02:00
|
|
|
#elif defined(Q_WS_MAEMO_5)
|
|
|
|
|
Qt::WidgetAttribute attribute;
|
|
|
|
|
switch (orientation) {
|
2010-11-01 17:03:46 +01:00
|
|
|
case ScreenOrientationLockPortrait:
|
2010-09-10 13:54:31 +02:00
|
|
|
attribute = Qt::WA_Maemo5PortraitOrientation;
|
|
|
|
|
break;
|
2010-11-01 17:03:46 +01:00
|
|
|
case ScreenOrientationLockLandscape:
|
2010-09-10 13:54:31 +02:00
|
|
|
attribute = Qt::WA_Maemo5LandscapeOrientation;
|
|
|
|
|
break;
|
2010-11-01 17:03:46 +01:00
|
|
|
case ScreenOrientationAuto:
|
2010-09-10 13:54:31 +02:00
|
|
|
default:
|
|
|
|
|
attribute = Qt::WA_Maemo5AutoOrientation;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
setAttribute(attribute, true);
|
|
|
|
|
#else // Q_OS_SYMBIAN
|
|
|
|
|
Q_UNUSED(orientation);
|
|
|
|
|
#endif // Q_OS_SYMBIAN
|
2010-07-15 11:58:37 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-01 19:19:32 +01:00
|
|
|
void QmlApplicationViewer::showExpanded()
|
2010-09-20 13:18:35 +02:00
|
|
|
{
|
|
|
|
|
#ifdef Q_OS_SYMBIAN
|
|
|
|
|
showFullScreen();
|
|
|
|
|
#elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
|
|
|
|
|
showMaximized();
|
|
|
|
|
#else
|
2010-11-01 19:19:32 +01:00
|
|
|
show();
|
2010-09-20 13:18:35 +02:00
|
|
|
#endif
|
|
|
|
|
}
|