##// END OF EJS Templates
Demo about creating a custom legend on QML
Tero Ahola -
r2069:fff5aa874bbe
parent child
Show More
@@ -0,0 +1,36
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include <QtGui/QApplication>
22 #include <QDeclarativeEngine>
23 #include "qmlapplicationviewer.h"
24
25 Q_DECL_EXPORT int main(int argc, char *argv[])
26 {
27 QScopedPointer<QApplication> app(createApplication(argc, argv));
28 QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
29
30 viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
31 viewer->setSource(QUrl("qrc:/qml/qmlcustomlegend/loader.qml"));
32 viewer->setRenderHint(QPainter::Antialiasing, true);
33 viewer->showExpanded();
34
35 return app->exec();
36 }
@@ -0,0 +1,30
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
23
24 AreaSeries {
25 id: series
26
27 Behavior on opacity {
28 NumberAnimation { duration: 250 }
29 }
30 }
@@ -0,0 +1,72
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
23
24 //![1]
25 ChartView {
26 id: chartViewHighlighted
27 title: ""
28 property variant selectedSeries
29 signal clicked
30
31 LineSeries {
32 id: lineSeries
33
34 axisX: ValueAxis {
35 min: 2005
36 max: 2011
37 labelFormat: "%.0f"
38 tickCount: 7
39 }
40 axisY: ValueAxis {
41 id: axisY
42 min: 0
43 max: 40000
44 niceNumbersEnabled: true
45 labelFormat: "%.0f"
46 tickCount: 5
47 }
48 }
49 //![1]
50
51 MouseArea {
52 anchors.fill: parent
53 onClicked: {
54 chartViewHighlighted.clicked();
55 }
56 }
57
58 onSelectedSeriesChanged: {
59 lineSeries.clear();
60 lineSeries.color = selectedSeries.color;
61 var maxVal = 0.0;
62 for (var i = 0; i < selectedSeries.upperSeries.count; i++ ) {
63 var y = selectedSeries.upperSeries.at(i).y - selectedSeries.lowerSeries.at(i).y;
64 lineSeries.append(selectedSeries.upperSeries.at(i).x, y);
65 if (maxVal < y)
66 maxVal = y;
67 }
68 chartViewHighlighted.title = selectedSeries.name;
69 axisY.max = maxVal;
70 }
71 }
72
@@ -0,0 +1,100
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
23
24 Rectangle {
25 id: chartViewSelector
26 width: parent.width
27 height: parent.height
28 signal seriesAdded(string seriesName, color seriesColor)
29
30 function highlightSeries(seriesName) {
31 if (seriesName == "") {
32 if (state != "")
33 state = "";
34
35 for (var i = 0; i < chartViewStacked.count; i++)
36 chartViewStacked.series(i).opacity = 1.0;
37 } else {
38 var targetOpacity = 0.1;
39 for (var j = 0; j < chartViewStacked.count; j++) {
40 if (chartViewStacked.series(j).name != seriesName)
41 chartViewStacked.series(j).opacity = 0.25;
42 else if (state == "highlight")
43 chartViewSelected.selectedSeries = chartViewStacked.series(j);
44 }
45 }
46 }
47
48 function selectSeries(seriesName) {
49 for (var i = 0; i < chartViewStacked.count; i++) {
50 if (chartViewStacked.series(i).name == seriesName) {
51 chartViewSelected.selectedSeries = chartViewStacked.series(i);
52 if (chartViewSelector.state == "")
53 chartViewSelector.state = "highlighted";
54 else
55 chartViewSelector.state = "";
56 }
57 }
58 }
59
60 ChartViewStacked {
61 id: chartViewStacked
62 anchors.left: parent.left
63 anchors.leftMargin: 0
64 width: parent.width
65 height: parent.height - parent.anchors.margins * 2 - customLegend.height
66 onSeriesAdded: chartViewSelector.seriesAdded(series.name, series.color);
67 }
68
69 ChartViewHighlighted {
70 id: chartViewSelected
71 anchors.left: chartViewStacked.right
72 width: parent.width
73 height: parent.height - parent.anchors.margins * 2 - customLegend.height
74
75 opacity: 0.0
76 onClicked: {
77 chartViewSelector.state = "";
78 }
79 }
80
81 states: State {
82 name: "highlighted"
83 PropertyChanges {
84 target: chartViewSelected
85 opacity: 1.0
86 }
87 PropertyChanges {
88 target: chartViewStacked
89 anchors.leftMargin: -chartViewStacked.width
90 opacity: 0.0
91 }
92 }
93
94 transitions: Transition {
95 PropertyAnimation {
96 properties: "width, height, opacity, anchors.leftMargin"
97 duration: 400
98 }
99 }
100 }
@@ -0,0 +1,131
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
23
24 ChartView {
25 id: chartView
26 title: "Government Finance Taxes in Finland"
27 signal entered(string seriesName)
28 signal exited(string seriesName)
29
30 ValueAxis {
31 id: axisX
32 min: 2005
33 max: 2011
34 tickCount: 7
35 labelFormat: "%.0f"
36 }
37
38 ValueAxis {
39 id: axisY
40 min: 0
41 max: 90000
42 tickCount: 10
43 labelFormat: "%.0f"
44 }
45
46 AnimatedAreaSeries {
47 id: stateSeries
48 name: "state"
49 axisX: axisX
50 axisY: axisY
51 borderWidth: 0
52 upperSeries: LineSeries {
53 id: stateUpper
54 XYPoint { x: 2005; y: 35771 }
55 XYPoint { x: 2006; y: 36822 }
56 XYPoint { x: 2007; y: 39220 }
57 XYPoint { x: 2008; y: 39624 }
58 XYPoint { x: 2009; y: 34061 }
59 XYPoint { x: 2010; y: 34680 }
60 XYPoint { x: 2011; y: 39180 }
61 }
62 lowerSeries: LineSeries {
63 XYPoint { x: 2005; y: 0 }
64 XYPoint { x: 2006; y: 0 }
65 XYPoint { x: 2007; y: 0 }
66 XYPoint { x: 2008; y: 0 }
67 XYPoint { x: 2009; y: 0 }
68 XYPoint { x: 2010; y: 0 }
69 XYPoint { x: 2011; y: 0 }
70 }
71 }
72
73 //![1]
74 AnimatedAreaSeries {
75 id: municipalSeries
76 name: "municipal"
77 axisX: axisX
78 axisY: axisY
79 borderWidth: 0
80 upperSeries: LineSeries {
81 id: municipalUpper
82 XYPoint { x: 2005; y: 35771 + 14330 }
83 XYPoint { x: 2006; y: 36822 + 15299 }
84 XYPoint { x: 2007; y: 39220 + 16482 }
85 XYPoint { x: 2008; y: 39624 + 17502 }
86 XYPoint { x: 2009; y: 34061 + 17595 }
87 XYPoint { x: 2010; y: 34680 + 18535 }
88 XYPoint { x: 2011; y: 39180 + 19166 }
89 }
90 lowerSeries: stateUpper
91 }
92 //![1]
93
94 AnimatedAreaSeries {
95 id: socialSeries
96 name: "social sec. funds"
97 axisX: axisX
98 axisY: axisY
99 borderWidth: 0
100 upperSeries: LineSeries {
101 id: socialUpper
102 XYPoint { x: 2005; y: 35771 + 14330 + 18865 }
103 XYPoint { x: 2006; y: 36822 + 15299 + 20258 }
104 XYPoint { x: 2007; y: 39220 + 16482 + 21367 }
105 XYPoint { x: 2008; y: 39624 + 17502 + 22316 }
106 XYPoint { x: 2009; y: 34061 + 17595 + 22026 }
107 XYPoint { x: 2010; y: 34680 + 18535 + 22601 }
108 XYPoint { x: 2011; y: 39180 + 19166 + 23696 }
109 }
110 lowerSeries: municipalUpper
111 }
112
113 AnimatedAreaSeries {
114 id: euSeries
115 name: "EU"
116 axisX: axisX
117 axisY: axisY
118 borderWidth: 0
119 upperSeries: LineSeries {
120 id: euUpper
121 XYPoint { x: 2005; y: 35771 + 14330 + 18865 + 154 }
122 XYPoint { x: 2006; y: 36822 + 15299 + 20258 + 176 }
123 XYPoint { x: 2007; y: 39220 + 16482 + 21367 + 200 }
124 XYPoint { x: 2008; y: 39624 + 17502 + 22316 + 206 }
125 XYPoint { x: 2009; y: 34061 + 17595 + 22026 + 153 }
126 XYPoint { x: 2010; y: 34680 + 18535 + 22601 + 152 }
127 XYPoint { x: 2011; y: 39180 + 19166 + 23696 + 190 }
128 }
129 lowerSeries: socialUpper
130 }
131 }
@@ -0,0 +1,117
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
23
24 Rectangle {
25 id: legend
26 radius: 8
27 color: "lightblue"
28 property int seriesCount: 0
29 property variant seriesNames: []
30 property variant seriesColors: []
31 signal entered(string seriesName)
32 signal exited(string seriesName)
33 signal selected(string seriesName)
34
35 function addSeries(seriesName, color) {
36 var names = seriesNames;
37 names[seriesCount] = seriesName;
38 seriesNames = names;
39
40 var colors = seriesColors;
41 colors[seriesCount] = color;
42 seriesColors = colors;
43
44 seriesCount++;
45 }
46
47 //![2]
48 Component {
49 id: legendDelegate
50 Rectangle {
51 id: rect
52 // ...
53 //![2]
54 property string name: seriesNames[index]
55 property color markerColor: seriesColors[index]
56 color: "transparent"
57 border.color: seriesColors[index]
58 border.width: 2
59 radius: 4
60 height: 20
61 width: row.width + row.anchors.leftMargin * 2
62
63 Row {
64 id: row
65 spacing: 5
66 anchors.verticalCenter: parent.verticalCenter
67 anchors.left: parent.left
68 anchors.leftMargin: 5
69 Rectangle {
70 id: marker
71 anchors.verticalCenter: parent.verticalCenter
72 color: markerColor
73 radius: 4
74 width: 12
75 height: 12
76 }
77 Text {
78 id: label
79 anchors.verticalCenter: parent.verticalCenter
80 text: name
81 }
82 }
83
84 //![3]
85 MouseArea {
86 anchors.fill: parent
87 hoverEnabled: true
88 onEntered: {
89 rect.color = "white";
90 legend.entered(label.text);
91 }
92 onExited: {
93 rect.color = "transparent";
94 legend.exited(label.text);
95 }
96 onClicked: {
97 legend.selected(label.text);
98 }
99 }
100 //![3]
101 }
102 }
103
104 //![1]
105 Row {
106 id: legendRow
107 anchors.centerIn: parent
108 spacing: 4
109
110 Repeater {
111 id: legendRepeater
112 model: seriesCount
113 delegate: legendDelegate
114 }
115 }
116 //![1]
117 }
@@ -0,0 +1,37
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22
23 Item {
24 id: container
25 width: 400
26 height: 300
27 Component.onCompleted: {
28 var co = Qt.createComponent("main.qml")
29 if (co.status == Component.Ready) {
30 var o = co.createObject(container)
31 } else {
32 console.log(co.errorString())
33 console.log("QtCommercial.Chart 1.1 not available")
34 console.log("Please use correct QML_IMPORT_PATH export")
35 }
36 }
37 }
@@ -0,0 +1,66
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
23
24 Rectangle {
25 id: main
26 width: parent.width
27 height: parent.height
28
29 Column {
30 id: column
31 anchors.fill: parent
32 anchors.bottomMargin: 10
33 spacing: 0
34
35 ChartViewSelector {
36 id: chartViewSelector
37 width: parent.width
38 height: parent.height - customLegend.height - anchors.bottomMargin
39 onSeriesAdded: customLegend.addSeries(seriesName, seriesColor);
40 }
41
42 CustomLegend {
43 id: customLegend
44 width: 360
45 height: 30
46 anchors.horizontalCenter: parent.horizontalCenter
47 onEntered: chartViewSelector.highlightSeries(seriesName);
48 onExited: chartViewSelector.highlightSeries("");
49 onSelected: chartViewSelector.selectSeries(seriesName);
50 }
51 }
52
53 states: State {
54 name: "highlighted"
55 PropertyChanges {
56 target: chartViewHighlighted
57 width: column.width
58 height: (column.height - column.anchors.margins * 2 - customLegend.height)
59 }
60 PropertyChanges {
61 target: chartViewStacked
62 width: 1
63 height: 1
64 }
65 }
66 }
@@ -0,0 +1,200
1 // checksum 0x78c version 0x60010
2 /*
3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 QmlApplicationViewer is a convenience class containing mobile device specific
5 code such as screen orientation handling. Also QML paths and debugging are
6 handled here.
7 It is recommended not to modify this file, since newer versions of Qt Creator
8 may offer an updated version of it.
9 */
10
11 #include "qmlapplicationviewer.h"
12
13 #include <QtCore/QDir>
14 #include <QtCore/QFileInfo>
15 #include <QtDeclarative/QDeclarativeComponent>
16 #include <QtDeclarative/QDeclarativeEngine>
17 #include <QtDeclarative/QDeclarativeContext>
18 #include <QtGui/QApplication>
19
20 #include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
21
22 #ifdef HARMATTAN_BOOSTER
23 #include <MDeclarativeCache>
24 #endif
25
26 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
27
28 #include <qt_private/qdeclarativedebughelper_p.h>
29
30 #if !defined(NO_JSDEBUGGER)
31 #include <jsdebuggeragent.h>
32 #endif
33 #if !defined(NO_QMLOBSERVER)
34 #include <qdeclarativeviewobserver.h>
35 #endif
36
37 // Enable debugging before any QDeclarativeEngine is created
38 struct QmlJsDebuggingEnabler
39 {
40 QmlJsDebuggingEnabler()
41 {
42 QDeclarativeDebugHelper::enableDebugging();
43 }
44 };
45
46 // Execute code in constructor before first QDeclarativeEngine is instantiated
47 static QmlJsDebuggingEnabler enableDebuggingHelper;
48
49 #endif // QMLJSDEBUGGER
50
51 class QmlApplicationViewerPrivate
52 {
53 QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {}
54
55 QString mainQmlFile;
56 QDeclarativeView *view;
57 friend class QmlApplicationViewer;
58 QString adjustPath(const QString &path);
59 };
60
61 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
62 {
63 #ifdef Q_OS_UNIX
64 #ifdef Q_OS_MAC
65 if (!QDir::isAbsolutePath(path))
66 return QCoreApplication::applicationDirPath()
67 + QLatin1String("/../Resources/") + path;
68 #else
69 QString pathInInstallDir;
70 const QString applicationDirPath = QCoreApplication::applicationDirPath();
71 pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path);
72
73 if (QFileInfo(pathInInstallDir).exists())
74 return pathInInstallDir;
75 #endif
76 #endif
77 return path;
78 }
79
80 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
81 : QDeclarativeView(parent)
82 , d(new QmlApplicationViewerPrivate(this))
83 {
84 connect(engine(), SIGNAL(quit()), SLOT(close()));
85 setResizeMode(QDeclarativeView::SizeRootObjectToView);
86 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
87 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
88 #if !defined(NO_JSDEBUGGER)
89 new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
90 #endif
91 #if !defined(NO_QMLOBSERVER)
92 new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
93 #endif
94 #endif
95 }
96
97 QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, QWidget *parent)
98 : QDeclarativeView(parent)
99 , d(new QmlApplicationViewerPrivate(view))
100 {
101 connect(view->engine(), SIGNAL(quit()), view, SLOT(close()));
102 view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
103 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
104 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
105 #if !defined(NO_JSDEBUGGER)
106 new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
107 #endif
108 #if !defined(NO_QMLOBSERVER)
109 new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
110 #endif
111 #endif
112 }
113
114 QmlApplicationViewer::~QmlApplicationViewer()
115 {
116 delete d;
117 }
118
119 QmlApplicationViewer *QmlApplicationViewer::create()
120 {
121 #ifdef HARMATTAN_BOOSTER
122 return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0);
123 #else
124 return new QmlApplicationViewer();
125 #endif
126 }
127
128 void QmlApplicationViewer::setMainQmlFile(const QString &file)
129 {
130 d->mainQmlFile = d->adjustPath(file);
131 d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile));
132 }
133
134 void QmlApplicationViewer::addImportPath(const QString &path)
135 {
136 d->view->engine()->addImportPath(d->adjustPath(path));
137 }
138
139 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
140 {
141 #if defined(Q_OS_SYMBIAN)
142 // If the version of Qt on the device is < 4.7.2, that attribute won't work
143 if (orientation != ScreenOrientationAuto) {
144 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
145 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
146 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
147 return;
148 }
149 }
150 #endif // Q_OS_SYMBIAN
151
152 Qt::WidgetAttribute attribute;
153 switch (orientation) {
154 #if QT_VERSION < 0x040702
155 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
156 case ScreenOrientationLockPortrait:
157 attribute = static_cast<Qt::WidgetAttribute>(128);
158 break;
159 case ScreenOrientationLockLandscape:
160 attribute = static_cast<Qt::WidgetAttribute>(129);
161 break;
162 default:
163 case ScreenOrientationAuto:
164 attribute = static_cast<Qt::WidgetAttribute>(130);
165 break;
166 #else // QT_VERSION < 0x040702
167 case ScreenOrientationLockPortrait:
168 attribute = Qt::WA_LockPortraitOrientation;
169 break;
170 case ScreenOrientationLockLandscape:
171 attribute = Qt::WA_LockLandscapeOrientation;
172 break;
173 default:
174 case ScreenOrientationAuto:
175 attribute = Qt::WA_AutoOrientation;
176 break;
177 #endif // QT_VERSION < 0x040702
178 };
179 setAttribute(attribute, true);
180 }
181
182 void QmlApplicationViewer::showExpanded()
183 {
184 #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
185 d->view->showFullScreen();
186 #elif defined(Q_WS_MAEMO_5)
187 d->view->showMaximized();
188 #else
189 d->view->show();
190 #endif
191 }
192
193 QApplication *createApplication(int &argc, char **argv)
194 {
195 #ifdef HARMATTAN_BOOSTER
196 return MDeclarativeCache::qApplication(argc, argv);
197 #else
198 return new QApplication(argc, argv);
199 #endif
200 }
@@ -0,0 +1,47
1 // checksum 0x82ed version 0x60010
2 /*
3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 QmlApplicationViewer is a convenience class containing mobile device specific
5 code such as screen orientation handling. Also QML paths and debugging are
6 handled here.
7 It is recommended not to modify this file, since newer versions of Qt Creator
8 may offer an updated version of it.
9 */
10
11 #ifndef QMLAPPLICATIONVIEWER_H
12 #define QMLAPPLICATIONVIEWER_H
13
14 #include <QtDeclarative/QDeclarativeView>
15
16 class QmlApplicationViewer : public QDeclarativeView
17 {
18 Q_OBJECT
19
20 public:
21 enum ScreenOrientation {
22 ScreenOrientationLockPortrait,
23 ScreenOrientationLockLandscape,
24 ScreenOrientationAuto
25 };
26
27 explicit QmlApplicationViewer(QWidget *parent = 0);
28 virtual ~QmlApplicationViewer();
29
30 static QmlApplicationViewer *create();
31
32 void setMainQmlFile(const QString &file);
33 void addImportPath(const QString &path);
34
35 // Note that this will only have an effect on Symbian and Fremantle.
36 void setOrientation(ScreenOrientation orientation);
37
38 void showExpanded();
39
40 private:
41 explicit QmlApplicationViewer(QDeclarativeView *view, QWidget *parent);
42 class QmlApplicationViewerPrivate *d;
43 };
44
45 QApplication *createApplication(int &argc, char **argv);
46
47 #endif // QMLAPPLICATIONVIEWER_H
@@ -0,0 +1,13
1 QT += declarative
2
3 SOURCES += $$PWD/qmlapplicationviewer.cpp
4 HEADERS += $$PWD/qmlapplicationviewer.h
5 INCLUDEPATH += $$PWD
6
7 # Include JS debugger library if QMLJSDEBUGGER_PATH is set
8 !isEmpty(QMLJSDEBUGGER_PATH) {
9 include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri)
10 } else {
11 DEFINES -= QMLJSDEBUGGER
12 }
13
@@ -0,0 +1,8
1 !include( ../demos.pri ) {
2 error( "Couldn't find the demos.pri file!" )
3 }
4
5 RESOURCES += resources.qrc
6 SOURCES += main.cpp
7
8 include(qmlapplicationviewer/qmlapplicationviewer.pri)
@@ -0,0 +1,11
1 <RCC>
2 <qresource prefix="/">
3 <file>qml/qmlcustomlegend/loader.qml</file>
4 <file>qml/qmlcustomlegend/main.qml</file>
5 <file>qml/qmlcustomlegend/CustomLegend.qml</file>
6 <file>qml/qmlcustomlegend/ChartViewStacked.qml</file>
7 <file>qml/qmlcustomlegend/ChartViewHighlighted.qml</file>
8 <file>qml/qmlcustomlegend/ChartViewSelector.qml</file>
9 <file>qml/qmlcustomlegend/AnimatedAreaSeries.qml</file>
10 </qresource>
11 </RCC>
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,40
1 /*!
2 \example demos/qmlcustomlegend
3 \title Qml Custom Legend
4 \subtitle
5
6 This demo application shows you how to create your own, custom legend instead of using the
7 built-in legend of ChartView API.
8
9 \table
10 \row
11 \o \br
12 The main view of the application shows a stacked area chart. This is how one of
13 \br
14 the stacked areas is created. See ChartViewStacked.qml and AnimatedAreaSeries.qml.
15 \br
16 \br
17 \snippet ../demos/qmlcustomlegend/qml/qmlcustomlegend/ChartViewStacked.qml 1
18 \o \inlineimage demos-qmlcustomlegend1.png
19 \row
20 \o \br
21 Hovering with mouse on top of the legend will highlight the hovered series
22 \br
23 (see CustomLegend.qml).
24 \br
25 \br
26 \snippet ../demos/qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml 1
27 \snippet ../demos/qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml 2
28 \snippet ../demos/qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml 3
29 \o \inlineimage demos-qmlcustomlegend2.png
30 \row
31 \o \br
32 You can also select one of the stacked areas for a closer look as a line series by
33 \br
34 a mouse click (see ChartViewHighlighted.qml).
35 \br
36 \br
37 \snippet ../demos/qmlcustomlegend/qml/qmlcustomlegend/ChartViewHighlighted.qml 1
38 \o \inlineimage demos-qmlcustomlegend3.png
39 \endtable
40 */
@@ -1,24 +1,25
1 CURRENTLY_BUILDING_COMPONENTS = "demos"
1 CURRENTLY_BUILDING_COMPONENTS = "demos"
2 !include( ../config.pri ) {
2 !include( ../config.pri ) {
3 error( "Couldn't find the config.pri file!" )
3 error( "Couldn't find the config.pri file!" )
4 }
4 }
5
5
6 TEMPLATE = subdirs
6 TEMPLATE = subdirs
7 SUBDIRS += piechartcustomization \
7 SUBDIRS += piechartcustomization \
8 dynamicspline \
8 dynamicspline \
9 nesteddonuts \
9 nesteddonuts \
10 qmlchart \
10 qmlchart \
11 qmlweather \
11 qmlweather \
12 qmlf1legends \
12 qmlf1legends \
13 qmlcustomizations \
13 qmlcustomizations \
14 qmlcustommodel \
14 qmlcustommodel \
15 chartinteractions \
15 chartinteractions \
16 qmlaxes
16 qmlaxes \
17 qmlcustomlegend
17
18
18 contains(QT_CONFIG, opengl) {
19 contains(QT_CONFIG, opengl) {
19 SUBDIRS += chartthemes \
20 SUBDIRS += chartthemes \
20 qmloscilloscope \
21 qmloscilloscope \
21 chartviewer
22 chartviewer
22 } else {
23 } else {
23 message("OpenGL not available. Some demos are disabled")
24 message("OpenGL not available. Some demos are disabled")
24 }
25 }
@@ -1,65 +1,67
1 /*!
1 /*!
2 \page demos.html
2 \page demos.html
3 \title Demos
3 \title Demos
4 \keyword Demos
4 \keyword Demos
5
5
6 \raw HTML
6 \raw HTML
7 <div class="demos">
7 <div class="demos">
8 <table>
8 <table>
9 <tr>
9 <tr>
10 <td align="center"><a href="demos-chartthemes.html">Chart Themes</a></td>
10 <td align="center"><a href="demos-chartthemes.html">Chart Themes</a></td>
11 <td align="center"><a href="demos-dynamicspline.html">Dynamic Spline Chart</a></td>
11 <td align="center"><a href="demos-dynamicspline.html">Dynamic Spline Chart</a></td>
12 </tr>
12 </tr>
13 <tr>
13 <tr>
14 <td><a href="demos-chartthemes.html"><img src="images/demo_chartthemes_blue_cerulean.png" width="300" alt="Chart Themes" /></a></td>
14 <td><a href="demos-chartthemes.html"><img src="images/demo_chartthemes_blue_cerulean.png" width="300" alt="Chart Themes" /></a></td>
15 <td><a href="demos-dynamicspline.html"><img src="images/demos_dynamicspline2.png" width="300" alt="Dynamic Spline" /></a></td>
15 <td><a href="demos-dynamicspline.html"><img src="images/demos_dynamicspline2.png" width="300" alt="Dynamic Spline" /></a></td>
16 </tr>
16 </tr>
17
17
18 <tr>
18 <tr>
19 <td align="center"><a href="demos-nesteddonuts.html">Nested Donuts Chart</a></td>
19 <td align="center"><a href="demos-nesteddonuts.html">Nested Donuts Chart</a></td>
20 <td align="center"><a href="demos-piechartcustomization.html">Pie Chart Customization</a></td>
20 <td align="center"><a href="demos-piechartcustomization.html">Pie Chart Customization</a></td>
21 </tr>
21 </tr>
22 <tr>
22 <tr>
23 <td><a href="demos-nesteddonuts.html"><img src="images/demos_nesteddonuts.png" width="300" alt="Nested Donuts Chart" /></a></td>
23 <td><a href="demos-nesteddonuts.html"><img src="images/demos_nesteddonuts.png" width="300" alt="Nested Donuts Chart" /></a></td>
24 <td><a href="demos-piechartcustomization.html"><img src="images/piechart_customization.png" width="300" alt="Pie Chart Customization" /></a></td>
24 <td><a href="demos-piechartcustomization.html"><img src="images/piechart_customization.png" width="300" alt="Pie Chart Customization" /></a></td>
25 </tr>
25 </tr>
26
26
27 <tr>
27 <tr>
28 <td align="center"><a href="demos-qmlchart.html">Qml Basic Charts</a></td>
28 <td align="center"><a href="demos-qmlchart.html">Qml Basic Charts</a></td>
29 <td align="center"><a href="demos-qmlaxes.html">Qml Axes</a></td>
29 <td align="center"><a href="demos-qmlaxes.html">Qml Axes</a></td>
30 </tr>
30 </tr>
31 <tr>
31 <tr>
32 <td><a href="demos-qmlchart.html"><img src="images/demos_qmlchart1.png" width="300" alt="Qml Basic Charts" /></a></td>
32 <td><a href="demos-qmlchart.html"><img src="images/demos_qmlchart1.png" width="300" alt="Qml Basic Charts" /></a></td>
33 <td><a href="demos-qmlaxes.html"><img src="images/demos_qmlaxes1.png" width="300" alt="Qml Axes" /></a></td>
33 <td><a href="demos-qmlaxes.html"><img src="images/demos_qmlaxes1.png" width="300" alt="Qml Axes" /></a></td>
34 </tr>
34 </tr>
35
35
36 <tr>
36 <tr>
37 <td align="center"><a href="demos-qmlcustomizations.html">Qml Customizations</a></td>
37 <td align="center"><a href="demos-qmlcustomizations.html">Qml Customizations</a></td>
38 <td align="center"><a href="demos-qmlcustommodel.html">Qml Custom Model</a></td>
38 <td align="center"><a href="demos-qmlcustommodel.html">Qml Custom Model</a></td>
39 </tr>
39 </tr>
40 <tr>
40 <tr>
41 <td><a href="demos-qmlcustomizations.html"><img src="images/demos_qmlcustomizations.png" width="300" alt="Qml Customizations" /></a></td>
41 <td><a href="demos-qmlcustomizations.html"><img src="images/demos_qmlcustomizations.png" width="300" alt="Qml Customizations" /></a></td>
42 <td><a href="demos-qmlcustommodel.html"><img src="images/demos_qmlcustommodel.png" width="300" alt="Qml Custom Model" /></a></td>
42 <td><a href="demos-qmlcustommodel.html"><img src="images/demos_qmlcustommodel.png" width="300" alt="Qml Custom Model" /></a></td>
43 </tr>
43 </tr>
44
44
45 <tr>
45 <tr>
46 <td align="center"><a href="demos-qmlf1legends.html">Qml F1 Legends</a></td>
46 <td align="center"><a href="demos-qmlf1legends.html">Qml F1 Legends</a></td>
47 <td align="center"><a href="demos-qmloscilloscope.html">Qml Oscilloscope</a></td>
47 <td align="center"><a href="demos-qmloscilloscope.html">Qml Oscilloscope</a></td>
48 </tr>
48 </tr>
49 <tr>
49 <tr>
50 <td><a href="demos-qmlf1legends.html"><img src="images/demos_qmlf1legends.png" width="300" alt="Qml F1 Legends" /></a></td>
50 <td><a href="demos-qmlf1legends.html"><img src="images/demos_qmlf1legends.png" width="300" alt="Qml F1 Legends" /></a></td>
51 <td><a href="demos-qmloscilloscope.html"><img src="images/demos_qmloscilloscope.png" width="300" alt="Qml Oscilloscope" /></a></td>
51 <td><a href="demos-qmloscilloscope.html"><img src="images/demos_qmloscilloscope.png" width="300" alt="Qml Oscilloscope" /></a></td>
52 </tr>
52 </tr>
53
53
54 <tr>
54 <tr>
55 <td align="center"><a href="demos-qmlweather.html">Qml Weather</a></td>
55 <td align="center"><a href="demos-qmlweather.html">Qml Weather</a></td>
56 <td align="center"><a href="demos-qmlcustomlegend.html">Qml Custom Legend</a></td>
56 </tr>
57 </tr>
57 <tr>
58 <tr>
58 <td><a href="demos-qmlweather.html"><img src="images/demos_qmlweather.png" width="300" alt="Qml Weather" /></a></td>
59 <td><a href="demos-qmlweather.html"><img src="images/demos_qmlweather.png" width="300" alt="Qml Weather" /></a></td>
60 <td><a href="demos-qmlcustomlegend.html"><img src="images/demos-qmlcustomlegend1.png" width="300" alt="Qml Custom Legend" /></a></td>
59 </tr>
61 </tr>
60
62
61 </table>
63 </table>
62 </div>
64 </div>
63 \endraw
65 \endraw
64
66
65 */
67 */
General Comments 0
You need to be logged in to leave comments. Login now