diff options
author | Tero Ahola <tero.ahola@digia.com> | 2012-05-28 10:51:27 +0300 |
---|---|---|
committer | Tero Ahola <tero.ahola@digia.com> | 2012-05-28 16:09:21 +0300 |
commit | 5664856ed1d470dc96be1dd7ab0ec2680e47bd02 (patch) | |
tree | b1ed794fe70914a14894d4e5fdc798d2cf61f9ad /demos/qmlcustomizations | |
parent | 9ffa0de920ecdd29e6a3bdde67c97143d6e7169b (diff) |
App for demonstrating QML customization apis
Diffstat (limited to 'demos/qmlcustomizations')
9 files changed, 491 insertions, 0 deletions
diff --git a/demos/qmlcustomizations/main.cpp b/demos/qmlcustomizations/main.cpp new file mode 100644 index 00000000..adb8f565 --- /dev/null +++ b/demos/qmlcustomizations/main.cpp @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui/QApplication> +#include <QDeclarativeEngine> +#include "qmlapplicationviewer.h" + +Q_DECL_EXPORT int main(int argc, char *argv[]) +{ + QScopedPointer<QApplication> app(createApplication(argc, argv)); + QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create()); + + viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); + viewer->setSource(QUrl("qrc:/qml/qmlcustomizations/loader.qml")); + viewer->showExpanded(); + + return app->exec(); +} diff --git a/demos/qmlcustomizations/qml/qmlcustomizations/View1.qml b/demos/qmlcustomizations/qml/qmlcustomizations/View1.qml new file mode 100644 index 00000000..7d996704 --- /dev/null +++ b/demos/qmlcustomizations/qml/qmlcustomizations/View1.qml @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +Rectangle { + anchors.fill: parent + + ChartView { + id: chart + title: "Top-5 car brand shares in Finland" + anchors.fill: parent + theme: ChartView.ChartThemeLight + legend: ChartView.LegendBottom + animationOptions: ChartView.SeriesAnimations + + PieSeries { + id: pieSeries + PieSlice { label: "Volkswagen"; value: 13.5 } + PieSlice { label: "Toyota"; value: 10.9 } + PieSlice { label: "Ford"; value: 8.6 } + PieSlice { label: "Skoda"; value: 8.2 } + PieSlice { label: "Volvo"; value: 6.8 } + } + } +} diff --git a/demos/qmlcustomizations/qml/qmlcustomizations/loader.qml b/demos/qmlcustomizations/qml/qmlcustomizations/loader.qml new file mode 100644 index 00000000..7668f0c6 --- /dev/null +++ b/demos/qmlcustomizations/qml/qmlcustomizations/loader.qml @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 + +Item { + id: container + width: 400 + height: 300 + Component.onCompleted: { + var co = Qt.createComponent("main.qml") + if (co.status == Component.Ready) { + var o = co.createObject(container) + } else { + console.log(co.errorString()) + console.log("QtCommercial.Chart 1.1 not available") + console.log("Please use correct QML_IMPORT_PATH export") + } + } +} diff --git a/demos/qmlcustomizations/qml/qmlcustomizations/main.qml b/demos/qmlcustomizations/qml/qmlcustomizations/main.qml new file mode 100644 index 00000000..c8ae550e --- /dev/null +++ b/demos/qmlcustomizations/qml/qmlcustomizations/main.qml @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +Rectangle { + width: parent.width + height: parent.height + property int __activeIndex: 1 + property real __intervalCoefficient: 0 + + + ChartView { + id: chartView + anchors.fill: parent + title: "Wheel of fortune" + legend: ChartView.LegendDisabled + + PieSeries { + id: wheelOfFortune + } + + SplineSeries { + id: splineSeries + } + + ScatterSeries { + id: scatterSeries + } + } + + + Component.onCompleted: { + __intervalCoefficient = Math.random() + 0.1; + console.log("__intervalCoefficient: " + __intervalCoefficient); + + for (var i = 0; i < 20; i++) + wheelOfFortune.append("", 1); + + var interval = 1; + for (var j = 0; interval < 800; j++) { + interval = __intervalCoefficient * j * j; + splineSeries.append(j, interval); + } + chartView.axisX.max = j; + chartView.axisY.max = 1000; + } + + Timer { + triggeredOnStart: true + running: true + repeat: true + interval: 100 + onTriggered: { +// console.log("interval: " + interval); + var index = __activeIndex % wheelOfFortune.count; + if (interval < 700) { + scatterSeries.clear(); + wheelOfFortune.at(index).exploded = false; + __activeIndex++; + index = __activeIndex % wheelOfFortune.count; + wheelOfFortune.at(index).exploded = true; + interval = splineSeries.at(__activeIndex).y; + scatterSeries.append(__activeIndex, interval); + } else { + // Switch the colors of the slice and the border + wheelOfFortune.at(index).borderWidth = 2; + var borderColor = wheelOfFortune.at(index).borderColor; + wheelOfFortune.at(index).borderColor = wheelOfFortune.at(index).color; + wheelOfFortune.at(index).color = borderColor; + } + } + } + +// Loader { +// id: loader +// anchors.fill: parent +// source: "View" + (__viewNumber % 5 + 1) + ".qml"; +// } +} diff --git a/demos/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.cpp b/demos/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.cpp new file mode 100644 index 00000000..8ba6e886 --- /dev/null +++ b/demos/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.cpp @@ -0,0 +1,200 @@ +// checksum 0x78c version 0x60010 +/* + 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 QCoreApplication::applicationDirPath() + + QLatin1String("/../Resources/") + path; +#else + QString pathInInstallDir; + const QString applicationDirPath = QCoreApplication::applicationDirPath(); + pathInInstallDir = QString::fromAscii("%1/../%2").arg(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/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.h b/demos/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.h new file mode 100644 index 00000000..f8008f5c --- /dev/null +++ b/demos/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.h @@ -0,0 +1,47 @@ +// checksum 0x82ed version 0x60010 +/* + 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/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.pri b/demos/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.pri new file mode 100644 index 00000000..567c6dc6 --- /dev/null +++ b/demos/qmlcustomizations/qmlapplicationviewer/qmlapplicationviewer.pri @@ -0,0 +1,13 @@ +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 +} + diff --git a/demos/qmlcustomizations/qmlcustomizations.pro b/demos/qmlcustomizations/qmlcustomizations.pro new file mode 100644 index 00000000..394db8f7 --- /dev/null +++ b/demos/qmlcustomizations/qmlcustomizations.pro @@ -0,0 +1,10 @@ +!include( ../demos.pri ) { + error( "Couldn't find the demos.pri file!" ) +} + +RESOURCES += resources.qrc +SOURCES += main.cpp + +include(qmlapplicationviewer/qmlapplicationviewer.pri) + +!system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_DEMOS_BIN_DIR" diff --git a/demos/qmlcustomizations/resources.qrc b/demos/qmlcustomizations/resources.qrc new file mode 100644 index 00000000..e32c3501 --- /dev/null +++ b/demos/qmlcustomizations/resources.qrc @@ -0,0 +1,7 @@ +<RCC> + <qresource prefix="/"> + <file>qml/qmlcustomizations/loader.qml</file> + <file>qml/qmlcustomizations/main.qml</file> + <file>qml/qmlcustomizations/View1.qml</file> + </qresource> +</RCC> |