diff options
Diffstat (limited to 'examples/declarative/tutorials/extending/chapter5-plugins')
-rw-r--r-- | examples/declarative/tutorials/extending/chapter5-plugins/app.qml | 16 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro | 12 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.cpp (renamed from examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.cpp) | 14 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter5-plugins/chartsplugin.h (renamed from examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.h) | 6 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp (renamed from examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp) | 21 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter5-plugins/piechart.h (renamed from examples/declarative/tutorials/extending/chapter5-plugins/musician.h) | 20 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp (renamed from examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp) | 25 | ||||
-rw-r--r-- | examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h (renamed from examples/declarative/tutorials/extending/chapter5-plugins/instrument.h) | 21 |
8 files changed, 78 insertions, 57 deletions
diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/app.qml b/examples/declarative/tutorials/extending/chapter5-plugins/app.qml index 9c050b8..b06e399 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/app.qml +++ b/examples/declarative/tutorials/extending/chapter5-plugins/app.qml @@ -41,13 +41,19 @@ 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) } diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro b/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro index 483da8f..1ffbf29 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-plugins.pro +++ b/examples/declarative/tutorials/extending/chapter5-plugins/chapter5-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/chapter5-plugins/chartsplugin.cpp index 76acf01..5aa2a4b 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.cpp +++ b/examples/declarative/tutorials/extending/chapter5-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/chapter5-plugins/chartsplugin.h index d6a5392..797d1e7 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/musicplugin.h +++ b/examples/declarative/tutorials/extending/chapter5-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/chapter5-plugins/musician.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp index e62efb1..2d7acf7 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/musician.cpp +++ b/examples/declarative/tutorials/extending/chapter5-plugins/piechart.cpp @@ -37,31 +37,32 @@ ** $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 +PieSlice *PieChart::pieSlice() const { - return m_instrument; + return m_pieSlice; } -void Musician::setInstrument(Instrument *instrument) +void PieChart::setPieSlice(PieSlice *pieSlice) { - m_instrument = instrument; + m_pieSlice = pieSlice; + m_pieSlice->setParentItem(this); } diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/musician.h b/examples/declarative/tutorials/extending/chapter5-plugins/piechart.h index b920631..a8b5b6e 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/musician.h +++ b/examples/declarative/tutorials/extending/chapter5-plugins/piechart.h @@ -37,31 +37,31 @@ ** $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(QString name READ name WRITE setName) - Q_PROPERTY(Instrument* instrument READ instrument WRITE setInstrument) + Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice) public: - Musician(QObject *parent = 0); + PieChart(QDeclarativeItem *parent = 0); QString name() const; void setName(const QString &name); - Instrument *instrument() const; - void setInstrument(Instrument *instrument); + PieSlice *pieSlice() const; + void setPieSlice(PieSlice *pieSlice); private: QString m_name; - Instrument *m_instrument; + PieSlice *m_pieSlice; }; #endif diff --git a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp b/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp index 9ca96f6..a312da3 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.cpp +++ b/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.cpp @@ -37,20 +37,31 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "instrument.h" +#include "pieslice.h" -Instrument::Instrument(QObject *parent) - : QObject(parent) +#include <QPainter> + +PieSlice::PieSlice(QDeclarativeItem *parent) + : QDeclarativeItem(parent) { + // need to disable this flag to draw inside a QDeclarativeItem + setFlag(QGraphicsItem::ItemHasNoContents, false); } -QString Instrument::type() const +QColor PieSlice::color() const { - return m_type; + return m_color; } -void Instrument::setType(const QString &type) +void PieSlice::setColor(const QColor &color) { - m_type = type; + 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/chapter5-plugins/instrument.h b/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h index ce1e7ce..6774731 100644 --- a/examples/declarative/tutorials/extending/chapter5-plugins/instrument.h +++ b/examples/declarative/tutorials/extending/chapter5-plugins/pieslice.h @@ -37,24 +37,27 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#ifndef INSTRUMENT_H -#define INSTRUMENT_H +#ifndef PIESLICE_H +#define PIESLICE_H -#include <QObject> +#include <QDeclarativeItem> +#include <QColor> -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 &QColor); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); private: - QString m_type; + QColor m_color; }; #endif |