@@ -1,123 +1,123 | |||
|
1 | 1 | #ifndef AXISITEM_H_ |
|
2 | 2 | #define AXISITEM_H_ |
|
3 | 3 | |
|
4 | 4 | #include "chart_p.h" |
|
5 | 5 | #include <QGraphicsItem> |
|
6 | 6 | |
|
7 | 7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | 8 | |
|
9 | 9 | class QChartAxis; |
|
10 | 10 | class ChartPresenter; |
|
11 | 11 | |
|
12 | 12 | class Axis : public Chart |
|
13 | 13 | { |
|
14 | 14 | Q_OBJECT |
|
15 | 15 | public: |
|
16 | 16 | enum AxisType{X_AXIS,Y_AXIS}; |
|
17 | 17 | |
|
18 | 18 | Axis(QChartAxis *axis, ChartPresenter *presenter, AxisType type = X_AXIS); |
|
19 | 19 | ~Axis(); |
|
20 | 20 | |
|
21 | 21 | AxisType axisType() const { return m_type; } |
|
22 | 22 | |
|
23 | 23 | void setAxisOpacity(qreal opacity); |
|
24 | 24 | qreal axisOpacity() const; |
|
25 | 25 | |
|
26 | 26 | void setGridOpacity(qreal opacity); |
|
27 | 27 | qreal gridOpacity() const; |
|
28 | 28 | |
|
29 | 29 | void setLabelsOpacity(qreal opacity); |
|
30 | 30 | qreal labelsOpacity() const; |
|
31 | 31 | |
|
32 | 32 | void setShadesOpacity(qreal opacity); |
|
33 | 33 | qreal shadesOpacity() const; |
|
34 | 34 | |
|
35 | 35 | void setLabelsAngle(int angle); |
|
36 | 36 | int labelsAngle()const { return m_labelsAngle; } |
|
37 | 37 | |
|
38 | 38 | void setShadesBrush(const QBrush &brush); |
|
39 | 39 | void setShadesPen(const QPen &pen); |
|
40 | 40 | |
|
41 | 41 | void setAxisPen(const QPen &pen); |
|
42 | 42 | void setGridPen(const QPen &pen); |
|
43 | 43 | |
|
44 | 44 | void setLabelsPen(const QPen &pen); |
|
45 | 45 | void setLabelsBrush(const QBrush &brush); |
|
46 | 46 | void setLabelsFont(const QFont &font); |
|
47 | 47 | |
|
48 | 48 | inline QRectF geometry() const { return m_rect; } |
|
49 | 49 | inline QVector<qreal> layout() { return m_layoutVector; } |
|
50 | 50 | |
|
51 | 51 | public Q_SLOTS: |
|
52 | 52 | void handleAxisUpdated(); |
|
53 | 53 | void handleAxisCategoriesUpdated(); |
|
54 | 54 | void handleRangeChanged(qreal min , qreal max,int tickCount); |
|
55 | 55 | void handleGeometryChanged(const QRectF &size); |
|
56 | 56 | |
|
57 | 57 | |
|
58 | 58 | private: |
|
59 | 59 | inline bool isEmpty(); |
|
60 | 60 | void createItems(int count); |
|
61 | 61 | void deleteItems(int count); |
|
62 | 62 | |
|
63 | 63 | QVector<qreal> calculateLayout() const; |
|
64 | 64 | void updateLayout(QVector<qreal> &layout); |
|
65 | 65 | void setLayout(QVector<qreal> &layout); |
|
66 | 66 | |
|
67 | 67 | bool createLabels(QStringList &labels,qreal min, qreal max,int ticks) const; |
|
68 | 68 | void axisSelected(); |
|
69 | 69 | |
|
70 | 70 | private: |
|
71 | 71 | QChartAxis* m_chartAxis; |
|
72 | 72 | AxisType m_type; |
|
73 | 73 | QRectF m_rect; |
|
74 | 74 | int m_labelsAngle; |
|
75 |
QGraphicsItemGroup |
|
|
76 |
QGraphicsItemGroup |
|
|
77 |
QGraphicsItemGroup |
|
|
78 |
QGraphicsItemGroup |
|
|
75 | QScopedPointer<QGraphicsItemGroup> m_grid; | |
|
76 | QScopedPointer<QGraphicsItemGroup> m_shades; | |
|
77 | QScopedPointer<QGraphicsItemGroup> m_labels; | |
|
78 | QScopedPointer<QGraphicsItemGroup> m_axis; | |
|
79 | 79 | QVector<qreal> m_layoutVector; |
|
80 | 80 | qreal m_min; |
|
81 | 81 | qreal m_max; |
|
82 | 82 | int m_ticksCount; |
|
83 | 83 | qreal m_zoomFactor; |
|
84 | 84 | |
|
85 | 85 | friend class AxisAnimation; |
|
86 | 86 | friend class AxisItem; |
|
87 | 87 | |
|
88 | 88 | }; |
|
89 | 89 | |
|
90 | 90 | class AxisItem: public QGraphicsLineItem |
|
91 | 91 | { |
|
92 | 92 | public: |
|
93 | 93 | |
|
94 | 94 | AxisItem(Axis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {} |
|
95 | 95 | |
|
96 | 96 | protected: |
|
97 | 97 | void mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
98 | 98 | { |
|
99 | 99 | Q_UNUSED(event) |
|
100 | 100 | m_axis->axisSelected(); |
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | QRectF boundingRect() const |
|
104 | 104 | { |
|
105 | 105 | return shape().boundingRect(); |
|
106 | 106 | } |
|
107 | 107 | |
|
108 | 108 | QPainterPath shape() const |
|
109 | 109 | { |
|
110 | 110 | QPainterPath path = QGraphicsLineItem::shape(); |
|
111 | 111 | QRectF rect = path.boundingRect(); |
|
112 | 112 | path.addRect(rect.adjusted(0,0,m_axis->axisType()!=Axis::X_AXIS?8:0,m_axis->axisType()!=Axis::Y_AXIS?8:0)); |
|
113 | 113 | return path; |
|
114 | 114 | } |
|
115 | 115 | |
|
116 | 116 | private: |
|
117 | 117 | Axis* m_axis; |
|
118 | 118 | |
|
119 | 119 | }; |
|
120 | 120 | |
|
121 | 121 | QTCOMMERCIALCHART_END_NAMESPACE |
|
122 | 122 | |
|
123 | 123 | #endif /* AXISITEM_H_ */ |
General Comments 0
You need to be logged in to leave comments.
Login now