diff options
author | Daniel Molkentin <daniel.molkentin@nokia.com> | 2011-11-21 12:24:20 (GMT) |
---|---|---|
committer | Daniel Molkentin <daniel.molkentin@nokia.com> | 2011-11-21 12:50:57 (GMT) |
commit | 0b594c27b946eb8c2356f1400e3dfb72be824588 (patch) | |
tree | 627374251c5a14659fb8543ee98f46d46c761ebb /demos | |
parent | 7eb8de4dde6df60b26e5297407573f01634415c3 (diff) | |
download | Qt-0b594c27b946eb8c2356f1400e3dfb72be824588.zip Qt-0b594c27b946eb8c2356f1400e3dfb72be824588.tar.gz Qt-0b594c27b946eb8c2356f1400e3dfb72be824588.tar.bz2 |
Fix use of qmlapplicationviewer.
- Two separate copies for demos and example
- Fix deployment (don't install to opt in desktop case)
Reviewed-by: Casper van Donderen
Diffstat (limited to 'demos')
-rw-r--r-- | demos/declarative/calculator/calculator.pro | 3 | ||||
-rw-r--r-- | demos/declarative/flickr/flickr.pro | 3 | ||||
-rw-r--r-- | demos/declarative/minehunt/minehunt.pro | 3 | ||||
-rw-r--r-- | demos/declarative/photoviewer/photoviewer.pro | 3 | ||||
-rw-r--r-- | demos/declarative/rssnews/rssnews.pro | 3 | ||||
-rw-r--r-- | demos/declarative/samegame/samegame.pro | 3 | ||||
-rw-r--r-- | demos/declarative/snake/snake.pro | 3 | ||||
-rw-r--r-- | demos/declarative/twitter/twitter.pro | 3 | ||||
-rw-r--r-- | demos/declarative/webbrowser/webbrowser.pro | 3 | ||||
-rw-r--r-- | demos/helper/qmlapplicationviewer/qmlapplicationviewer.cpp | 197 | ||||
-rw-r--r-- | demos/helper/qmlapplicationviewer/qmlapplicationviewer.h | 46 | ||||
-rw-r--r-- | demos/helper/qmlapplicationviewer/qmlapplicationviewer.pri | 150 |
12 files changed, 411 insertions, 9 deletions
diff --git a/demos/declarative/calculator/calculator.pro b/demos/declarative/calculator/calculator.pro index 697a0d8..9c91bcc 100644 --- a/demos/declarative/calculator/calculator.pro +++ b/demos/declarative/calculator/calculator.pro @@ -33,5 +33,6 @@ symbian:TARGET.CAPABILITY += NetworkServices SOURCES += main.cpp # Please do not modify the following two lines. Required for deployment. -include(../../../examples/tools/qmlapplicationviewer/qmlapplicationviewer.pri) +desktopInstallPrefix=$$[QT_INSTALL_DEMOS]/declarative/calculator +include(../../helper/qmlapplicationviewer/qmlapplicationviewer.pri) qtcAddDeployment() diff --git a/demos/declarative/flickr/flickr.pro b/demos/declarative/flickr/flickr.pro index 30206f8..1b45eee 100644 --- a/demos/declarative/flickr/flickr.pro +++ b/demos/declarative/flickr/flickr.pro @@ -33,5 +33,6 @@ symbian:TARGET.CAPABILITY += NetworkServices SOURCES += main.cpp # Please do not modify the following two lines. Required for deployment. -include(../../../examples/tools/qmlapplicationviewer/qmlapplicationviewer.pri) +desktopInstallPrefix=$$[QT_INSTALL_DEMOS]/declarative/flickr +include(../../helper/qmlapplicationviewer/qmlapplicationviewer.pri) qtcAddDeployment() diff --git a/demos/declarative/minehunt/minehunt.pro b/demos/declarative/minehunt/minehunt.pro index 4eed9c1..17786f6 100644 --- a/demos/declarative/minehunt/minehunt.pro +++ b/demos/declarative/minehunt/minehunt.pro @@ -44,5 +44,6 @@ SOURCES += main.cpp minehunt.cpp RESOURCES = minehunt.qrc # Please do not modify the following two lines. Required for deployment. -include(../../../examples/tools/qmlapplicationviewer/qmlapplicationviewer.pri) +desktopInstallPrefix=$$[QT_INSTALL_DEMOS]/declarative/minehunt +include(../../helper/qmlapplicationviewer/qmlapplicationviewer.pri) qtcAddDeployment() diff --git a/demos/declarative/photoviewer/photoviewer.pro b/demos/declarative/photoviewer/photoviewer.pro index cdfab1e..c44ba24 100644 --- a/demos/declarative/photoviewer/photoviewer.pro +++ b/demos/declarative/photoviewer/photoviewer.pro @@ -33,5 +33,6 @@ symbian:TARGET.CAPABILITY += NetworkServices SOURCES += main.cpp # Please do not modify the following two lines. Required for deployment. -include(../../../examples/tools/qmlapplicationviewer/qmlapplicationviewer.pri) +desktopInstallPrefix=$$[QT_INSTALL_DEMOS]/declarative/photoviewer +include(../../helper/qmlapplicationviewer/qmlapplicationviewer.pri) qtcAddDeployment() diff --git a/demos/declarative/rssnews/rssnews.pro b/demos/declarative/rssnews/rssnews.pro index 30dd524..e152311 100644 --- a/demos/declarative/rssnews/rssnews.pro +++ b/demos/declarative/rssnews/rssnews.pro @@ -33,5 +33,6 @@ symbian:TARGET.CAPABILITY += NetworkServices SOURCES += main.cpp # Please do not modify the following two lines. Required for deployment. -include(../../../examples/tools/qmlapplicationviewer/qmlapplicationviewer.pri) +desktopInstallPrefix=$$[QT_INSTALL_DEMOS]/declarative/rssnews +include(../../helper/qmlapplicationviewer/qmlapplicationviewer.pri) qtcAddDeployment() diff --git a/demos/declarative/samegame/samegame.pro b/demos/declarative/samegame/samegame.pro index 1a2455b..13a9f76 100644 --- a/demos/declarative/samegame/samegame.pro +++ b/demos/declarative/samegame/samegame.pro @@ -33,5 +33,6 @@ symbian:TARGET.CAPABILITY += NetworkServices SOURCES += main.cpp # Please do not modify the following two lines. Required for deployment. -include(../../../examples/tools/qmlapplicationviewer/qmlapplicationviewer.pri) +desktopInstallPrefix=$$[QT_INSTALL_DEMOS]/declarative/samegame +include(../../helper/qmlapplicationviewer/qmlapplicationviewer.pri) qtcAddDeployment() diff --git a/demos/declarative/snake/snake.pro b/demos/declarative/snake/snake.pro index 81b2dfc..4f562ab 100644 --- a/demos/declarative/snake/snake.pro +++ b/demos/declarative/snake/snake.pro @@ -33,5 +33,6 @@ symbian:TARGET.CAPABILITY += NetworkServices SOURCES += main.cpp # Please do not modify the following two lines. Required for deployment. -include(../../../examples/tools/qmlapplicationviewer/qmlapplicationviewer.pri) +desktopInstallPrefix=$$[QT_INSTALL_DEMOS]/declarative/snake +include(../../helper/qmlapplicationviewer/qmlapplicationviewer.pri) qtcAddDeployment() diff --git a/demos/declarative/twitter/twitter.pro b/demos/declarative/twitter/twitter.pro index a45f338..c8485bf 100644 --- a/demos/declarative/twitter/twitter.pro +++ b/demos/declarative/twitter/twitter.pro @@ -33,5 +33,6 @@ symbian:TARGET.CAPABILITY += NetworkServices SOURCES += main.cpp # Please do not modify the following two lines. Required for deployment. -include(../../../examples/tools/qmlapplicationviewer/qmlapplicationviewer.pri) +desktopInstallPrefix=$$[QT_INSTALL_DEMOS]/declarative/twitter +include(../../helper/qmlapplicationviewer/qmlapplicationviewer.pri) qtcAddDeployment() diff --git a/demos/declarative/webbrowser/webbrowser.pro b/demos/declarative/webbrowser/webbrowser.pro index 2a7bdbd..d368832 100644 --- a/demos/declarative/webbrowser/webbrowser.pro +++ b/demos/declarative/webbrowser/webbrowser.pro @@ -33,5 +33,6 @@ symbian:TARGET.CAPABILITY += NetworkServices SOURCES += main.cpp # Please do not modify the following two lines. Required for deployment. -include(../../../examples/tools/qmlapplicationviewer/qmlapplicationviewer.pri) +desktopInstallPrefix=$$[QT_INSTALL_DEMOS]/declarative/webbrowser +include(../../helper/qmlapplicationviewer/qmlapplicationviewer.pri) qtcAddDeployment() diff --git a/demos/helper/qmlapplicationviewer/qmlapplicationviewer.cpp b/demos/helper/qmlapplicationviewer/qmlapplicationviewer.cpp new file mode 100644 index 0000000..1bba248 --- /dev/null +++ b/demos/helper/qmlapplicationviewer/qmlapplicationviewer.cpp @@ -0,0 +1,197 @@ +/* + 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. +*/ + +#include "qmlapplicationviewer.h" + +#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> + +#if !defined(NO_JSDEBUGGER) +#include <jsdebuggeragent.h> +#endif +#if !defined(NO_QMLOBSERVER) +#include <qdeclarativeviewobserver.h> +#endif + +// 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 + +class QmlApplicationViewerPrivate +{ + QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {} + + QString mainQmlFile; + QDeclarativeView *view; + friend class QmlApplicationViewer; + QString adjustPath(const QString &path); +}; + +QString QmlApplicationViewerPrivate::adjustPath(const QString &path) +{ +#ifdef Q_OS_UNIX +#ifdef Q_OS_MAC + if (!QDir::isAbsolutePath(path)) + return QString::fromLatin1("%1/../Resources/%2") + .arg(QCoreApplication::applicationDirPath(), path); +#else + const QString pathInInstallDir = + QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path); + if (QFileInfo(pathInInstallDir).exists()) + return pathInInstallDir; +#endif +#endif + return path; +} + +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(d->view->engine()); +#endif +#if !defined(NO_QMLOBSERVER) + 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 d; +} + +QmlApplicationViewer *QmlApplicationViewer::create() +{ +#ifdef HARMATTAN_BOOSTER + return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0); +#else + return new QmlApplicationViewer(); +#endif +} + +void QmlApplicationViewer::setMainQmlFile(const QString &file) +{ + d->mainQmlFile = d->adjustPath(file); + d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile)); +} + +void QmlApplicationViewer::addImportPath(const QString &path) +{ + d->view->engine()->addImportPath(d->adjustPath(path)); +} + +void QmlApplicationViewer::setOrientation(ScreenOrientation orientation) +{ +#if defined(Q_OS_SYMBIAN) + // If the version of Qt on the device is < 4.7.2, that attribute won't work + if (orientation != ScreenOrientationAuto) { + const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.')); + if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) { + qWarning("Screen orientation locking only supported with Qt 4.7.2 and above"); + return; + } + } +#endif // Q_OS_SYMBIAN + + Qt::WidgetAttribute attribute; + switch (orientation) { +#if QT_VERSION < 0x040702 + // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes + case ScreenOrientationLockPortrait: + attribute = static_cast<Qt::WidgetAttribute>(128); + break; + case ScreenOrientationLockLandscape: + attribute = static_cast<Qt::WidgetAttribute>(129); + break; + default: + case ScreenOrientationAuto: + attribute = static_cast<Qt::WidgetAttribute>(130); + break; +#else // QT_VERSION < 0x040702 + case ScreenOrientationLockPortrait: + attribute = Qt::WA_LockPortraitOrientation; + break; + case ScreenOrientationLockLandscape: + attribute = Qt::WA_LockLandscapeOrientation; + break; + default: + case ScreenOrientationAuto: + attribute = Qt::WA_AutoOrientation; + break; +#endif // QT_VERSION < 0x040702 + }; + setAttribute(attribute, true); +} + +void QmlApplicationViewer::showExpanded() +{ +#if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR) + d->view->showFullScreen(); +#elif defined(Q_WS_MAEMO_5) + d->view->showMaximized(); +#else + 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 +} diff --git a/demos/helper/qmlapplicationviewer/qmlapplicationviewer.h b/demos/helper/qmlapplicationviewer/qmlapplicationviewer.h new file mode 100644 index 0000000..d6cb43e --- /dev/null +++ b/demos/helper/qmlapplicationviewer/qmlapplicationviewer.h @@ -0,0 +1,46 @@ +/* + 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. +*/ + +#ifndef QMLAPPLICATIONVIEWER_H +#define QMLAPPLICATIONVIEWER_H + +#include <QtDeclarative/QDeclarativeView> + +class QmlApplicationViewer : public QDeclarativeView +{ + Q_OBJECT + +public: + enum ScreenOrientation { + ScreenOrientationLockPortrait, + ScreenOrientationLockLandscape, + ScreenOrientationAuto + }; + + explicit QmlApplicationViewer(QWidget *parent = 0); + virtual ~QmlApplicationViewer(); + + static QmlApplicationViewer *create(); + + void setMainQmlFile(const QString &file); + void addImportPath(const QString &path); + + // Note that this will only have an effect on Symbian and Fremantle. + void setOrientation(ScreenOrientation orientation); + + void showExpanded(); + +private: + explicit QmlApplicationViewer(QDeclarativeView *view, QWidget *parent); + class QmlApplicationViewerPrivate *d; +}; + +QApplication *createApplication(int &argc, char **argv); + +#endif // QMLAPPLICATIONVIEWER_H diff --git a/demos/helper/qmlapplicationviewer/qmlapplicationviewer.pri b/demos/helper/qmlapplicationviewer/qmlapplicationviewer.pri new file mode 100644 index 0000000..8a51c9b --- /dev/null +++ b/demos/helper/qmlapplicationviewer/qmlapplicationviewer.pri @@ -0,0 +1,150 @@ +# This file was generated by the Qt Quick Application wizard of Qt Creator. +# The code below adds the QmlApplicationViewer to the project and handles the +# activation of QML debugging. +# It is recommended not to modify this file, since newer versions of Qt Creator +# may offer an updated version of it. + +QT += declarative + +SOURCES += $$PWD/qmlapplicationviewer.cpp +HEADERS += $$PWD/qmlapplicationviewer.h +INCLUDEPATH += $$PWD + +# Include JS debugger library if QMLJSDEBUGGER_PATH is set +!isEmpty(QMLJSDEBUGGER_PATH) { + include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri) +} else { + DEFINES -= QMLJSDEBUGGER +} + +contains(CONFIG,qdeclarative-boostable):contains(MEEGO_EDITION,harmattan) { + DEFINES += HARMATTAN_BOOSTER +} +# This file was generated by an application wizard of Qt Creator. +# The code below handles deployment to Symbian and Maemo, aswell as copying +# of the application data to shadow build directories on desktop. +# It is recommended not to modify this file, since newer versions of Qt Creator +# may offer an updated version of it. + +defineTest(qtcAddDeployment) { +for(deploymentfolder, DEPLOYMENTFOLDERS) { + item = item$${deploymentfolder} + itemsources = $${item}.sources + $$itemsources = $$eval($${deploymentfolder}.source) + itempath = $${item}.path + $$itempath= $$eval($${deploymentfolder}.target) + export($$itemsources) + export($$itempath) + DEPLOYMENT += $$item +} + +MAINPROFILEPWD = $$_PRO_FILE_PWD_ + +symbian { + isEmpty(ICON):exists($${TARGET}.svg):ICON = $${TARGET}.svg + isEmpty(TARGET.EPOCHEAPSIZE):TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 +} else:win32 { + copyCommand = + for(deploymentfolder, DEPLOYMENTFOLDERS) { + source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) + source = $$replace(source, /, \\) + sourcePathSegments = $$split(source, \\) + target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) + target = $$replace(target, /, \\) + target ~= s,\\\\\\.?\\\\,\\, + !isEqual(source,$$target) { + !isEmpty(copyCommand):copyCommand += && + isEqual(QMAKE_DIR_SEP, \\) { + copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" + } else { + source = $$replace(source, \\\\, /) + target = $$OUT_PWD/$$eval($${deploymentfolder}.target) + target = $$replace(target, \\\\, /) + copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" + } + } + } + !isEmpty(copyCommand) { + copyCommand = @echo Copying application data... && $$copyCommand + copydeploymentfolders.commands = $$copyCommand + first.depends = $(first) copydeploymentfolders + export(first.depends) + export(copydeploymentfolders.commands) + QMAKE_EXTRA_TARGETS += first copydeploymentfolders + } +} else:unix { + maemo5 { + installPrefix = /opt/$${TARGET} + desktopfile.files = $${TARGET}.desktop + desktopfile.path = /usr/share/applications/hildon + icon.files = $${TARGET}64.png + icon.path = /usr/share/icons/hicolor/64x64/apps + } else:!isEmpty(MEEGO_VERSION_MAJOR) { + installPrefix = /opt/$${TARGET} + desktopfile.files = $${TARGET}_harmattan.desktop + desktopfile.path = /usr/share/applications + icon.files = $${TARGET}80.png + icon.path = /usr/share/icons/hicolor/80x80/apps + } else { # Assumed to be a Desktop Unix + isEmpty(desktopInstallPrefix):installPrefix = $$[QT_INSTALL_DEMOS]/$${TARGET} + else:installPrefix = $$desktopInstallPrefix + copyCommand = + for(deploymentfolder, DEPLOYMENTFOLDERS) { + source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) + source = $$replace(source, \\\\, /) + macx { + target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) + } else { + target = $$OUT_PWD/$$eval($${deploymentfolder}.target) + } + target = $$replace(target, \\\\, /) + sourcePathSegments = $$split(source, /) + targetFullPath = $$target/$$last(sourcePathSegments) + targetFullPath ~= s,/\\.?/,/, + !isEqual(source,$$targetFullPath) { + !isEmpty(copyCommand):copyCommand += && + copyCommand += $(MKDIR) \"$$target\" + copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" + } + } + !isEmpty(copyCommand) { + copyCommand = @echo Copying application data... && $$copyCommand + copydeploymentfolders.commands = $$copyCommand + first.depends = $(first) copydeploymentfolders + export(first.depends) + export(copydeploymentfolders.commands) + QMAKE_EXTRA_TARGETS += first copydeploymentfolders + } + } + for(deploymentfolder, DEPLOYMENTFOLDERS) { + item = item$${deploymentfolder} + itemfiles = $${item}.files + $$itemfiles = $$eval($${deploymentfolder}.source) + itempath = $${item}.path + $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) + export($$itemfiles) + export($$itempath) + INSTALLS += $$item + } + + !isEmpty(desktopfile.path) { + export(icon.files) + export(icon.path) + export(desktopfile.files) + export(desktopfile.path) + INSTALLS += icon desktopfile + } + + target.path = $${installPrefix}/bin + export(target.path) + INSTALLS += target +} + +export (ICON) +export (INSTALLS) +export (DEPLOYMENT) +export (TARGET.EPOCHEAPSIZE) +export (TARGET.CAPABILITY) +export (LIBS) +export (QMAKE_EXTRA_TARGETS) +} |