forked from qt-creator/qt-creator
QtQuickApp: Tweak template to enable Meego booster
Add support for the meego booster. This requires - Telling qmake to link to right libraries - Exporting main method - using QApplication, QDeclarativeView objects from cache - avoiding QCoreApplication::applicationDirPath() To keep compatibility, QmlApplicationViewer is still derived from QDeclarativeView. However, if the app booster is used it merely acts as a proxy to the view from the cache. Change-Id: I83e285d9ca3c2cfd86d1711e1fb93c72589ba14d Reviewed-on: http://codereview.qt.nokia.com/3730 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Alessandro Portale <alessandro.portale@nokia.com> Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
This commit is contained in:
@@ -28,7 +28,11 @@ symbian:TARGET.CAPABILITY += NetworkServices
|
||||
# CONFIG += mobility
|
||||
# MOBILITY +=
|
||||
|
||||
# Add dependency to symbian components
|
||||
# Speed up launching on MeeGo/Harmattan when using applauncherd daemon
|
||||
# HARMATTAN_BOOSTABLE #
|
||||
# CONFIG += qdeclarative-boostable
|
||||
|
||||
# Add dependency to Symbian components
|
||||
# QTQUICKCOMPONENTS #
|
||||
# CONFIG += qtquickcomponents
|
||||
|
||||
|
@@ -1,15 +1,15 @@
|
||||
#include <QtGui/QApplication>
|
||||
#include "qmlapplicationviewer.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
Q_DECL_EXPORT int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
QScopedPointer<QApplication> app(createApplication(argc, argv));
|
||||
QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
|
||||
|
||||
QmlApplicationViewer viewer;
|
||||
viewer.addImportPath(QLatin1String("modules")); // ADDIMPORTPATH
|
||||
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto); // ORIENTATION
|
||||
viewer.setMainQmlFile(QLatin1String("qml/app/main.qml")); // MAINQML
|
||||
viewer.showExpanded();
|
||||
viewer->addImportPath(QLatin1String("modules")); // ADDIMPORTPATH
|
||||
viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); // ORIENTATION
|
||||
viewer->setMainQmlFile(QLatin1String("qml/app/main.qml")); // MAINQML
|
||||
viewer->showExpanded();
|
||||
|
||||
return app.exec();
|
||||
return app->exec();
|
||||
}
|
||||
|
@@ -9,15 +9,19 @@
|
||||
|
||||
#include "qmlapplicationviewer.h"
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtDeclarative/QDeclarativeComponent>
|
||||
#include <QtDeclarative/QDeclarativeEngine>
|
||||
#include <QtDeclarative/QDeclarativeContext>
|
||||
#include <QtGui/QApplication>
|
||||
|
||||
#include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
|
||||
|
||||
#ifdef HARMATTAN_BOOSTER
|
||||
#include <MDeclarativeCache>
|
||||
#endif
|
||||
|
||||
#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
|
||||
|
||||
#include <qt_private/qdeclarativedebughelper_p.h>
|
||||
@@ -45,9 +49,12 @@ static QmlJsDebuggingEnabler enableDebuggingHelper;
|
||||
|
||||
class QmlApplicationViewerPrivate
|
||||
{
|
||||
QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {}
|
||||
|
||||
QString mainQmlFile;
|
||||
QDeclarativeView *view;
|
||||
friend class QmlApplicationViewer;
|
||||
static QString adjustPath(const QString &path);
|
||||
QString adjustPath(const QString &path);
|
||||
};
|
||||
|
||||
QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
|
||||
@@ -58,49 +65,78 @@ QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
|
||||
return QCoreApplication::applicationDirPath()
|
||||
+ QLatin1String("/../Resources/") + path;
|
||||
#else
|
||||
const QString pathInInstallDir = QCoreApplication::applicationDirPath()
|
||||
+ QLatin1String("/../") + path;
|
||||
if (pathInInstallDir.contains(QLatin1String("opt"))
|
||||
&& pathInInstallDir.contains(QLatin1String("bin"))
|
||||
&& QFileInfo(pathInInstallDir).exists()) {
|
||||
QString pathInInstallDir;
|
||||
#ifdef HARMATTAN_BOOSTER
|
||||
QString applicationDirPath = MDeclarativeCache::applicationDirPath();
|
||||
#else
|
||||
QString applicationDirPath = QCoreApplication::applicationDirPath();
|
||||
#endif
|
||||
pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path);
|
||||
|
||||
if (QFileInfo(pathInInstallDir).exists())
|
||||
return pathInInstallDir;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return path;
|
||||
}
|
||||
|
||||
QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
|
||||
QDeclarativeView(parent),
|
||||
m_d(new QmlApplicationViewerPrivate)
|
||||
QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
|
||||
: QDeclarativeView(parent)
|
||||
, d(new QmlApplicationViewerPrivate(this))
|
||||
{
|
||||
connect(engine(), SIGNAL(quit()), SLOT(close()));
|
||||
setResizeMode(QDeclarativeView::SizeRootObjectToView);
|
||||
// Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
|
||||
#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
|
||||
#if !defined(NO_JSDEBUGGER)
|
||||
new QmlJSDebugger::JSDebuggerAgent(engine());
|
||||
new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
|
||||
#endif
|
||||
#if !defined(NO_QMLOBSERVER)
|
||||
new QmlJSDebugger::QDeclarativeViewObserver(this, this);
|
||||
new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, QWidget *parent)
|
||||
: QDeclarativeView(parent)
|
||||
, d(new QmlApplicationViewerPrivate(view))
|
||||
{
|
||||
connect(view->engine(), SIGNAL(quit()), view, SLOT(close()));
|
||||
view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
|
||||
// Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
|
||||
#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
|
||||
#if !defined(NO_JSDEBUGGER)
|
||||
new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
|
||||
#endif
|
||||
#if !defined(NO_QMLOBSERVER)
|
||||
new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
QmlApplicationViewer::~QmlApplicationViewer()
|
||||
{
|
||||
delete m_d;
|
||||
delete d;
|
||||
}
|
||||
|
||||
QmlApplicationViewer *QmlApplicationViewer::create()
|
||||
{
|
||||
#ifdef HARMATTAN_BOOSTER
|
||||
return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0);
|
||||
#else
|
||||
return new QmlApplicationViewer();
|
||||
#endif
|
||||
}
|
||||
|
||||
void QmlApplicationViewer::setMainQmlFile(const QString &file)
|
||||
{
|
||||
m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
|
||||
setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
|
||||
d->mainQmlFile = d->adjustPath(file);
|
||||
d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile));
|
||||
}
|
||||
|
||||
void QmlApplicationViewer::addImportPath(const QString &path)
|
||||
{
|
||||
engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
|
||||
d->view->engine()->addImportPath(d->adjustPath(path));
|
||||
}
|
||||
|
||||
void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
|
||||
@@ -149,10 +185,19 @@ void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
|
||||
void QmlApplicationViewer::showExpanded()
|
||||
{
|
||||
#if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
|
||||
showFullScreen();
|
||||
d->view->showFullScreen();
|
||||
#elif defined(Q_WS_MAEMO_5)
|
||||
showMaximized();
|
||||
d->view->showMaximized();
|
||||
#else
|
||||
show();
|
||||
d->view->show();
|
||||
#endif
|
||||
}
|
||||
|
||||
QApplication *createApplication(int &argc, char **argv)
|
||||
{
|
||||
#ifdef HARMATTAN_BOOSTER
|
||||
return MDeclarativeCache::qApplication(argc, argv);
|
||||
#else
|
||||
return new QApplication(argc, argv);
|
||||
#endif
|
||||
}
|
||||
|
@@ -26,6 +26,8 @@ public:
|
||||
explicit QmlApplicationViewer(QWidget *parent = 0);
|
||||
virtual ~QmlApplicationViewer();
|
||||
|
||||
static QmlApplicationViewer *create();
|
||||
|
||||
void setMainQmlFile(const QString &file);
|
||||
void addImportPath(const QString &path);
|
||||
|
||||
@@ -35,7 +37,10 @@ public:
|
||||
void showExpanded();
|
||||
|
||||
private:
|
||||
class QmlApplicationViewerPrivate *m_d;
|
||||
explicit QmlApplicationViewer(QDeclarativeView *view, QWidget *parent);
|
||||
class QmlApplicationViewerPrivate *d;
|
||||
};
|
||||
|
||||
QApplication *createApplication(int &argc, char **argv);
|
||||
|
||||
#endif // QMLAPPLICATIONVIEWER_H
|
||||
|
@@ -16,3 +16,7 @@ INCLUDEPATH += $$PWD
|
||||
} else {
|
||||
DEFINES -= QMLJSDEBUGGER
|
||||
}
|
||||
|
||||
contains(CONFIG,qdeclarative-boostable):contains(MEEGO_EDITION,harmattan) {
|
||||
DEFINES += HARMATTAN_BOOSTER
|
||||
}
|
||||
|
@@ -460,7 +460,7 @@ QString QtQuickApp::componentSetDir(ComponentSet componentSet) const
|
||||
}
|
||||
}
|
||||
|
||||
const int QtQuickApp::StubVersion = 15;
|
||||
const int QtQuickApp::StubVersion = 16;
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Qt4ProjectManager
|
||||
|
Reference in New Issue
Block a user