diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2011-08-17 12:27:24 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@nokia.com> | 2011-09-01 13:15:12 +0200 |
commit | d687d11240877f848f3d1c28e2ec70ed4ff555f4 (patch) | |
tree | 94fc34a5b11c46192e82ef2faeb23473299f30cd | |
parent | 4848be6fe806f2f0602db4c0414316c387bb2aff (diff) | |
download | qt-creator-d687d11240877f848f3d1c28e2ec70ed4ff555f4.tar.gz |
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>
6 files changed, 89 insertions, 31 deletions
diff --git a/share/qtcreator/templates/qtquickapp/app.pro b/share/qtcreator/templates/qtquickapp/app.pro index e8d197665a..fcbcc0b8af 100644 --- a/share/qtcreator/templates/qtquickapp/app.pro +++ b/share/qtcreator/templates/qtquickapp/app.pro @@ -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 diff --git a/share/qtcreator/templates/qtquickapp/main.cpp b/share/qtcreator/templates/qtquickapp/main.cpp index dfb208a90c..82347f65b2 100644 --- a/share/qtcreator/templates/qtquickapp/main.cpp +++ b/share/qtcreator/templates/qtquickapp/main.cpp @@ -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(); } diff --git a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.cpp b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.cpp index d8500a28c4..c7ccf089be 100644 --- a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.cpp +++ b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.cpp @@ -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 + d->view->show(); +#endif +} + +QApplication *createApplication(int &argc, char **argv) +{ +#ifdef HARMATTAN_BOOSTER + return MDeclarativeCache::qApplication(argc, argv); #else - show(); + return new QApplication(argc, argv); #endif } diff --git a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.h b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.h index f4d7f40cd9..d6cb43e10e 100644 --- a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.h +++ b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.h @@ -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 diff --git a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.pri b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.pri index 6704a74c1b..a32c88d1ae 100644 --- a/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.pri +++ b/share/qtcreator/templates/qtquickapp/qmlapplicationviewer/qmlapplicationviewer.pri @@ -16,3 +16,7 @@ INCLUDEPATH += $$PWD } else { DEFINES -= QMLJSDEBUGGER } + +contains(CONFIG,qdeclarative-boostable):contains(MEEGO_EDITION,harmattan) { + DEFINES += HARMATTAN_BOOSTER +} diff --git a/src/plugins/qt4projectmanager/wizards/qtquickapp.cpp b/src/plugins/qt4projectmanager/wizards/qtquickapp.cpp index 859d2da090..72446e5bd6 100644 --- a/src/plugins/qt4projectmanager/wizards/qtquickapp.cpp +++ b/src/plugins/qt4projectmanager/wizards/qtquickapp.cpp @@ -460,7 +460,7 @@ QString QtQuickApp::componentSetDir(ComponentSet componentSet) const } } -const int QtQuickApp::StubVersion = 15; +const int QtQuickApp::StubVersion = 16; } // namespace Internal } // namespace Qt4ProjectManager |