@@ -0,0 +1,43 | |||
|
1 | #include "chartbackground_p.h" | |
|
2 | #include <QPen> | |
|
3 | #include <QBrush> | |
|
4 | #include <QPainter> | |
|
5 | ||
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
7 | ||
|
8 | ChartBackground::ChartBackground(QGraphicsItem* parent):QGraphicsRectItem(parent), | |
|
9 | m_diameter(15) | |
|
10 | { | |
|
11 | ||
|
12 | } | |
|
13 | ||
|
14 | ChartBackground::~ChartBackground() | |
|
15 | { | |
|
16 | ||
|
17 | } | |
|
18 | ||
|
19 | void ChartBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
20 | { | |
|
21 | Q_UNUSED(option); | |
|
22 | Q_UNUSED(widget); | |
|
23 | painter->setPen(pen()); | |
|
24 | painter->setBrush(brush()); | |
|
25 | painter->drawRoundRect(rect(),roundness(rect().width()),roundness(rect().height())); | |
|
26 | } | |
|
27 | ||
|
28 | int ChartBackground::roundness(qreal size) const | |
|
29 | { | |
|
30 | return 100*m_diameter/int(size); | |
|
31 | } | |
|
32 | ||
|
33 | int ChartBackground::diameter() const | |
|
34 | { | |
|
35 | return m_diameter; | |
|
36 | } | |
|
37 | ||
|
38 | void ChartBackground::setDimeter(int dimater) | |
|
39 | { | |
|
40 | m_diameter=dimater; | |
|
41 | } | |
|
42 | ||
|
43 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,33 | |||
|
1 | #ifndef CHARTBACKGROUND_H_ | |
|
2 | #define CHARTBACKGROUND_H_ | |
|
3 | ||
|
4 | #include "qchartglobal.h" | |
|
5 | #include <QGraphicsRectItem> | |
|
6 | ||
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
8 | ||
|
9 | class ChartBackground: public QGraphicsRectItem | |
|
10 | { | |
|
11 | public: | |
|
12 | ChartBackground(QGraphicsItem *parent =0); | |
|
13 | ~ChartBackground(); | |
|
14 | ||
|
15 | void setDimeter(int dimater); | |
|
16 | int diameter() const; | |
|
17 | ||
|
18 | ||
|
19 | protected: | |
|
20 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
|
21 | ||
|
22 | ||
|
23 | private: | |
|
24 | int roundness(qreal size) const; | |
|
25 | ||
|
26 | private: | |
|
27 | int m_diameter; | |
|
28 | ||
|
29 | }; | |
|
30 | ||
|
31 | #endif /* CHARTBACKGROUND_H_ */ | |
|
32 | ||
|
33 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now