summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDavid Boddie <dboddie@trolltech.com>2010-07-16 15:46:21 (GMT)
committerDavid Boddie <dboddie@trolltech.com>2010-07-16 15:46:21 (GMT)
commit6b1b666574d6e27efdd3b243de8815a5278c3666 (patch)
tree7a5ac02fe569b3fc497ca8d0a333d10587eb3567 /examples
parenteef1d13743baddf41bd135d98fc2ad12944b8477 (diff)
parentab4dde176cfa314522964e5e5fbf9f2d388f8fdf (diff)
downloadQt-6b1b666574d6e27efdd3b243de8815a5278c3666.zip
Qt-6b1b666574d6e27efdd3b243de8815a5278c3666.tar.gz
Qt-6b1b666574d6e27efdd3b243de8815a5278c3666.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7
Conflicts: tools/qdoc3/test/qt.qdocconf
Diffstat (limited to 'examples')
-rw-r--r--examples/declarative/cppextensions/imageprovider/imageprovider-example.qml28
-rw-r--r--examples/declarative/cppextensions/imageprovider/imageprovider.cpp73
-rw-r--r--examples/declarative/cppextensions/plugins/com/nokia/TimeExample/Clock.qml16
-rw-r--r--examples/declarative/modelviews/listview/highlight.qml5
-rw-r--r--examples/declarative/touchinteraction/mousearea/mousearea-example.qml64
-rw-r--r--examples/declarative/toys/clocks/content/Clock.qml35
-rw-r--r--examples/declarative/toys/corkboards/Day.qml6
-rw-r--r--examples/declarative/toys/tvtennis/tvtennis.qml24
-rw-r--r--examples/declarative/tutorials/extending/chapter1-basics/app.qml18
-rw-r--r--examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro4
-rw-r--r--examples/declarative/tutorials/extending/chapter1-basics/main.cpp4
-rw-r--r--examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp81
-rw-r--r--examples/declarative/tutorials/extending/chapter1-basics/piechart.h (renamed from examples/declarative/tutorials/extending/chapter1-basics/musician.h)21
-rw-r--r--examples/declarative/tutorials/extending/chapter2-methods/app.qml24
-rw-r--r--examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro4
-rw-r--r--examples/declarative/tutorials/extending/chapter2-methods/main.cpp4
-rw-r--r--examples/declarative/tutorials/extending/chapter2-methods/piechart.cpp87
-rw-r--r--examples/declarative/tutorials/extending/chapter2-methods/piechart.h (renamed from examples/declarative/tutorials/extending/chapter3-bindings/musician.h)26
-rw-r--r--examples/declarative/tutorials/extending/chapter3-bindings/app.qml42
-rw-r--r--examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro4
-rw-r--r--examples/declarative/tutorials/extending/chapter3-bindings/main.cpp4
-rw-r--r--examples/declarative/tutorials/extending/chapter3-bindings/piechart.cpp89
-rw-r--r--examples/declarative/tutorials/extending/chapter3-bindings/piechart.h84
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml18
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro8
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.cpp56
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp8
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.cpp (renamed from examples/declarative/tutorials/extending/chapter2-methods/musician.cpp)30
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h (renamed from examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h)20
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.cpp68
-rw-r--r--examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h (renamed from examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.h)21
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/app.qml70
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro7
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp (renamed from examples/declarative/tutorials/extending/chapter1-basics/musician.cpp)34
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/piechart.cpp (renamed from examples/declarative/tutorials/extending/chapter3-bindings/musician.cpp)32
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h (renamed from examples/declarative/tutorials/extending/chapter2-methods/musician.h)34
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.cpp88
-rw-r--r--examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h76
-rw-r--r--examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp56
-rw-r--r--examples/declarative/tutorials/extending/chapter5-plugins/instrument.h61
-rw-r--r--examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp67
-rw-r--r--examples/declarative/tutorials/extending/chapter5-plugins/qmldir1
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/app.qml (renamed from examples/declarative/tutorials/extending/chapter5-plugins/app.qml)29
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro (renamed from examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro)12
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp (renamed from examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.cpp)14
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.h (renamed from examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.h)6
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/piechart.cpp (renamed from examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.cpp)24
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/piechart.h (renamed from examples/declarative/tutorials/extending/chapter5-plugins/musician.h)21
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp88
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h74
-rw-r--r--examples/declarative/tutorials/extending/chapter6-plugins/qmldir1
-rw-r--r--examples/declarative/tutorials/extending/extending.pro3
-rw-r--r--examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml11
-rwxr-xr-xexamples/declarative/tutorials/samegame/samegame4/content/samegame.js7
-rw-r--r--examples/declarative/ui-components/dialcontrol/content/Dial.qml19
-rw-r--r--examples/declarative/ui-components/tabwidget/TabWidget.qml7
-rw-r--r--examples/network/bearermonitor/sessionwidget.h2
-rw-r--r--examples/network/bearermonitor/sessionwidget_maemo.ui48
58 files changed, 1254 insertions, 614 deletions
diff --git a/examples/declarative/cppextensions/imageprovider/imageprovider-example.qml b/examples/declarative/cppextensions/imageprovider/imageprovider-example.qml
index 5890c91..1ef97fa 100644
--- a/examples/declarative/cppextensions/imageprovider/imageprovider-example.qml
+++ b/examples/declarative/cppextensions/imageprovider/imageprovider-example.qml
@@ -37,29 +37,13 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-
import Qt 4.7
-import "ImageProviderCore"
-//![0]
-ListView {
- width: 100; height: 100
- anchors.fill: parent
-
- model: myModel
+import "ImageProviderCore" // import the plugin that registers the color image provider
- delegate: Component {
- Item {
- width: 100
- height: 50
- Text {
- text: "Loading..."
- anchors.centerIn: parent
- }
- Image {
- source: modelData
- sourceSize: "50x25"
- }
- }
- }
+//![0]
+Column {
+ Image { source: "image://colors/yellow" }
+ Image { source: "image://colors/red" }
}
//![0]
+
diff --git a/examples/declarative/cppextensions/imageprovider/imageprovider.cpp b/examples/declarative/cppextensions/imageprovider/imageprovider.cpp
index 0281b4a..18d027e 100644
--- a/examples/declarative/cppextensions/imageprovider/imageprovider.cpp
+++ b/examples/declarative/cppextensions/imageprovider/imageprovider.cpp
@@ -42,7 +42,6 @@
#include <qdeclarativeextensionplugin.h>
#include <qdeclarativeengine.h>
-#include <qdeclarativecontext.h>
#include <qdeclarative.h>
#include <qdeclarativeitem.h>
#include <qdeclarativeimageprovider.h>
@@ -50,62 +49,57 @@
#include <QImage>
#include <QPainter>
-/*
- This example illustrates using a QDeclarativeImageProvider to serve
- images asynchronously.
-*/
-
//![0]
class ColorImageProvider : public QDeclarativeImageProvider
{
public:
- // This is run in a low priority thread.
- QImage request(const QString &id, QSize *size, const QSize &req_size)
+ ColorImageProvider()
+ : QDeclarativeImageProvider(QDeclarativeImageProvider::Pixmap)
{
- if (size) *size = QSize(100,50);
- QImage image(
- req_size.width() > 0 ? req_size.width() : 100,
- req_size.height() > 0 ? req_size.height() : 50,
- QImage::Format_RGB32);
- image.fill(QColor(id).rgba());
- QPainter p(&image);
- QFont f = p.font();
- f.setPixelSize(30);
- p.setFont(f);
- p.setPen(Qt::black);
- if (req_size.isValid())
- p.scale(req_size.width()/100.0, req_size.height()/50.0);
- p.drawText(QRectF(0,0,100,50),Qt::AlignCenter,id);
- return image;
+ }
+
+ QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
+ {
+ int width = 100;
+ int height = 50;
+
+ if (size)
+ *size = QSize(width, height);
+ QPixmap pixmap(requestedSize.width() > 0 ? requestedSize.width() : width,
+ requestedSize.height() > 0 ? requestedSize.height() : height);
+ pixmap.fill(QColor(id).rgba());
+//![0]
+
+ // write the color name
+ QPainter painter(&pixmap);
+ QFont f = painter.font();
+ f.setPixelSize(20);
+ painter.setFont(f);
+ painter.setPen(Qt::black);
+ if (requestedSize.isValid())
+ painter.scale(requestedSize.width() / width, requestedSize.height() / height);
+ painter.drawText(QRectF(0, 0, width, height), Qt::AlignCenter, id);
+
+//![1]
+ return pixmap;
}
};
+//![1]
class ImageProviderExtensionPlugin : public QDeclarativeExtensionPlugin
{
Q_OBJECT
public:
- void registerTypes(const char *uri) {
+ void registerTypes(const char *uri)
+ {
Q_UNUSED(uri);
-
}
- void initializeEngine(QDeclarativeEngine *engine, const char *uri) {
+ void initializeEngine(QDeclarativeEngine *engine, const char *uri)
+ {
Q_UNUSED(uri);
-
engine->addImageProvider("colors", new ColorImageProvider);
-
- QStringList dataList;
- dataList.append("image://colors/red");
- dataList.append("image://colors/green");
- dataList.append("image://colors/blue");
- dataList.append("image://colors/brown");
- dataList.append("image://colors/orange");
- dataList.append("image://colors/purple");
- dataList.append("image://colors/yellow");
-
- QDeclarativeContext *ctxt = engine->rootContext();
- ctxt->setContextProperty("myModel", QVariant::fromValue(dataList));
}
};
@@ -113,5 +107,4 @@ public:
#include "imageprovider.moc"
Q_EXPORT_PLUGIN(ImageProviderExtensionPlugin);
-//![0]
diff --git a/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/Clock.qml b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/Clock.qml
index 37128b5..6b2676e 100644
--- a/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/Clock.qml
+++ b/examples/declarative/cppextensions/plugins/com/nokia/TimeExample/Clock.qml
@@ -57,10 +57,10 @@ Rectangle {
smooth: true
transform: Rotation {
id: hourRotation
- origin.x: 7.5; origin.y: 73; angle: 0
- SpringFollow on angle {
- spring: 2; damping: 0.2; modulus: 360
- to: (clock.hours * 30) + (clock.minutes * 0.5)
+ origin.x: 7.5; origin.y: 73;
+ angle: (clock.hours * 30) + (clock.minutes * 0.5)
+ Behavior on angle {
+ SpringAnimation{ spring: 2; damping: 0.2; modulus: 360 }
}
}
}
@@ -71,10 +71,10 @@ Rectangle {
smooth: true
transform: Rotation {
id: minuteRotation
- origin.x: 6.5; origin.y: 83; angle: 0
- SpringFollow on angle {
- spring: 2; damping: 0.2; modulus: 360
- to: clock.minutes * 6
+ origin.x: 6.5; origin.y: 83;
+ angle: clock.minutes * 6
+ Behavior on angle {
+ SpringAnimation{ spring: 2; damping: 0.2; modulus: 360 }
}
}
}
diff --git a/examples/declarative/modelviews/listview/highlight.qml b/examples/declarative/modelviews/listview/highlight.qml
index 4c14f2a..2d68da6 100644
--- a/examples/declarative/modelviews/listview/highlight.qml
+++ b/examples/declarative/modelviews/listview/highlight.qml
@@ -39,7 +39,7 @@
****************************************************************************/
// This example shows how to create your own highlight delegate for a ListView
-// that uses a SpringFollow animation to provide custom movement when the
+// that uses a SpringAnimation to provide custom movement when the
// highlight bar is moved between items.
import Qt 4.7
@@ -78,7 +78,8 @@ Rectangle {
Rectangle {
width: 200; height: 50
color: "#FFFF88"
- SpringFollow on y { to: listView.currentItem.y; spring: 3; damping: 0.1 }
+ y: listView.currentItem.y;
+ Behavior on y { SpringAnimation { spring: 2; damping: 0.1 } }
}
}
diff --git a/examples/declarative/touchinteraction/mousearea/mousearea-example.qml b/examples/declarative/touchinteraction/mousearea/mousearea-example.qml
index 64f72a9..85ea2dc 100644
--- a/examples/declarative/touchinteraction/mousearea/mousearea-example.qml
+++ b/examples/declarative/touchinteraction/mousearea/mousearea-example.qml
@@ -44,59 +44,69 @@ Rectangle {
id: box
width: 350; height: 250
- function showInfo(text) {
- statusText.text = text
- }
-
Rectangle {
+ id: redSquare
width: 80; height: 80
+ anchors.top: parent.top; anchors.left: parent.left; anchors.margins: 10
color: "red"
Text { text: "Click"; font.pixelSize: 16; anchors.centerIn: parent }
MouseArea {
- anchors.fill: parent
+ anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
- onPressed: box.showInfo('Pressed (x=' + mouse.x + ' y=' + mouse.y + ' button='
- + (mouse.button == Qt.RightButton ? 'right' : 'left')
- + ' Shift=' + (mouse.modifiers & Qt.ShiftModifier ? 'true' : 'false') + ')')
- onReleased: box.showInfo('Released (x=' + mouse.x + ' y=' + mouse.y
- + ' isClick=' + mouse.isClick + ' wasHeld=' + mouse.wasHeld + ')')
- onClicked: box.showInfo('Clicked (x=' + mouse.x + ' y=' + mouse.y + ' wasHeld=' + mouse.wasHeld + ')')
- onDoubleClicked: box.showInfo('Double clicked (x=' + mouse.x + ' y=' + mouse.y + ')')
- onPressAndHold: box.showInfo('Press and hold')
- onEntered: box.showInfo('Entered (pressed=' + pressed + ')')
- onExited: box.showInfo('Exited (pressed=' + pressed + ')')
+ onEntered: info.text = 'Entered'
+ onExited: info.text = 'Exited (pressed=' + pressed + ')'
+
+ onPressed: {
+ info.text = 'Pressed (button=' + (mouse.button == Qt.RightButton ? 'right' : 'left')
+ + ' shift=' + (mouse.modifiers & Qt.ShiftModifier ? 'true' : 'false') + ')'
+ var posInBox = redSquare.mapToItem(box, mouse.x, mouse.y)
+ posInfo.text = + mouse.x + ',' + mouse.y + ' in square'
+ + ' (' + posInBox.x + ',' + posInBox.y + ' in window)'
+ }
+
+ onReleased: {
+ info.text = 'Released (isClick=' + mouse.isClick + ' wasHeld=' + mouse.wasHeld + ')'
+ posInfo.text = ''
+ }
+
+ onPressAndHold: info.text = 'Press and hold'
+ onClicked: info.text = 'Clicked (wasHeld=' + mouse.wasHeld + ')'
+ onDoubleClicked: info.text = 'Double clicked'
}
}
Rectangle {
- width: 80; height: 80; anchors.right: parent.right
+ id: blueSquare
+ width: 80; height: 80
+ x: box.width - width - 10; y: 10 // making this item draggable, so don't use anchors
color: "blue"
Text { text: "Drag"; font.pixelSize: 16; color: "white"; anchors.centerIn: parent }
MouseArea {
anchors.fill: parent
- drag.target: parent
- drag.axis: Drag.XAxis
+ drag.target: blueSquare
+ drag.axis: Drag.XandYAxis
drag.minimumX: 0
- drag.maximumX: 150
-
- onPressed: box.showInfo('Pressed')
- onReleased: box.showInfo('Released (isClick=' + mouse.isClick + ' wasHeld=' + mouse.wasHeld + ')')
- onClicked: box.showInfo('Clicked' + ' (wasHeld=' + mouse.wasHeld + ')')
- onDoubleClicked: box.showInfo('Double clicked')
- onPressAndHold: box.showInfo('Press and hold')
+ drag.maximumX: box.width - parent.width
+ drag.minimumY: 0
+ drag.maximumY: box.height - parent.width
}
}
Text {
- id: statusText
- anchors.bottom: parent.bottom; anchors.horizontalCenter: parent.horizontalCenter; anchors.margins: 30
+ id: info
+ anchors.bottom: posInfo.top; anchors.horizontalCenter: parent.horizontalCenter; anchors.margins: 30
onTextChanged: console.log(text)
}
+
+ Text {
+ id: posInfo
+ anchors.bottom: parent.bottom; anchors.horizontalCenter: parent.horizontalCenter; anchors.margins: 30
+ }
}
diff --git a/examples/declarative/toys/clocks/content/Clock.qml b/examples/declarative/toys/clocks/content/Clock.qml
index 136573b..24a07ec 100644
--- a/examples/declarative/toys/clocks/content/Clock.qml
+++ b/examples/declarative/toys/clocks/content/Clock.qml
@@ -45,10 +45,10 @@ Item {
width: 200; height: 230
property alias city: cityLabel.text
- property variant hours
- property variant minutes
- property variant seconds
- property variant shift : 0
+ property int hours
+ property int minutes
+ property int seconds
+ property real shift
property bool night: false
function timeChanged() {
@@ -60,23 +60,24 @@ Item {
}
Timer {
- interval: 100; running: true; repeat: true; triggeredOnStart: true
+ interval: 100; running: true; repeat: true;
onTriggered: clock.timeChanged()
}
Image { id: background; source: "clock.png"; visible: clock.night == false }
Image { source: "clock-night.png"; visible: clock.night == true }
+
Image {
x: 92.5; y: 27
source: "hour.png"
smooth: true
transform: Rotation {
id: hourRotation
- origin.x: 7.5; origin.y: 73; angle: 0
- SpringFollow on angle {
- spring: 2; damping: 0.2; modulus: 360
- to: (clock.hours * 30) + (clock.minutes * 0.5)
+ origin.x: 7.5; origin.y: 73;
+ angle: (clock.hours * 30) + (clock.minutes * 0.5)
+ Behavior on angle {
+ NumberAnimation{}
}
}
}
@@ -87,10 +88,10 @@ Item {
smooth: true
transform: Rotation {
id: minuteRotation
- origin.x: 6.5; origin.y: 83; angle: 0
- SpringFollow on angle {
- spring: 2; damping: 0.2; modulus: 360
- to: clock.minutes * 6
+ origin.x: 6.5; origin.y: 83;
+ angle: clock.minutes * 6
+ Behavior on angle {
+ NumberAnimation{}
}
}
}
@@ -101,10 +102,10 @@ Item {
smooth: true
transform: Rotation {
id: secondRotation
- origin.x: 2.5; origin.y: 80; angle: 0
- SpringFollow on angle {
- spring: 5; damping: 0.25; modulus: 360
- to: clock.seconds * 6
+ origin.x: 2.5; origin.y: 80;
+ angle: clock.seconds * 6
+ Behavior on angle {
+ NumberAnimation{}
}
}
}
diff --git a/examples/declarative/toys/corkboards/Day.qml b/examples/declarative/toys/corkboards/Day.qml
index cc297b1..9d1f3ae 100644
--- a/examples/declarative/toys/corkboards/Day.qml
+++ b/examples/declarative/toys/corkboards/Day.qml
@@ -70,9 +70,9 @@ Component {
x: randomX; y: randomY
- SpringFollow on rotation {
- to: -flickable.horizontalVelocity / 100
- spring: 2.0; damping: 0.15
+ rotation: -flickable.horizontalVelocity / 100;
+ Behavior on rotation {
+ SpringAnimation { spring: 2.0; damping: 0.15 }
}
Item {
diff --git a/examples/declarative/toys/tvtennis/tvtennis.qml b/examples/declarative/toys/tvtennis/tvtennis.qml
index 726c649..2e144ed 100644
--- a/examples/declarative/toys/tvtennis/tvtennis.qml
+++ b/examples/declarative/toys/tvtennis/tvtennis.qml
@@ -50,7 +50,6 @@ Rectangle {
id: ball
// Add a property for the target y coordinate
- property int targetY : page.height - 10
property variant direction : "right"
x: 20; width: 20; height: 20; z: 1
@@ -65,15 +64,18 @@ Rectangle {
PropertyAction { target: ball; property: "direction"; value: "right" }
}
- // Make y follow the target y coordinate, with a velocity of 200
- SpringFollow on y { to: ball.targetY; velocity: 200 }
+ // Make y move with a velocity of 200
+ Behavior on y { SpringAnimation{ velocity: 200; }
+ }
+
+ Component.onCompleted: y = page.height-10; // start the ball motion
// Detect the ball hitting the top or bottom of the view and bounce it
onYChanged: {
if (y <= 0) {
- targetY = page.height - 20;
+ y = page.height - 20;
} else if (y >= page.height - 20) {
- targetY = 0;
+ y = 0;
}
}
}
@@ -84,19 +86,15 @@ Rectangle {
id: leftBat
color: "Lime"
x: 2; width: 20; height: 90
- SpringFollow on y {
- to: ball.y - 45; velocity: 300
- enabled: ball.direction == 'left'
- }
+ y: ball.direction == 'left' ? ball.y - 45 : page.height/2 -45;
+ Behavior on y { SpringAnimation{ spring: 1; damping: .1; } }
}
Rectangle {
id: rightBat
color: "Lime"
x: page.width - 22; width: 20; height: 90
- SpringFollow on y {
- to: ball.y-45; velocity: 300
- enabled: ball.direction == 'right'
- }
+ y: ball.direction == 'right' ? ball.y - 45 : page.height/2 -45;
+ Behavior on y { SpringAnimation{ spring: 1; damping: .1; } }
}
// The rest, to make it look realistic, if neither ever scores...
diff --git a/examples/declarative/tutorials/extending/chapter1-basics/app.qml b/examples/declarative/tutorials/extending/chapter1-basics/app.qml
index 9af155c..ada088d 100644
--- a/examples/declarative/tutorials/extending/chapter1-basics/app.qml
+++ b/examples/declarative/tutorials/extending/chapter1-basics/app.qml
@@ -38,21 +38,23 @@
**
****************************************************************************/
//![0]
-import Music 1.0
+import Charts 1.0
import Qt 4.7
-Rectangle {
+Item {
width: 300; height: 200
- Musician {
- id: aMusician
- name: "Reddy the Rocker"
- instrument: "Guitar"
+ PieChart {
+ id: aPieChart
+ anchors.centerIn: parent
+ width: 100; height: 100
+ name: "A simple pie chart"
+ color: "red"
}
Text {
- anchors.fill: parent
- text: aMusician.name + " plays the " + aMusician.instrument
+ anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 }
+ text: aPieChart.name
}
}
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro b/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro
index bd05ebe..0f04167 100644
--- a/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro
+++ b/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro
@@ -1,5 +1,5 @@
QT += declarative
-HEADERS += musician.h
-SOURCES += musician.cpp \
+HEADERS += piechart.h
+SOURCES += piechart.cpp \
main.cpp
diff --git a/examples/declarative/tutorials/extending/chapter1-basics/main.cpp b/examples/declarative/tutorials/extending/chapter1-basics/main.cpp
index 8ef6965..a5dbab3 100644
--- a/examples/declarative/tutorials/extending/chapter1-basics/main.cpp
+++ b/examples/declarative/tutorials/extending/chapter1-basics/main.cpp
@@ -38,7 +38,7 @@
**
****************************************************************************/
//![0]
-#include "musician.h"
+#include "piechart.h"
#include <qdeclarative.h>
#include <QDeclarativeView>
#include <QApplication>
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- qmlRegisterType<Musician>("Music", 1, 0, "Musician");
+ qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("app.qml"));
diff --git a/examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp b/examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp
new file mode 100644
index 0000000..3b9ef71
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "piechart.h"
+#include <QPainter>
+
+//![0]
+PieChart::PieChart(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+{
+ // need to disable this flag to draw inside a QDeclarativeItem
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+//![0]
+
+QString PieChart::name() const
+{
+ return m_name;
+}
+
+void PieChart::setName(const QString &name)
+{
+ m_name = name;
+}
+
+QColor PieChart::color() const
+{
+ return m_color;
+}
+
+void PieChart::setColor(const QColor &color)
+{
+ m_color = color;
+}
+
+//![1]
+void PieChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QPen pen(m_color, 2);
+ painter->setPen(pen);
+ painter->setRenderHints(QPainter::Antialiasing, true);
+ painter->drawPie(boundingRect(), 90 * 16, 290 * 16);
+}
+//![1]
+
diff --git a/examples/declarative/tutorials/extending/chapter1-basics/musician.h b/examples/declarative/tutorials/extending/chapter1-basics/piechart.h
index f9a0537..aae7b26 100644
--- a/examples/declarative/tutorials/extending/chapter1-basics/musician.h
+++ b/examples/declarative/tutorials/extending/chapter1-basics/piechart.h
@@ -37,30 +37,33 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef MUSICIAN_H
-#define MUSICIAN_H
+#ifndef PIECHART_H
+#define PIECHART_H
//![0]
-#include <QObject>
+#include <QDeclarativeItem>
+#include <QColor>
-class Musician : public QObject
+class PieChart : public QDeclarativeItem
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(QString instrument READ instrument WRITE setInstrument)
+ Q_PROPERTY(QColor color READ color WRITE setColor)
public:
- Musician(QObject *parent = 0);
+ PieChart(QDeclarativeItem *parent = 0);
QString name() const;
void setName(const QString &name);
- QString instrument() const;
- void setInstrument(const QString &instrument);
+ QColor color() const;
+ void setColor(const QColor &color);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
private:
QString m_name;
- QString m_instrument;
+ QColor m_color;
};
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter2-methods/app.qml b/examples/declarative/tutorials/extending/chapter2-methods/app.qml
index 02d33c2..0b55f7c 100644
--- a/examples/declarative/tutorials/extending/chapter2-methods/app.qml
+++ b/examples/declarative/tutorials/extending/chapter2-methods/app.qml
@@ -38,23 +38,29 @@
**
****************************************************************************/
//![0]
-import Music 1.0
+import Charts 1.0
import Qt 4.7
-Rectangle {
- width: 200; height: 200
+Item {
+ width: 300; height: 200
- Musician {
- id: aMusician
- name: "Reddy the Rocker"
- instrument: "Guitar"
+ PieChart {
+ id: aPieChart
+ anchors.centerIn: parent
+ width: 100; height: 100
+ color: "red"
- onPerformanceEnded: console.log("The performance has now ended")
+ onChartCleared: console.log("The chart has been cleared")
}
MouseArea {
anchors.fill: parent
- onClicked: aMusician.perform()
+ onClicked: aPieChart.clearChart()
+ }
+
+ Text {
+ anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 }
+ text: "Click anywhere to clear the chart"
}
}
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro b/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro
index bd05ebe..0f04167 100644
--- a/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro
+++ b/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro
@@ -1,5 +1,5 @@
QT += declarative
-HEADERS += musician.h
-SOURCES += musician.cpp \
+HEADERS += piechart.h
+SOURCES += piechart.cpp \
main.cpp
diff --git a/examples/declarative/tutorials/extending/chapter2-methods/main.cpp b/examples/declarative/tutorials/extending/chapter2-methods/main.cpp
index 8ef6965..a5dbab3 100644
--- a/examples/declarative/tutorials/extending/chapter2-methods/main.cpp
+++ b/examples/declarative/tutorials/extending/chapter2-methods/main.cpp
@@ -38,7 +38,7 @@
**
****************************************************************************/
//![0]
-#include "musician.h"
+#include "piechart.h"
#include <qdeclarative.h>
#include <QDeclarativeView>
#include <QApplication>
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- qmlRegisterType<Musician>("Music", 1, 0, "Musician");
+ qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("app.qml"));
diff --git a/examples/declarative/tutorials/extending/chapter2-methods/piechart.cpp b/examples/declarative/tutorials/extending/chapter2-methods/piechart.cpp
new file mode 100644
index 0000000..11ff7c8
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter2-methods/piechart.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "piechart.h"
+#include <QPainter>
+#include <QDebug>
+
+PieChart::PieChart(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+{
+ // need to disable this flag to draw inside a QDeclarativeItem
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+
+QString PieChart::name() const
+{
+ return m_name;
+}
+
+void PieChart::setName(const QString &name)
+{
+ m_name = name;
+}
+
+QColor PieChart::color() const
+{
+ return m_color;
+}
+
+void PieChart::setColor(const QColor &color)
+{
+ m_color = color;
+}
+
+void PieChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QPen pen(m_color, 2);
+ painter->setPen(pen);
+ painter->setRenderHints(QPainter::Antialiasing, true);
+ painter->drawPie(boundingRect(), 90 * 16, 290 * 16);
+}
+
+//![0]
+void PieChart::clearChart()
+{
+ setColor(QColor(Qt::transparent));
+ update();
+
+ emit chartCleared();
+}
+//![0]
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/musician.h b/examples/declarative/tutorials/extending/chapter2-methods/piechart.h
index 0b0addb..246fd9f 100644
--- a/examples/declarative/tutorials/extending/chapter3-bindings/musician.h
+++ b/examples/declarative/tutorials/extending/chapter2-methods/piechart.h
@@ -37,42 +37,44 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef MUSICIAN_H
-#define MUSICIAN_H
+#ifndef PIECHART_H
+#define PIECHART_H
-#include <QObject>
+#include <QDeclarativeItem>
+#include <QColor>
//![0]
-class Musician : public QObject
+class PieChart : public QDeclarativeItem
{
//![0]
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(QString instrument READ instrument WRITE setInstrument)
+ Q_PROPERTY(QColor color READ color WRITE setColor)
//![1]
- Q_PROPERTY(QString instrument READ instrument WRITE setInstrument NOTIFY instrumentChanged)
public:
//![1]
- Musician(QObject *parent = 0);
+ PieChart(QDeclarativeItem *parent = 0);
QString name() const;
void setName(const QString &name);
- QString instrument() const;
- void setInstrument(const QString &instrument);
+ QColor color() const;
+ void setColor(const QColor &color);
- Q_INVOKABLE void perform();
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
//![2]
+ Q_INVOKABLE void clearChart();
+
signals:
- void instrumentChanged();
+ void chartCleared();
//![2]
private:
QString m_name;
- QString m_instrument;
+ QColor m_color;
//![3]
};
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/app.qml b/examples/declarative/tutorials/extending/chapter3-bindings/app.qml
index 8bf6ecf..2ff6ae1 100644
--- a/examples/declarative/tutorials/extending/chapter3-bindings/app.qml
+++ b/examples/declarative/tutorials/extending/chapter3-bindings/app.qml
@@ -38,35 +38,37 @@
**
****************************************************************************/
//![0]
-import Music 1.0
+import Charts 1.0
import Qt 4.7
-Rectangle {
- width: 200; height: 200
+Item {
+ width: 300; height: 200
- Musician {
- id: reddy
- name: "Reddy the Rocker"
- instrument: "Guitar"
- }
+ Row {
+ anchors.centerIn: parent
+ spacing: 20
+
+ PieChart {
+ id: chartA
+ width: 100; height: 100
+ color: "red"
+ }
- Musician {
- id: craig
- name: "Craig the Copycat"
- instrument: reddy.instrument
+ PieChart {
+ id: chartB
+ width: 100; height: 100
+ color: chartA.color
+ }
}
MouseArea {
anchors.fill: parent
- onClicked: {
- reddy.perform()
- craig.perform()
-
- reddy.instrument = "Drums"
+ onClicked: { chartA.color = "blue" }
+ }
- reddy.perform()
- craig.perform()
- }
+ Text {
+ anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter; bottomMargin: 20 }
+ text: "Click anywhere to change the chart color"
}
}
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro b/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro
index bd05ebe..0f04167 100644
--- a/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro
+++ b/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro
@@ -1,5 +1,5 @@
QT += declarative
-HEADERS += musician.h
-SOURCES += musician.cpp \
+HEADERS += piechart.h
+SOURCES += piechart.cpp \
main.cpp
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp b/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp
index 8ef6965..a5dbab3 100644
--- a/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp
+++ b/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp
@@ -38,7 +38,7 @@
**
****************************************************************************/
//![0]
-#include "musician.h"
+#include "piechart.h"
#include <qdeclarative.h>
#include <QDeclarativeView>
#include <QApplication>
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- qmlRegisterType<Musician>("Music", 1, 0, "Musician");
+ qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("app.qml"));
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/piechart.cpp b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.cpp
new file mode 100644
index 0000000..85a9762
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.cpp
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "piechart.h"
+#include <QPainter>
+#include <QDebug>
+
+PieChart::PieChart(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+{
+ // need to disable this flag to draw inside a QDeclarativeItem
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+
+QString PieChart::name() const
+{
+ return m_name;
+}
+
+void PieChart::setName(const QString &name)
+{
+ m_name = name;
+}
+
+QColor PieChart::color() const
+{
+ return m_color;
+}
+
+//![0]
+void PieChart::setColor(const QColor &color)
+{
+ if (color != m_color) {
+ m_color = color;
+ update(); // repaint with the new color
+ emit colorChanged();
+ }
+}
+//![0]
+
+void PieChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QPen pen(m_color, 2);
+ painter->setPen(pen);
+ painter->setRenderHints(QPainter::Antialiasing, true);
+ painter->drawPie(boundingRect(), 90 * 16, 290 * 16);
+}
+
+void PieChart::clearChart()
+{
+ setColor(QColor(Qt::transparent));
+ update();
+}
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/piechart.h b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.h
new file mode 100644
index 0000000..164cebb
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef PIECHART_H
+#define PIECHART_H
+
+#include <QDeclarativeItem>
+#include <QColor>
+
+//![0]
+class PieChart : public QDeclarativeItem
+{
+//![0]
+ Q_OBJECT
+ Q_PROPERTY(QString name READ name WRITE setName)
+
+//![1]
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
+public:
+//![1]
+
+ PieChart(QDeclarativeItem *parent = 0);
+
+ QString name() const;
+ void setName(const QString &name);
+
+ QColor color() const;
+ void setColor(const QColor &color);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+ Q_INVOKABLE void clearChart();
+
+//![2]
+signals:
+ void colorChanged();
+//![2]
+
+private:
+ QString m_name;
+ QColor m_color;
+
+//![3]
+};
+//![3]
+
+#endif
+
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml
index d76f801..fcd3806 100644
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/app.qml
@@ -38,17 +38,23 @@
**
****************************************************************************/
//![0]
-import Music 1.0
+import Charts 1.0
import Qt 4.7
Item {
+ width: 300; height: 200
- Musician {
- id: reddy
- name: "Reddy the Rocker"
- instrument: Instrument { type: "Guitar" }
+ PieChart {
+ id: chart
+ anchors.centerIn: parent
+ width: 100; height: 100
+
+ pieSlice: PieSlice {
+ anchors.fill: parent
+ color: "red"
+ }
}
- Component.onCompleted: console.log("Reddy plays the " + reddy.instrument.type)
+ Component.onCompleted: console.log("The pie is colored " + chart.pieSlice.color)
}
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro
index aea07a0..c3f5402 100644
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro
@@ -1,7 +1,7 @@
QT += declarative
-HEADERS += musician.h \
- instrument.h
-SOURCES += musician.cpp \
- instrument.cpp \
+HEADERS += piechart.h \
+ pieslice.h
+SOURCES += piechart.cpp \
+ pieslice.cpp \
main.cpp
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.cpp
deleted file mode 100644
index 9ca96f6..0000000
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
-** the names of its contributors may be used to endorse or promote
-** products derived from this software without specific prior written
-** permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "instrument.h"
-
-Instrument::Instrument(QObject *parent)
- : QObject(parent)
-{
-}
-
-QString Instrument::type() const
-{
- return m_type;
-}
-
-void Instrument::setType(const QString &type)
-{
- m_type = type;
-}
-
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp
index d94cb03..fd518a2 100644
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp
@@ -37,8 +37,8 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "musician.h"
-#include "instrument.h"
+#include "piechart.h"
+#include "pieslice.h"
#include <qdeclarative.h>
#include <QDeclarativeView>
@@ -50,10 +50,10 @@ int main(int argc, char *argv[])
//![0]
QApplication app(argc, argv);
- qmlRegisterType<Musician>("Music", 1, 0, "Musician");
+ qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
//![1]
- qmlRegisterType<Instrument>("Music", 1, 0, "Instrument");
+ qmlRegisterType<PieSlice>("Charts", 1, 0, "PieSlice");
//![1]
QDeclarativeView view;
diff --git a/examples/declarative/tutorials/extending/chapter2-methods/musician.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.cpp
index 0ce0022..7098854 100644
--- a/examples/declarative/tutorials/extending/chapter2-methods/musician.cpp
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.cpp
@@ -37,38 +37,36 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "musician.h"
-#include <QDebug>
+#include "piechart.h"
+#include "pieslice.h"
-Musician::Musician(QObject *parent)
- : QObject(parent)
+PieChart::PieChart(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
{
+ // this doesn't need to disable QGraphicsItem::ItemHasNoContents
+ // anymore since the drawing is now done in PieSlice
}
-QString Musician::name() const
+QString PieChart::name() const
{
return m_name;
}
-void Musician::setName(const QString &name)
+void PieChart::setName(const QString &name)
{
m_name = name;
}
-QString Musician::instrument() const
+PieSlice *PieChart::pieSlice() const
{
- return m_instrument;
-}
-
-void Musician::setInstrument(const QString &instrument)
-{
- m_instrument = instrument;
+ return m_pieSlice;
}
//![0]
-void Musician::perform()
+void PieChart::setPieSlice(PieSlice *pieSlice)
{
- qWarning() << m_name << "is playing the" << m_instrument;
- emit performanceEnded();
+ m_pieSlice = pieSlice;
+ pieSlice->setParentItem(this);
}
//![0]
+
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h
index 8f67f61..448ca7b 100644
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.h
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h
@@ -37,18 +37,18 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef MUSICIAN_H
-#define MUSICIAN_H
+#ifndef PIECHART_H
+#define PIECHART_H
-#include <QObject>
+#include <QDeclarativeItem>
-class Instrument;
+class PieSlice;
//![0]
-class Musician : public QObject
+class PieChart : public QDeclarativeItem
{
Q_OBJECT
- Q_PROPERTY(Instrument* instrument READ instrument WRITE setInstrument)
+ Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice)
//![0]
Q_PROPERTY(QString name READ name WRITE setName)
@@ -56,19 +56,19 @@ class Musician : public QObject
public:
//![1]
- Musician(QObject *parent = 0);
+ PieChart(QDeclarativeItem *parent = 0);
QString name() const;
void setName(const QString &name);
//![2]
- Instrument *instrument() const;
- void setInstrument(Instrument *instrument);
+ PieSlice *pieSlice() const;
+ void setPieSlice(PieSlice *pieSlice);
//![2]
private:
QString m_name;
- Instrument *m_instrument;
+ PieSlice *m_pieSlice;
//![3]
};
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.cpp
new file mode 100644
index 0000000..7a420fd
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "pieslice.h"
+
+#include <QPainter>
+
+PieSlice::PieSlice(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+{
+ // need to disable this flag to draw inside a QDeclarativeItem
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+
+QColor PieSlice::color() const
+{
+ return m_color;
+}
+
+void PieSlice::setColor(const QColor &color)
+{
+ m_color = color;
+}
+
+void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QPen pen(m_color, 2);
+ painter->setPen(pen);
+ painter->setRenderHints(QPainter::Antialiasing, true);
+ painter->drawPie(boundingRect(), 90 * 16, 290 * 16);
+}
+
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.h b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h
index 9971207..085a9b8 100644
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/instrument.h
+++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h
@@ -37,25 +37,28 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef INSTRUMENT_H
-#define INSTRUMENT_H
+#ifndef PIESLICE_H
+#define PIESLICE_H
-#include <QObject>
+#include <QDeclarativeItem>
+#include <QColor>
//![0]
-class Instrument : public QObject
+class PieSlice : public QDeclarativeItem
{
Q_OBJECT
- Q_PROPERTY(QString type READ type WRITE setType)
+ Q_PROPERTY(QColor color READ color WRITE setColor)
public:
- Instrument(QObject *parent = 0);
+ PieSlice(QDeclarativeItem *parent = 0);
- QString type() const;
- void setType(const QString &type);
+ QColor color() const;
+ void setColor(const QColor &color);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
private:
- QString m_type;
+ QColor m_color;
};
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/app.qml b/examples/declarative/tutorials/extending/chapter5-listproperties/app.qml
new file mode 100644
index 0000000..f759bc9
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/app.qml
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+//![0]
+import Charts 1.0
+import Qt 4.7
+
+Item {
+ width: 300; height: 200
+
+ PieChart {
+ anchors.centerIn: parent
+ width: 100; height: 100
+
+ slices: [
+ PieSlice {
+ anchors.fill: parent
+ color: "red"
+ fromAngle: 0; angleSpan: 110
+ },
+ PieSlice {
+ anchors.fill: parent
+ color: "black"
+ fromAngle: 110; angleSpan: 50
+ },
+ PieSlice {
+ anchors.fill: parent
+ color: "blue"
+ fromAngle: 160; angleSpan: 100
+ }
+ ]
+ }
+}
+//![0]
diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro b/examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro
new file mode 100644
index 0000000..c3f5402
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro
@@ -0,0 +1,7 @@
+QT += declarative
+
+HEADERS += piechart.h \
+ pieslice.h
+SOURCES += piechart.cpp \
+ pieslice.cpp \
+ main.cpp
diff --git a/examples/declarative/tutorials/extending/chapter1-basics/musician.cpp b/examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp
index 6c42f31..f73c49f 100644
--- a/examples/declarative/tutorials/extending/chapter1-basics/musician.cpp
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp
@@ -37,30 +37,22 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "musician.h"
+#include "piechart.h"
+#include "pieslice.h"
-Musician::Musician(QObject *parent)
- : QObject(parent)
-{
-}
-
-QString Musician::name() const
-{
- return m_name;
-}
+#include <qdeclarative.h>
+#include <QDeclarativeView>
+#include <QApplication>
-void Musician::setName(const QString &name)
+int main(int argc, char *argv[])
{
- m_name = name;
-}
+ QApplication app(argc, argv);
-QString Musician::instrument() const
-{
- return m_instrument;
-}
+ qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart");
+ qmlRegisterType<PieSlice>("Charts", 1, 0, "PieSlice");
-void Musician::setInstrument(const QString &instrument)
-{
- m_instrument = instrument;
+ QDeclarativeView view;
+ view.setSource(QUrl::fromLocalFile("app.qml"));
+ view.show();
+ return app.exec();
}
-
diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/musician.cpp b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.cpp
index 5f9ead4..2515b64 100644
--- a/examples/declarative/tutorials/extending/chapter3-bindings/musician.cpp
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.cpp
@@ -37,40 +37,36 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "musician.h"
-#include <QDebug>
+#include "piechart.h"
+#include "pieslice.h"
-Musician::Musician(QObject *parent)
- : QObject(parent)
+PieChart::PieChart(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
{
}
-QString Musician::name() const
+QString PieChart::name() const
{
return m_name;
}
-void Musician::setName(const QString &name)
+void PieChart::setName(const QString &name)
{
m_name = name;
}
-QString Musician::instrument() const
+//![0]
+QDeclarativeListProperty<PieSlice> PieChart::slices()
{
- return m_instrument;
+ return QDeclarativeListProperty<PieSlice>(this, 0, &PieChart::append_slice);
}
-//![0]
-void Musician::setInstrument(const QString &instrument)
+void PieChart::append_slice(QDeclarativeListProperty<PieSlice> *list, PieSlice *slice)
{
- if (instrument != m_instrument) {
- m_instrument = instrument;
- emit instrumentChanged();
+ PieChart *chart = qobject_cast<PieChart *>(list->object);
+ if (chart) {
+ slice->setParentItem(chart);
+ chart->m_slices.append(slice);
}
}
//![0]
-
-void Musician::perform()
-{
- qWarning() << m_name << "is playing the" << m_instrument;
-}
diff --git a/examples/declarative/tutorials/extending/chapter2-methods/musician.h b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h
index 86849ba..4424251 100644
--- a/examples/declarative/tutorials/extending/chapter2-methods/musician.h
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h
@@ -37,45 +37,39 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef MUSICIAN_H
-#define MUSICIAN_H
+#ifndef PIECHART_H
+#define PIECHART_H
-#include <QObject>
+#include <QDeclarativeItem>
+
+class PieSlice;
//![0]
-class Musician : public QObject
+class PieChart : public QDeclarativeItem
{
-//![0]
Q_OBJECT
+ Q_PROPERTY(QDeclarativeListProperty<PieSlice> slices READ slices)
+//![0]
Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(QString instrument READ instrument WRITE setInstrument)
//![1]
public:
//![1]
-
- Musician(QObject *parent = 0);
+ PieChart(QDeclarativeItem *parent = 0);
QString name() const;
void setName(const QString &name);
- QString instrument() const;
- void setInstrument(const QString &instrument);
-
-//![2]
- Q_INVOKABLE void perform();
-
-signals:
- void performanceEnded();
//![2]
+ QDeclarativeListProperty<PieSlice> slices();
private:
- QString m_name;
- QString m_instrument;
+ static void append_slice(QDeclarativeListProperty<PieSlice> *list, PieSlice *slice);
-//![3]
+ QString m_name;
+ QList<PieSlice *> m_slices;
};
-//![3]
+//![2]
#endif
diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.cpp b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.cpp
new file mode 100644
index 0000000..65120f5
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "pieslice.h"
+
+#include <QPainter>
+
+PieSlice::PieSlice(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+{
+ // need to disable this flag to draw inside a QDeclarativeItem
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+
+QColor PieSlice::color() const
+{
+ return m_color;
+}
+
+void PieSlice::setColor(const QColor &color)
+{
+ m_color = color;
+}
+
+int PieSlice::fromAngle() const
+{
+ return m_fromAngle;
+}
+
+void PieSlice::setFromAngle(int angle)
+{
+ m_fromAngle = angle;
+}
+
+int PieSlice::angleSpan() const
+{
+ return m_angleSpan;
+}
+
+void PieSlice::setAngleSpan(int angle)
+{
+ m_angleSpan = angle;
+}
+
+void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QPen pen(m_color, 2);
+ painter->setPen(pen);
+ painter->setRenderHints(QPainter::Antialiasing, true);
+ painter->drawPie(boundingRect(), m_fromAngle * 16, m_angleSpan * 16);
+}
+
diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h
new file mode 100644
index 0000000..7cd0c74
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef PIESLICE_H
+#define PIESLICE_H
+
+#include <QDeclarativeItem>
+#include <QColor>
+
+//![0]
+class PieSlice : public QDeclarativeItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QColor color READ color WRITE setColor)
+ Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle)
+ Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan)
+//![0]
+
+public:
+ PieSlice(QDeclarativeItem *parent = 0);
+
+ QColor color() const;
+ void setColor(const QColor &color);
+
+ int fromAngle() const;
+ void setFromAngle(int angle);
+
+ int angleSpan() const;
+ void setAngleSpan(int span);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+private:
+ QColor m_color;
+ int m_fromAngle;
+ int m_angleSpan;
+};
+
+#endif
+
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp
deleted file mode 100644
index 9ca96f6..0000000
--- a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
-** the names of its contributors may be used to endorse or promote
-** products derived from this software without specific prior written
-** permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "instrument.h"
-
-Instrument::Instrument(QObject *parent)
- : QObject(parent)
-{
-}
-
-QString Instrument::type() const
-{
- return m_type;
-}
-
-void Instrument::setType(const QString &type)
-{
- m_type = type;
-}
-
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.h b/examples/declarative/tutorials/extending/chapter5-plugins/instrument.h
deleted file mode 100644
index ce1e7ce..0000000
--- a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
-** the names of its contributors may be used to endorse or promote
-** products derived from this software without specific prior written
-** permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef INSTRUMENT_H
-#define INSTRUMENT_H
-
-#include <QObject>
-
-class Instrument : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QString type READ type WRITE setType)
-
-public:
- Instrument(QObject *parent = 0);
-
- QString type() const;
- void setType(const QString &type);
-
-private:
- QString m_type;
-};
-
-#endif
-
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp
deleted file mode 100644
index e62efb1..0000000
--- a/examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
-** the names of its contributors may be used to endorse or promote
-** products derived from this software without specific prior written
-** permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include "musician.h"
-#include "instrument.h"
-
-Musician::Musician(QObject *parent)
- : QObject(parent)
-{
-}
-
-QString Musician::name() const
-{
- return m_name;
-}
-
-void Musician::setName(const QString &name)
-{
- m_name = name;
-}
-
-Instrument *Musician::instrument() const
-{
- return m_instrument;
-}
-
-void Musician::setInstrument(Instrument *instrument)
-{
- m_instrument = instrument;
-}
-
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/qmldir b/examples/declarative/tutorials/extending/chapter5-plugins/qmldir
deleted file mode 100644
index c3afd6b..0000000
--- a/examples/declarative/tutorials/extending/chapter5-plugins/qmldir
+++ /dev/null
@@ -1 +0,0 @@
-plugin chapter5-plugins lib
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/app.qml b/examples/declarative/tutorials/extending/chapter6-plugins/app.qml
index 9c050b8..38ceefa 100644
--- a/examples/declarative/tutorials/extending/chapter5-plugins/app.qml
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/app.qml
@@ -37,17 +37,32 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-
import Qt 4.7
Item {
+ width: 300; height: 200
- Musician {
- id: reddy
- name: "Reddy the Rocker"
- instrument: Instrument { type: "Guitar" }
- }
+ PieChart {
+ anchors.centerIn: parent
+ width: 100; height: 100
- Component.onCompleted: console.log("Reddy plays the " + reddy.instrument.type)
+ slices: [
+ PieSlice {
+ anchors.fill: parent
+ color: "red"
+ fromAngle: 0; angleSpan: 110
+ },
+ PieSlice {
+ anchors.fill: parent
+ color: "black"
+ fromAngle: 110; angleSpan: 50
+ },
+ PieSlice {
+ anchors.fill: parent
+ color: "blue"
+ fromAngle: 160; angleSpan: 100
+ }
+ ]
+ }
}
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro b/examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro
index 483da8f..1ffbf29 100644
--- a/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro
@@ -6,13 +6,13 @@ DESTDIR = lib
OBJECTS_DIR = tmp
MOC_DIR = tmp
-HEADERS += musician.h \
- instrument.h \
- musicplugin.h
+HEADERS += piechart.h \
+ pieslice.h \
+ chartsplugin.h
-SOURCES += musician.cpp \
- instrument.cpp \
- musicplugin.cpp
+SOURCES += piechart.cpp \
+ pieslice.cpp \
+ chartsplugin.cpp
symbian {
include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.cpp b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp
index 76acf01..5aa2a4b 100644
--- a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.cpp
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.cpp
@@ -37,18 +37,18 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "musicplugin.h"
+#include "chartsplugin.h"
//![0]
-#include "musician.h"
-#include "instrument.h"
+#include "piechart.h"
+#include "pieslice.h"
#include <QtDeclarative/qdeclarative.h>
-void MusicPlugin::registerTypes(const char *uri)
+void ChartsPlugin::registerTypes(const char *uri)
{
- qmlRegisterType<Musician>(uri, 1, 0, "Musician");
- qmlRegisterType<Instrument>(uri, 1, 0, "Instrument");
+ qmlRegisterType<PieChart>(uri, 1, 0, "PieChart");
+ qmlRegisterType<PieSlice>(uri, 1, 0, "PieSlice");
}
-Q_EXPORT_PLUGIN2(musicplugin, MusicPlugin);
+Q_EXPORT_PLUGIN2(chartsplugin, ChartsPlugin);
//![0]
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.h b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.h
index d6a5392..797d1e7 100644
--- a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.h
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/chartsplugin.h
@@ -37,13 +37,13 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef MUSICPLUGIN_H
-#define MUSICPLUGIN_H
+#ifndef CHARTSPLUGIN_H
+#define CHARTSPLUGIN_H
//![0]
#include <QtDeclarative/QDeclarativeExtensionPlugin>
-class MusicPlugin : public QDeclarativeExtensionPlugin
+class ChartsPlugin : public QDeclarativeExtensionPlugin
{
Q_OBJECT
public:
diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.cpp b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.cpp
index e62efb1..4e6ee5c 100644
--- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/musician.cpp
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.cpp
@@ -37,31 +37,35 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "musician.h"
-#include "instrument.h"
+#include "piechart.h"
+#include "pieslice.h"
-Musician::Musician(QObject *parent)
- : QObject(parent)
+PieChart::PieChart(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
{
}
-QString Musician::name() const
+QString PieChart::name() const
{
return m_name;
}
-void Musician::setName(const QString &name)
+void PieChart::setName(const QString &name)
{
m_name = name;
}
-Instrument *Musician::instrument() const
+QDeclarativeListProperty<PieSlice> PieChart::slices()
{
- return m_instrument;
+ return QDeclarativeListProperty<PieSlice>(this, 0, &PieChart::append_slice);
}
-void Musician::setInstrument(Instrument *instrument)
+void PieChart::append_slice(QDeclarativeListProperty<PieSlice> *list, PieSlice *slice)
{
- m_instrument = instrument;
+ PieChart *chart = qobject_cast<PieChart *>(list->object);
+ if (chart) {
+ slice->setParentItem(chart);
+ chart->m_slices.append(slice);
+ }
}
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/musician.h b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.h
index b920631..d6e4439 100644
--- a/examples/declarative/tutorials/extending/chapter5-plugins/musician.h
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.h
@@ -37,31 +37,32 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef MUSICIAN_H
-#define MUSICIAN_H
+#ifndef PIECHART_H
+#define PIECHART_H
-#include <QObject>
+#include <QDeclarativeItem>
-class Instrument;
+class PieSlice;
-class Musician : public QObject
+class PieChart : public QDeclarativeItem
{
Q_OBJECT
+ Q_PROPERTY(QDeclarativeListProperty<PieSlice> slices READ slices)
Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(Instrument* instrument READ instrument WRITE setInstrument)
public:
- Musician(QObject *parent = 0);
+ PieChart(QDeclarativeItem *parent = 0);
QString name() const;
void setName(const QString &name);
- Instrument *instrument() const;
- void setInstrument(Instrument *instrument);
+ QDeclarativeListProperty<PieSlice> slices();
private:
+ static void append_slice(QDeclarativeListProperty<PieSlice> *list, PieSlice *slice);
+
QString m_name;
- Instrument *m_instrument;
+ QList<PieSlice *> m_slices;
};
#endif
diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp
new file mode 100644
index 0000000..65120f5
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "pieslice.h"
+
+#include <QPainter>
+
+PieSlice::PieSlice(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+{
+ // need to disable this flag to draw inside a QDeclarativeItem
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+}
+
+QColor PieSlice::color() const
+{
+ return m_color;
+}
+
+void PieSlice::setColor(const QColor &color)
+{
+ m_color = color;
+}
+
+int PieSlice::fromAngle() const
+{
+ return m_fromAngle;
+}
+
+void PieSlice::setFromAngle(int angle)
+{
+ m_fromAngle = angle;
+}
+
+int PieSlice::angleSpan() const
+{
+ return m_angleSpan;
+}
+
+void PieSlice::setAngleSpan(int angle)
+{
+ m_angleSpan = angle;
+}
+
+void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QPen pen(m_color, 2);
+ painter->setPen(pen);
+ painter->setRenderHints(QPainter::Antialiasing, true);
+ painter->drawPie(boundingRect(), m_fromAngle * 16, m_angleSpan * 16);
+}
+
diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h
new file mode 100644
index 0000000..a3afd25
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef PIESLICE_H
+#define PIESLICE_H
+
+#include <QDeclarativeItem>
+#include <QColor>
+
+class PieSlice : public QDeclarativeItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QColor color READ color WRITE setColor)
+ Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle)
+ Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan)
+
+public:
+ PieSlice(QDeclarativeItem *parent = 0);
+
+ QColor color() const;
+ void setColor(const QColor &color);
+
+ int fromAngle() const;
+ void setFromAngle(int angle);
+
+ int angleSpan() const;
+ void setAngleSpan(int span);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+private:
+ QColor m_color;
+ int m_fromAngle;
+ int m_angleSpan;
+};
+
+#endif
+
diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/qmldir b/examples/declarative/tutorials/extending/chapter6-plugins/qmldir
new file mode 100644
index 0000000..a83bf85
--- /dev/null
+++ b/examples/declarative/tutorials/extending/chapter6-plugins/qmldir
@@ -0,0 +1 @@
+plugin chapter6-plugins lib
diff --git a/examples/declarative/tutorials/extending/extending.pro b/examples/declarative/tutorials/extending/extending.pro
index 0c86fed..967473f 100644
--- a/examples/declarative/tutorials/extending/extending.pro
+++ b/examples/declarative/tutorials/extending/extending.pro
@@ -5,5 +5,6 @@ SUBDIRS += \
chapter2-methods \
chapter3-bindings \
chapter4-customPropertyTypes \
- chapter5-plugins
+ chapter5-listproperties \
+ chapter6-plugins
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml
index 1f51e13..92c607f 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml
+++ b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml
@@ -49,11 +49,14 @@ Item {
//![1]
property bool spawned: false
- property int targetX: 0
- property int targetY: 0
- SpringFollow on x { to: targetX; spring: 2; damping: 0.2; enabled: spawned }
- SpringFollow on y { to: targetY; spring: 2; damping: 0.2 }
+ Behavior on x {
+ enabled: spawned;
+ SpringAnimation{ spring: 2; damping: 0.2 }
+ }
+ Behavior on y {
+ SpringAnimation{ spring: 2; damping: 0.2 }
+ }
//![1]
//![2]
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js
index 930a3d8..b1f427c 100755
--- a/examples/declarative/tutorials/samegame/samegame4/content/samegame.js
+++ b/examples/declarative/tutorials/samegame/samegame4/content/samegame.js
@@ -57,8 +57,7 @@ function createBlock(column, row) {
}
dynamicObject.type = Math.floor(Math.random() * 3);
dynamicObject.x = column * gameCanvas.blockSize;
- dynamicObject.targetX = column * gameCanvas.blockSize;
- dynamicObject.targetY = row * gameCanvas.blockSize;
+ dynamicObject.y = row * gameCanvas.blockSize;
dynamicObject.width = gameCanvas.blockSize;
dynamicObject.height = gameCanvas.blockSize;
dynamicObject.spawned = true;
@@ -128,7 +127,7 @@ function shuffleDown() {
} else {
if (fallDist > 0) {
var obj = board[index(column, row)];
- obj.targetY += fallDist * gameCanvas.blockSize;
+ obj.y += fallDist * gameCanvas.blockSize;
board[index(column, row + fallDist)] = obj;
board[index(column, row)] = null;
}
@@ -146,7 +145,7 @@ function shuffleDown() {
obj = board[index(column, row)];
if (obj == null)
continue;
- obj.targetX -= fallDist * gameCanvas.blockSize;
+ obj.x -= fallDist * gameCanvas.blockSize;
board[index(column - fallDist, row)] = obj;
board[index(column, row)] = null;
}
diff --git a/examples/declarative/ui-components/dialcontrol/content/Dial.qml b/examples/declarative/ui-components/dialcontrol/content/Dial.qml
index 2b421bf..b5074a64 100644
--- a/examples/declarative/ui-components/dialcontrol/content/Dial.qml
+++ b/examples/declarative/ui-components/dialcontrol/content/Dial.qml
@@ -50,11 +50,11 @@ Item {
//! [needle_shadow]
Image {
- x: 93
+ x: 96
y: 35
source: "needle_shadow.png"
transform: Rotation {
- origin.x: 11; origin.y: 67
+ origin.x: 9; origin.y: 67
angle: needleRotation.angle
}
}
@@ -62,17 +62,18 @@ Item {
//! [needle]
Image {
id: needle
- x: 95; y: 33
+ x: 98; y: 33
smooth: true
source: "needle.png"
transform: Rotation {
id: needleRotation
- origin.x: 7; origin.y: 65
- angle: -130
- SpringFollow on angle {
- spring: 1.4
- damping: .15
- to: Math.min(Math.max(-130, root.value*2.6 - 130), 133)
+ origin.x: 5; origin.y: 65
+ angle: Math.min(Math.max(-130, root.value*2.6 - 130), 133)
+ Behavior on angle {
+ SpringAnimation {
+ spring: 1.4
+ damping: .15
+ }
}
}
}
diff --git a/examples/declarative/ui-components/tabwidget/TabWidget.qml b/examples/declarative/ui-components/tabwidget/TabWidget.qml
index 9642e04..ce57213 100644
--- a/examples/declarative/ui-components/tabwidget/TabWidget.qml
+++ b/examples/declarative/ui-components/tabwidget/TabWidget.qml
@@ -43,9 +43,14 @@ import Qt 4.7
Item {
id: tabWidget
- property int current: 0
+ // Setting the default property to stack.children means any child items
+ // of the TabWidget are actually added to the 'stack' item's children.
+ // See the "Extending Types from QML" documentation for details on default
+ // properties.
default property alias content: stack.children
+ property int current: 0
+
onCurrentChanged: setOpacities()
Component.onCompleted: setOpacities()
diff --git a/examples/network/bearermonitor/sessionwidget.h b/examples/network/bearermonitor/sessionwidget.h
index 5b5827b..c92db44 100644
--- a/examples/network/bearermonitor/sessionwidget.h
+++ b/examples/network/bearermonitor/sessionwidget.h
@@ -41,12 +41,12 @@
#ifndef SESSIONWIDGET_H
#define SESSIONWIDGET_H
+#include <qnetworksession.h>
#if defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
#include "ui_sessionwidget_maemo.h"
#else
#include "ui_sessionwidget.h"
#endif
-#include <qnetworksession.h>
QT_USE_NAMESPACE
diff --git a/examples/network/bearermonitor/sessionwidget_maemo.ui b/examples/network/bearermonitor/sessionwidget_maemo.ui
index ca68246..8867509 100644
--- a/examples/network/bearermonitor/sessionwidget_maemo.ui
+++ b/examples/network/bearermonitor/sessionwidget_maemo.ui
@@ -214,6 +214,54 @@
</item>
</layout>
</item>
+ <item>
+ <layout class="QHBoxLayout" name="errorStringLayout_2">
+ <item>
+ <widget class="QLabel" name="rxData">
+ <property name="text">
+ <string>0</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="txData">
+ <property name="text">
+ <string>0</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="errorStringLayout_3">
+ <item>
+ <widget class="QLabel" name="errorStringLabel_2">
+ <property name="text">
+ <string>Active Time:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="activeTime">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>0 seconds</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
</layout>
</item>
<item>