diff options
author | David Boddie <dboddie@trolltech.com> | 2010-07-16 15:46:21 (GMT) |
---|---|---|
committer | David Boddie <dboddie@trolltech.com> | 2010-07-16 15:46:21 (GMT) |
commit | 6b1b666574d6e27efdd3b243de8815a5278c3666 (patch) | |
tree | 7a5ac02fe569b3fc497ca8d0a333d10587eb3567 /examples/declarative/tutorials/extending/chapter1-basics | |
parent | eef1d13743baddf41bd135d98fc2ad12944b8477 (diff) | |
parent | ab4dde176cfa314522964e5e5fbf9f2d388f8fdf (diff) | |
download | Qt-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/declarative/tutorials/extending/chapter1-basics')
-rw-r--r-- | examples/declarative/tutorials/extending/chapter1-basics/app.qml | 18 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro | 4 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter1-basics/main.cpp | 4 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp (renamed from examples/declarative/tutorials/extending/chapter1-basics/musician.cpp) | 33 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter1-basics/piechart.h (renamed from examples/declarative/tutorials/extending/chapter1-basics/musician.h) | 21 |
5 files changed, 50 insertions, 30 deletions
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/musician.cpp b/examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp index 6c42f31..3b9ef71 100644 --- a/examples/declarative/tutorials/extending/chapter1-basics/musician.cpp +++ b/examples/declarative/tutorials/extending/chapter1-basics/piechart.cpp @@ -37,30 +37,45 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "musician.h" +#include "piechart.h" +#include <QPainter> -Musician::Musician(QObject *parent) - : QObject(parent) +//![0] +PieChart::PieChart(QDeclarativeItem *parent) + : QDeclarativeItem(parent) { + // need to disable this flag to draw inside a QDeclarativeItem + setFlag(QGraphicsItem::ItemHasNoContents, false); } +//![0] -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 +QColor PieChart::color() const { - return m_instrument; + return m_color; } -void Musician::setInstrument(const QString &instrument) +void PieChart::setColor(const QColor &color) { - m_instrument = instrument; + 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] |