@@ -0,0 +1,7 | |||||
|
1 | TEMPLATE = subdirs | |||
|
2 | SUBDIRS += widget qmlplugin | |||
|
3 | ||||
|
4 | # install feature file | |||
|
5 | feature.path = $$[QT_INSTALL_DATA]/mkspecs/features | |||
|
6 | feature.files = $$PWD/features/charts.prf | |||
|
7 | INSTALLS += feature |
@@ -0,0 +1,5 | |||||
|
1 | INCLUDEPATH += $$[QT_INSTALL_HEADERS]/Charts | |||
|
2 | ||||
|
3 | contains(CHARTS, widget) { | |||
|
4 | LIBS += -lChartWidget | |||
|
5 | } |
@@ -0,0 +1,27 | |||||
|
1 | #include "declarativechart.h" | |||
|
2 | #include <QPainter> | |||
|
3 | ||||
|
4 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) | |||
|
5 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |||
|
6 | : QDeclarativeItem(parent) | |||
|
7 | { | |||
|
8 | // need to disable this flag to draw inside a QDeclarativeItem | |||
|
9 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |||
|
10 | } | |||
|
11 | #else | |||
|
12 | DeclarativeChart::DeclarativeChart(QQuickItem *parent) | |||
|
13 | : QQuickPaintedItem(parent) | |||
|
14 | { | |||
|
15 | ||||
|
16 | } | |||
|
17 | #endif | |||
|
18 | ||||
|
19 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) | |||
|
20 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) | |||
|
21 | #else | |||
|
22 | void DeclarativeChart::paint(QPainter *painter) | |||
|
23 | #endif | |||
|
24 | { | |||
|
25 | drawChart(painter, boundingRect()); | |||
|
26 | } | |||
|
27 |
@@ -0,0 +1,37 | |||||
|
1 | #ifndef DECLARATIVECHART_H | |||
|
2 | #define DECLARATIVECHART_H | |||
|
3 | ||||
|
4 | #include <QtCore/QtGlobal> | |||
|
5 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) | |||
|
6 | #include <QDeclarativeItem> | |||
|
7 | #else | |||
|
8 | #include <QtQuick/QQuickPaintedItem> | |||
|
9 | #endif | |||
|
10 | #include <QColor> | |||
|
11 | #include "../src/chart.h" | |||
|
12 | ||||
|
13 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) | |||
|
14 | class DeclarativeChart : public QDeclarativeItem, public Chart | |||
|
15 | #else | |||
|
16 | class DeclarativeChart : public QQuickPaintedItem, public Chart | |||
|
17 | #endif | |||
|
18 | { | |||
|
19 | Q_OBJECT | |||
|
20 | Q_PROPERTY(QColor color READ color WRITE setColor) | |||
|
21 | ||||
|
22 | public: | |||
|
23 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) | |||
|
24 | DeclarativeChart(QDeclarativeItem *parent = 0); | |||
|
25 | #else | |||
|
26 | DeclarativeChart(QQuickItem *parent = 0); | |||
|
27 | #endif | |||
|
28 | ||||
|
29 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) | |||
|
30 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |||
|
31 | #else | |||
|
32 | void paint(QPainter *painter); | |||
|
33 | #endif | |||
|
34 | }; | |||
|
35 | ||||
|
36 | ||||
|
37 | #endif // DECLARATIVECHART_H |
@@ -0,0 +1,22 | |||||
|
1 | #include <QtDeclarative/qdeclarativeextensionplugin.h> | |||
|
2 | #include <QtDeclarative/qdeclarative.h> | |||
|
3 | #include "declarativechart.h" | |||
|
4 | ||||
|
5 | QT_BEGIN_NAMESPACE | |||
|
6 | ||||
|
7 | class QmlChartPlugin : public QDeclarativeExtensionPlugin | |||
|
8 | { | |||
|
9 | Q_OBJECT | |||
|
10 | public: | |||
|
11 | virtual void registerTypes(const char *uri) | |||
|
12 | { | |||
|
13 | Q_ASSERT(QLatin1String(uri) == QLatin1String("com.digia.charts")); | |||
|
14 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "Chart"); | |||
|
15 | } | |||
|
16 | }; | |||
|
17 | ||||
|
18 | QT_END_NAMESPACE | |||
|
19 | ||||
|
20 | #include "plugin.moc" | |||
|
21 | ||||
|
22 | Q_EXPORT_PLUGIN2(qmlchartplugin, QT_PREPEND_NAMESPACE(QmlChartPlugin)); |
@@ -0,0 +1,29 | |||||
|
1 | import QtQuick 2.0 | |||
|
2 | ||||
|
3 | Canvas { | |||
|
4 | id: canvas | |||
|
5 | width: 200 | |||
|
6 | height: 200 | |||
|
7 | smooth:true | |||
|
8 | renderTarget:Canvas.Image | |||
|
9 | renderInThread:false | |||
|
10 | ||||
|
11 | onWidthChanged: requestPaint() | |||
|
12 | onHeightChanged: requestPaint() | |||
|
13 | ||||
|
14 | onPaint: { | |||
|
15 | var ctx = canvas.getContext('2d') | |||
|
16 | ctx.reset() | |||
|
17 | ctx.clearRect(0, 0, canvas.width, canvas.height) | |||
|
18 | ctx.strokeStyle = "red" | |||
|
19 | ctx.lineWidth = 1 | |||
|
20 | ctx.moveTo(10, 10) | |||
|
21 | ctx.lineTo(10, canvas.height-10) | |||
|
22 | ctx.lineTo(canvas.width-10, canvas.height-10) | |||
|
23 | ctx.text("Axis x", canvas.width / 2, canvas.height) | |||
|
24 | ctx.text("Insert chart here", canvas.width / 2, canvas.height / 2) | |||
|
25 | ctx.stroke(); | |||
|
26 | } | |||
|
27 | } | |||
|
28 | ||||
|
29 |
@@ -0,0 +1,16 | |||||
|
1 | import QmlProject 1.0 | |||
|
2 | ||||
|
3 | Project { | |||
|
4 | /* Include .qml, .js, and image files from current directory and subdirectories */ | |||
|
5 | QmlFiles { | |||
|
6 | directory: "." | |||
|
7 | } | |||
|
8 | JavaScriptFiles { | |||
|
9 | directory: "." | |||
|
10 | } | |||
|
11 | ImageFiles { | |||
|
12 | directory: "." | |||
|
13 | } | |||
|
14 | /* List of plugin directories passed to QML runtime */ | |||
|
15 | // importPaths: [ " ../exampleplugin " ] | |||
|
16 | } |
@@ -0,0 +1,1 | |||||
|
1 | plugin qmlchartplugin |
@@ -0,0 +1,26 | |||||
|
1 | TEMPLATE = lib | |||
|
2 | TARGET = qmlchartplugin | |||
|
3 | ||||
|
4 | CONFIG += qt plugin | |||
|
5 | QT += declarative | |||
|
6 | ||||
|
7 | OBJECTS_DIR = tmp | |||
|
8 | MOC_DIR = tmp | |||
|
9 | ||||
|
10 | SOURCES += \ | |||
|
11 | plugin.cpp \ | |||
|
12 | declarativechart.cpp | |||
|
13 | HEADERS += \ | |||
|
14 | declarativechart.h | |||
|
15 | include(../src/chart.pri) | |||
|
16 | ||||
|
17 | TARGETPATH = com/digia/charts | |||
|
18 | ||||
|
19 | #DESTDIR = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH | |||
|
20 | target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH | |||
|
21 | ||||
|
22 | qmldir.files += $$PWD/qmldir | |||
|
23 | qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH | |||
|
24 | ||||
|
25 | INSTALLS += target qmldir | |||
|
26 |
@@ -0,0 +1,46 | |||||
|
1 | #include "chart.h" | |||
|
2 | ||||
|
3 | Chart::Chart() | |||
|
4 | { | |||
|
5 | ||||
|
6 | } | |||
|
7 | ||||
|
8 | Chart::~Chart() | |||
|
9 | { | |||
|
10 | ||||
|
11 | } | |||
|
12 | ||||
|
13 | QColor Chart::color() const | |||
|
14 | { | |||
|
15 | return m_color; | |||
|
16 | } | |||
|
17 | ||||
|
18 | void Chart::setColor(const QColor &color) | |||
|
19 | { | |||
|
20 | m_color = color; | |||
|
21 | } | |||
|
22 | ||||
|
23 | void Chart::drawChart(QPainter *painter, const QRectF& drawRect) | |||
|
24 | { | |||
|
25 | QRectF r = drawRect; | |||
|
26 | r.adjust(10, 10, -10, -10); | |||
|
27 | ||||
|
28 | QPen pen(m_color, 2); | |||
|
29 | pen.setCapStyle(Qt::RoundCap); | |||
|
30 | painter->setPen(pen); | |||
|
31 | painter->setRenderHints(QPainter::Antialiasing, true); | |||
|
32 | painter->drawLine(r.topLeft(), r.bottomLeft()); | |||
|
33 | painter->drawLine(r.bottomLeft(), r.bottomRight()); | |||
|
34 | ||||
|
35 | painter->drawText(drawRect, "Axis x", QTextOption(Qt::AlignBottom | Qt::AlignHCenter)); | |||
|
36 | QTransform transform; | |||
|
37 | transform.translate(drawRect.width(), 0); // works badly if drawrect width != height :) | |||
|
38 | transform.rotate(90); | |||
|
39 | painter->setTransform(transform); | |||
|
40 | painter->drawText(drawRect, "Axis y", QTextOption(Qt::AlignBottom | Qt::AlignHCenter)); | |||
|
41 | painter->resetTransform(); | |||
|
42 | ||||
|
43 | painter->drawText(drawRect, QT_VERSION_STR, QTextOption(Qt::AlignTop | Qt::AlignRight)); | |||
|
44 | painter->drawText(drawRect, "Insert chart here", QTextOption(Qt::AlignCenter)); | |||
|
45 | ||||
|
46 | } |
@@ -0,0 +1,24 | |||||
|
1 | #ifndef CHART_H | |||
|
2 | #define CHART_H | |||
|
3 | #include <QColor> | |||
|
4 | #include <QPainter> | |||
|
5 | #include <QRect> | |||
|
6 | ||||
|
7 | class QPainter; | |||
|
8 | ||||
|
9 | class Chart | |||
|
10 | { | |||
|
11 | public: | |||
|
12 | Chart(); | |||
|
13 | virtual ~Chart(); | |||
|
14 | ||||
|
15 | QColor color() const; | |||
|
16 | void setColor(const QColor &color); | |||
|
17 | ||||
|
18 | void drawChart(QPainter *painter, const QRectF& drawRect); | |||
|
19 | ||||
|
20 | private: | |||
|
21 | QColor m_color; | |||
|
22 | }; | |||
|
23 | ||||
|
24 | #endif |
@@ -0,0 +1,16 | |||||
|
1 | TARGET = chartwidgettest | |||
|
2 | TEMPLATE = app | |||
|
3 | ||||
|
4 | QT += core gui | |||
|
5 | contains(QT_MAJOR_VERSION, 5) { | |||
|
6 | QT += widgets | |||
|
7 | } | |||
|
8 | ||||
|
9 | CONFIG += charts | |||
|
10 | CHARTS += widget | |||
|
11 | ||||
|
12 | OBJECTS_DIR = tmp | |||
|
13 | MOC_DIR = tmp | |||
|
14 | ||||
|
15 | SOURCES += main.cpp | |||
|
16 |
@@ -0,0 +1,19 | |||||
|
1 | #include <QtCore/QtGlobal> | |||
|
2 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) | |||
|
3 | #include <QApplication> | |||
|
4 | #else | |||
|
5 | #include <QtWidgets/QApplication> | |||
|
6 | #endif | |||
|
7 | #include <chartwidget.h> | |||
|
8 | ||||
|
9 | int main(int argc, char *argv[]) | |||
|
10 | { | |||
|
11 | QApplication a(argc, argv); | |||
|
12 | ||||
|
13 | ChartWidget w; | |||
|
14 | w.resize(QSize(200,200)); | |||
|
15 | w.setColor(Qt::red); | |||
|
16 | w.show(); | |||
|
17 | ||||
|
18 | return a.exec(); | |||
|
19 | } |
@@ -0,0 +1,11 | |||||
|
1 | //import QtQuick 1.1 | |||
|
2 | import QtQuick 2.0 | |||
|
3 | import com.digia.charts 1.0 | |||
|
4 | ||||
|
5 | Chart { | |||
|
6 | width: 200 | |||
|
7 | height: 200 | |||
|
8 | color: "red" | |||
|
9 | } | |||
|
10 | ||||
|
11 |
@@ -0,0 +1,38 | |||||
|
1 | #include "chartwidget.h" | |||
|
2 | #include "../src/chart.h" | |||
|
3 | #include <QPainter> | |||
|
4 | ||||
|
5 | class ChartWidgetPrivate : public Chart | |||
|
6 | { | |||
|
7 | public: | |||
|
8 | //Q_DECLARE_PUBLIC(ChartWidget) | |||
|
9 | ChartWidgetPrivate() {} | |||
|
10 | }; | |||
|
11 | ||||
|
12 | ChartWidget::ChartWidget(QWidget *parent) | |||
|
13 | : QWidget(parent) | |||
|
14 | { | |||
|
15 | d_ptr = new ChartWidgetPrivate(); | |||
|
16 | } | |||
|
17 | ||||
|
18 | ChartWidget::~ChartWidget() | |||
|
19 | { | |||
|
20 | delete d_ptr; | |||
|
21 | d_ptr = 0; | |||
|
22 | } | |||
|
23 | ||||
|
24 | QColor ChartWidget::color() const | |||
|
25 | { | |||
|
26 | return d_ptr->color(); | |||
|
27 | } | |||
|
28 | ||||
|
29 | void ChartWidget::setColor(const QColor &color) | |||
|
30 | { | |||
|
31 | d_ptr->setColor(color); | |||
|
32 | } | |||
|
33 | ||||
|
34 | void ChartWidget::paintEvent(QPaintEvent *) | |||
|
35 | { | |||
|
36 | QPainter painter(this); | |||
|
37 | d_ptr->drawChart(&painter, rect()); | |||
|
38 | } |
@@ -0,0 +1,40 | |||||
|
1 | #ifndef CHARTWIDGET_H | |||
|
2 | #define CHARTWIDGET_H | |||
|
3 | ||||
|
4 | #include <QtCore/QtGlobal> | |||
|
5 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) | |||
|
6 | #include <QWidget> | |||
|
7 | #else | |||
|
8 | #include <QtWidgets/QWidget> | |||
|
9 | #endif | |||
|
10 | ||||
|
11 | #if defined(CHARTWIDGET_LIBRARY) | |||
|
12 | # define CHARTWIDGET_EXPORT Q_DECL_EXPORT | |||
|
13 | #else | |||
|
14 | # define CHARTWIDGET_EXPORT Q_DECL_IMPORT | |||
|
15 | #endif | |||
|
16 | ||||
|
17 | class ChartWidgetPrivate; | |||
|
18 | ||||
|
19 | class CHARTWIDGET_EXPORT ChartWidget : public QWidget | |||
|
20 | { | |||
|
21 | Q_OBJECT | |||
|
22 | Q_PROPERTY(QColor color READ color WRITE setColor) | |||
|
23 | ||||
|
24 | public: | |||
|
25 | explicit ChartWidget(QWidget *parent = 0); | |||
|
26 | ~ChartWidget(); | |||
|
27 | ||||
|
28 | QColor color() const; | |||
|
29 | void setColor(const QColor &color); | |||
|
30 | ||||
|
31 | protected: | |||
|
32 | virtual void paintEvent(QPaintEvent *); | |||
|
33 | ||||
|
34 | private: | |||
|
35 | Q_DISABLE_COPY(ChartWidget) | |||
|
36 | Q_DECLARE_PRIVATE(ChartWidget) | |||
|
37 | ChartWidgetPrivate* d_ptr; | |||
|
38 | }; | |||
|
39 | ||||
|
40 | #endif |
@@ -0,0 +1,25 | |||||
|
1 | TARGET = ChartWidget | |||
|
2 | TEMPLATE = lib | |||
|
3 | ||||
|
4 | QT += core gui | |||
|
5 | contains(QT_MAJOR_VERSION, 5) { | |||
|
6 | QT += widgets | |||
|
7 | } | |||
|
8 | ||||
|
9 | SOURCES += \ | |||
|
10 | chartwidget.cpp | |||
|
11 | HEADERS += \ | |||
|
12 | chartwidget.h | |||
|
13 | include(../src/chart.pri) | |||
|
14 | ||||
|
15 | OBJECTS_DIR = tmp | |||
|
16 | MOC_DIR = tmp | |||
|
17 | ||||
|
18 | DEFINES += CHARTWIDGET_LIBRARY | |||
|
19 | ||||
|
20 | public_headers.path = $$[QT_INSTALL_HEADERS]/Charts | |||
|
21 | public_headers.files = chartwidget.h | |||
|
22 | ||||
|
23 | target.path=$$[QT_INSTALL_LIBS] | |||
|
24 | ||||
|
25 | INSTALLS += target public_headers |
General Comments 0
You need to be logged in to leave comments.
Login now