@@ -1,62 +1,63 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "drilldownslice.h" |
|
21 | #include "drilldownslice.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
23 | QTCOMMERCIALCHART_USE_NAMESPACE | |
24 |
|
24 | |||
25 | DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QAbstractSeries* drilldownSeries) |
|
25 | DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QAbstractSeries* drilldownSeries) | |
26 | :m_drilldownSeries(drilldownSeries), |
|
26 | :m_drilldownSeries(drilldownSeries), | |
27 | m_prefix(prefix) |
|
27 | m_prefix(prefix) | |
28 | { |
|
28 | { | |
29 | setValue(value); |
|
29 | setValue(value); | |
30 | updateLabel(); |
|
30 | updateLabel(); | |
31 | setLabelFont(QFont("Arial", 8)); |
|
31 | setLabelFont(QFont("Arial", 8)); | |
32 | connect(this, SIGNAL(changed()), this, SLOT(updateLabel())); |
|
32 | connect(this, SIGNAL(changed()), this, SLOT(updateLabel())); | |
33 | connect(this, SIGNAL(hovered(bool)), this, SLOT(showHighlight(bool))); |
|
33 | connect(this, SIGNAL(hovered(bool)), this, SLOT(showHighlight(bool))); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | DrilldownSlice::~DrilldownSlice() |
|
36 | DrilldownSlice::~DrilldownSlice() | |
37 | { |
|
37 | { | |
38 |
|
38 | |||
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QAbstractSeries* DrilldownSlice::drilldownSeries() const |
|
41 | QAbstractSeries* DrilldownSlice::drilldownSeries() const | |
42 | { |
|
42 | { | |
43 | return m_drilldownSeries; |
|
43 | return m_drilldownSeries; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void DrilldownSlice::updateLabel() |
|
46 | void DrilldownSlice::updateLabel() | |
47 | { |
|
47 | { | |
48 | QString label = m_prefix; |
|
48 | QString label = m_prefix; | |
49 | label += " $"; |
|
49 | label += " $"; | |
50 | label += QString::number(this->value()); |
|
50 | label += QString::number(this->value()); | |
51 | label += ", "; |
|
51 | label += ", "; | |
52 | label += QString::number(this->percentage()*100, 'f', 1); |
|
52 | label += QString::number(this->percentage()*100, 'f', 1); | |
53 | label += "%"; |
|
53 | label += "%"; | |
54 | setLabel(label); |
|
54 | setLabel(label); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | void DrilldownSlice::showHighlight(bool show) |
|
57 | void DrilldownSlice::showHighlight(bool show) | |
58 | { |
|
58 | { | |
59 | setLabelVisible(show); |
|
59 | setLabelVisible(show); | |
|
60 | setExploded(show); | |||
60 | } |
|
61 | } | |
61 |
|
62 | |||
62 | #include "moc_drilldownslice.cpp" |
|
63 | #include "moc_drilldownslice.cpp" |
@@ -1,214 +1,220 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "piesliceitem_p.h" |
|
21 | #include "piesliceitem_p.h" | |
22 | #include "piechartitem_p.h" |
|
22 | #include "piechartitem_p.h" | |
23 | #include "qpieseries.h" |
|
23 | #include "qpieseries.h" | |
24 | #include "qpieslice.h" |
|
24 | #include "qpieslice.h" | |
25 | #include "chartpresenter_p.h" |
|
25 | #include "chartpresenter_p.h" | |
26 | #include <QPainter> |
|
26 | #include <QPainter> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 | #include <QGraphicsSceneEvent> |
|
28 | #include <QGraphicsSceneEvent> | |
29 | #include <QTime> |
|
29 | #include <QTime> | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | #define PI 3.14159265 // TODO: is this defined in some header? |
|
33 | #define PI 3.14159265 // TODO: is this defined in some header? | |
34 |
|
34 | |||
35 | QPointF offset(qreal angle, qreal length) |
|
35 | QPointF offset(qreal angle, qreal length) | |
36 | { |
|
36 | { | |
37 | qreal dx = qSin(angle*(PI/180)) * length; |
|
37 | qreal dx = qSin(angle*(PI/180)) * length; | |
38 | qreal dy = qCos(angle*(PI/180)) * length; |
|
38 | qreal dy = qCos(angle*(PI/180)) * length; | |
39 | return QPointF(dx, -dy); |
|
39 | return QPointF(dx, -dy); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | PieSliceItem::PieSliceItem(QGraphicsItem* parent) |
|
42 | PieSliceItem::PieSliceItem(QGraphicsItem* parent) | |
43 | :QGraphicsObject(parent) |
|
43 | :QGraphicsObject(parent), | |
|
44 | m_hovered(false) | |||
44 | { |
|
45 | { | |
45 | setAcceptHoverEvents(true); |
|
46 | setAcceptHoverEvents(true); | |
46 | setAcceptedMouseButtons(Qt::MouseButtonMask); |
|
47 | setAcceptedMouseButtons(Qt::MouseButtonMask); | |
47 | setZValue(ChartPresenter::PieSeriesZValue); |
|
48 | setZValue(ChartPresenter::PieSeriesZValue); | |
48 | } |
|
49 | } | |
49 |
|
50 | |||
50 | PieSliceItem::~PieSliceItem() |
|
51 | PieSliceItem::~PieSliceItem() | |
51 | { |
|
52 | { | |
52 |
|
53 | // If user is hovering over the slice and it gets destroyed we do | ||
|
54 | // not get a hover leave event. So we must emit the signal here. | |||
|
55 | if (m_hovered) | |||
|
56 | emit hovered(false); | |||
53 | } |
|
57 | } | |
54 |
|
58 | |||
55 | QRectF PieSliceItem::boundingRect() const |
|
59 | QRectF PieSliceItem::boundingRect() const | |
56 | { |
|
60 | { | |
57 | return m_boundingRect; |
|
61 | return m_boundingRect; | |
58 | } |
|
62 | } | |
59 |
|
63 | |||
60 | QPainterPath PieSliceItem::shape() const |
|
64 | QPainterPath PieSliceItem::shape() const | |
61 | { |
|
65 | { | |
62 | // Don't include the label and label arm. |
|
66 | // Don't include the label and label arm. | |
63 | // This is used to detect a mouse clicks. We do not want clicks from label. |
|
67 | // This is used to detect a mouse clicks. We do not want clicks from label. | |
64 | return m_slicePath; |
|
68 | return m_slicePath; | |
65 | } |
|
69 | } | |
66 |
|
70 | |||
67 | void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) |
|
71 | void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) | |
68 | { |
|
72 | { | |
69 | painter->save(); |
|
73 | painter->save(); | |
70 | painter->setClipRect(parentItem()->boundingRect()); |
|
74 | painter->setClipRect(parentItem()->boundingRect()); | |
71 | painter->setPen(m_data.m_slicePen); |
|
75 | painter->setPen(m_data.m_slicePen); | |
72 | painter->setBrush(m_data.m_sliceBrush); |
|
76 | painter->setBrush(m_data.m_sliceBrush); | |
73 | painter->drawPath(m_slicePath); |
|
77 | painter->drawPath(m_slicePath); | |
74 | painter->restore(); |
|
78 | painter->restore(); | |
75 |
|
79 | |||
76 | if (m_data.m_isLabelVisible) { |
|
80 | if (m_data.m_isLabelVisible) { | |
77 | painter->setClipRect(parentItem()->boundingRect()); |
|
81 | painter->setClipRect(parentItem()->boundingRect()); | |
78 | painter->setPen(m_data.m_labelPen); |
|
82 | painter->setPen(m_data.m_labelPen); | |
79 | painter->drawPath(m_labelArmPath); |
|
83 | painter->drawPath(m_labelArmPath); | |
80 | // the pen color will affect the font color as well |
|
84 | // the pen color will affect the font color as well | |
81 | painter->setFont(m_data.m_labelFont); |
|
85 | painter->setFont(m_data.m_labelFont); | |
82 | painter->drawText(m_labelTextRect.bottomLeft(), m_data.m_labelText); |
|
86 | painter->drawText(m_labelTextRect.bottomLeft(), m_data.m_labelText); | |
83 | } |
|
87 | } | |
84 | } |
|
88 | } | |
85 |
|
89 | |||
86 | void PieSliceItem::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) |
|
90 | void PieSliceItem::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) | |
87 | { |
|
91 | { | |
|
92 | m_hovered = true; | |||
88 | emit hovered(true); |
|
93 | emit hovered(true); | |
89 | } |
|
94 | } | |
90 |
|
95 | |||
91 | void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) |
|
96 | void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) | |
92 | { |
|
97 | { | |
|
98 | m_hovered = false; | |||
93 | emit hovered(false); |
|
99 | emit hovered(false); | |
94 | } |
|
100 | } | |
95 |
|
101 | |||
96 | void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
102 | void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
97 | { |
|
103 | { | |
98 | emit clicked(event->buttons()); |
|
104 | emit clicked(event->buttons()); | |
99 | } |
|
105 | } | |
100 |
|
106 | |||
101 | void PieSliceItem::setLayout(const PieSliceData &sliceData) |
|
107 | void PieSliceItem::setLayout(const PieSliceData &sliceData) | |
102 | { |
|
108 | { | |
103 | m_data = sliceData; |
|
109 | m_data = sliceData; | |
104 | updateGeometry(); |
|
110 | updateGeometry(); | |
105 | update(); |
|
111 | update(); | |
106 | } |
|
112 | } | |
107 |
|
113 | |||
108 | void PieSliceItem::updateGeometry() |
|
114 | void PieSliceItem::updateGeometry() | |
109 | { |
|
115 | { | |
110 | if (m_data.m_radius <= 0) |
|
116 | if (m_data.m_radius <= 0) | |
111 | return; |
|
117 | return; | |
112 |
|
118 | |||
113 | prepareGeometryChange(); |
|
119 | prepareGeometryChange(); | |
114 |
|
120 | |||
115 | // update slice path |
|
121 | // update slice path | |
116 | qreal centerAngle; |
|
122 | qreal centerAngle; | |
117 | QPointF armStart; |
|
123 | QPointF armStart; | |
118 | m_slicePath = slicePath(m_data.m_center, m_data.m_radius, m_data.m_startAngle, m_data.m_angleSpan, ¢erAngle, &armStart); |
|
124 | m_slicePath = slicePath(m_data.m_center, m_data.m_radius, m_data.m_startAngle, m_data.m_angleSpan, ¢erAngle, &armStart); | |
119 |
|
125 | |||
120 | // update text rect |
|
126 | // update text rect | |
121 | m_labelTextRect = labelTextRect(m_data.m_labelFont, m_data.m_labelText); |
|
127 | m_labelTextRect = labelTextRect(m_data.m_labelFont, m_data.m_labelText); | |
122 |
|
128 | |||
123 | // update label arm path |
|
129 | // update label arm path | |
124 | QPointF labelTextStart; |
|
130 | QPointF labelTextStart; | |
125 | m_labelArmPath = labelArmPath(armStart, centerAngle, m_data.m_radius * m_data.m_labelArmLengthFactor, m_labelTextRect.width(), &labelTextStart); |
|
131 | m_labelArmPath = labelArmPath(armStart, centerAngle, m_data.m_radius * m_data.m_labelArmLengthFactor, m_labelTextRect.width(), &labelTextStart); | |
126 |
|
132 | |||
127 | // update text position |
|
133 | // update text position | |
128 | m_labelTextRect.moveBottomLeft(labelTextStart); |
|
134 | m_labelTextRect.moveBottomLeft(labelTextStart); | |
129 |
|
135 | |||
130 | // update bounding rect |
|
136 | // update bounding rect | |
131 | if (m_data.m_isLabelVisible) |
|
137 | if (m_data.m_isLabelVisible) | |
132 | m_boundingRect = m_slicePath.boundingRect().united(m_labelArmPath.boundingRect()).united(m_labelTextRect); |
|
138 | m_boundingRect = m_slicePath.boundingRect().united(m_labelArmPath.boundingRect()).united(m_labelTextRect); | |
133 | else |
|
139 | else | |
134 | m_boundingRect = m_slicePath.boundingRect(); |
|
140 | m_boundingRect = m_slicePath.boundingRect(); | |
135 | } |
|
141 | } | |
136 |
|
142 | |||
137 | QPointF PieSliceItem::sliceCenter(QPointF point, qreal radius, QPieSlice *slice) |
|
143 | QPointF PieSliceItem::sliceCenter(QPointF point, qreal radius, QPieSlice *slice) | |
138 | { |
|
144 | { | |
139 | if (slice->isExploded()) { |
|
145 | if (slice->isExploded()) { | |
140 | qreal centerAngle = slice->startAngle() + ((slice->endAngle() - slice->startAngle())/2); |
|
146 | qreal centerAngle = slice->startAngle() + ((slice->endAngle() - slice->startAngle())/2); | |
141 | qreal len = radius * slice->explodeDistanceFactor(); |
|
147 | qreal len = radius * slice->explodeDistanceFactor(); | |
142 | qreal dx = qSin(centerAngle*(PI/180)) * len; |
|
148 | qreal dx = qSin(centerAngle*(PI/180)) * len; | |
143 | qreal dy = -qCos(centerAngle*(PI/180)) * len; |
|
149 | qreal dy = -qCos(centerAngle*(PI/180)) * len; | |
144 | point += QPointF(dx, dy); |
|
150 | point += QPointF(dx, dy); | |
145 | } |
|
151 | } | |
146 | return point; |
|
152 | return point; | |
147 | } |
|
153 | } | |
148 |
|
154 | |||
149 | QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal *centerAngle, QPointF* armStart) |
|
155 | QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal *centerAngle, QPointF* armStart) | |
150 | { |
|
156 | { | |
151 | // calculate center angle |
|
157 | // calculate center angle | |
152 | *centerAngle = startAngle + (angleSpan/2); |
|
158 | *centerAngle = startAngle + (angleSpan/2); | |
153 |
|
159 | |||
154 | // calculate slice rectangle |
|
160 | // calculate slice rectangle | |
155 | QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2); |
|
161 | QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2); | |
156 |
|
162 | |||
157 | // slice path |
|
163 | // slice path | |
158 | // TODO: draw the shape so that it might have a hole in the center |
|
164 | // TODO: draw the shape so that it might have a hole in the center | |
159 | QPainterPath path; |
|
165 | QPainterPath path; | |
160 | path.moveTo(rect.center()); |
|
166 | path.moveTo(rect.center()); | |
161 | path.arcTo(rect, -startAngle + 90, -angleSpan); |
|
167 | path.arcTo(rect, -startAngle + 90, -angleSpan); | |
162 | path.closeSubpath(); |
|
168 | path.closeSubpath(); | |
163 |
|
169 | |||
164 | // calculate label arm start point |
|
170 | // calculate label arm start point | |
165 | *armStart = center; |
|
171 | *armStart = center; | |
166 | *armStart += offset(*centerAngle, radius + PIESLICE_LABEL_GAP); |
|
172 | *armStart += offset(*centerAngle, radius + PIESLICE_LABEL_GAP); | |
167 |
|
173 | |||
168 | return path; |
|
174 | return path; | |
169 | } |
|
175 | } | |
170 |
|
176 | |||
171 | QPainterPath PieSliceItem::labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF *textStart) |
|
177 | QPainterPath PieSliceItem::labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF *textStart) | |
172 | { |
|
178 | { | |
173 | // prevent label arm pointing straight down because it will look bad |
|
179 | // prevent label arm pointing straight down because it will look bad | |
174 | if (angle < 180 && angle > 170) |
|
180 | if (angle < 180 && angle > 170) | |
175 | angle = 170; |
|
181 | angle = 170; | |
176 | if (angle > 180 && angle < 190) |
|
182 | if (angle > 180 && angle < 190) | |
177 | angle = 190; |
|
183 | angle = 190; | |
178 |
|
184 | |||
179 | // line from slice to label |
|
185 | // line from slice to label | |
180 | qreal dx = qSin(angle*(PI/180)) * length; |
|
186 | qreal dx = qSin(angle*(PI/180)) * length; | |
181 | qreal dy = -qCos(angle*(PI/180)) * length; |
|
187 | qreal dy = -qCos(angle*(PI/180)) * length; | |
182 | QPointF parm1 = start + QPointF(dx, dy); |
|
188 | QPointF parm1 = start + QPointF(dx, dy); | |
183 |
|
189 | |||
184 | // line to underline the label |
|
190 | // line to underline the label | |
185 | QPointF parm2 = parm1; |
|
191 | QPointF parm2 = parm1; | |
186 | if (angle < 180) { // arm swings the other way on the left side |
|
192 | if (angle < 180) { // arm swings the other way on the left side | |
187 | parm2 += QPointF(textWidth, 0); |
|
193 | parm2 += QPointF(textWidth, 0); | |
188 | *textStart = parm1; |
|
194 | *textStart = parm1; | |
189 | } |
|
195 | } | |
190 | else { |
|
196 | else { | |
191 | parm2 += QPointF(-textWidth,0); |
|
197 | parm2 += QPointF(-textWidth,0); | |
192 | *textStart = parm2; |
|
198 | *textStart = parm2; | |
193 | } |
|
199 | } | |
194 |
|
200 | |||
195 | // elevate the text position a bit so that it does not hit the line |
|
201 | // elevate the text position a bit so that it does not hit the line | |
196 | *textStart += QPointF(0, -3); |
|
202 | *textStart += QPointF(0, -3); | |
197 |
|
203 | |||
198 | QPainterPath path; |
|
204 | QPainterPath path; | |
199 | path.moveTo(start); |
|
205 | path.moveTo(start); | |
200 | path.lineTo(parm1); |
|
206 | path.lineTo(parm1); | |
201 | path.lineTo(parm2); |
|
207 | path.lineTo(parm2); | |
202 |
|
208 | |||
203 | return path; |
|
209 | return path; | |
204 | } |
|
210 | } | |
205 |
|
211 | |||
206 | QRectF PieSliceItem::labelTextRect(QFont font, QString text) |
|
212 | QRectF PieSliceItem::labelTextRect(QFont font, QString text) | |
207 | { |
|
213 | { | |
208 | QFontMetricsF fm(font); |
|
214 | QFontMetricsF fm(font); | |
209 | return fm.boundingRect(text); |
|
215 | return fm.boundingRect(text); | |
210 | } |
|
216 | } | |
211 |
|
217 | |||
212 | #include "moc_piesliceitem_p.cpp" |
|
218 | #include "moc_piesliceitem_p.cpp" | |
213 |
|
219 | |||
214 | QTCOMMERCIALCHART_END_NAMESPACE |
|
220 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,79 +1,80 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef PIESLICEITEM_H |
|
21 | #ifndef PIESLICEITEM_H | |
22 | #define PIESLICEITEM_H |
|
22 | #define PIESLICEITEM_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "qpieseries.h" |
|
26 | #include "qpieseries.h" | |
27 | #include "pieslicedata_p.h" |
|
27 | #include "pieslicedata_p.h" | |
28 | #include <QGraphicsItem> |
|
28 | #include <QGraphicsItem> | |
29 | #include <QRectF> |
|
29 | #include <QRectF> | |
30 | #include <QColor> |
|
30 | #include <QColor> | |
31 | #include <QPen> |
|
31 | #include <QPen> | |
32 |
|
32 | |||
33 | #define PIESLICE_LABEL_GAP 5 |
|
33 | #define PIESLICE_LABEL_GAP 5 | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 | class PieChartItem; |
|
36 | class PieChartItem; | |
37 | class PieSliceLabel; |
|
37 | class PieSliceLabel; | |
38 | class QPieSlice; |
|
38 | class QPieSlice; | |
39 |
|
39 | |||
40 | class PieSliceItem : public QGraphicsObject |
|
40 | class PieSliceItem : public QGraphicsObject | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 |
|
43 | |||
44 | public: |
|
44 | public: | |
45 | PieSliceItem(QGraphicsItem* parent = 0); |
|
45 | PieSliceItem(QGraphicsItem* parent = 0); | |
46 | ~PieSliceItem(); |
|
46 | ~PieSliceItem(); | |
47 |
|
47 | |||
48 | // from QGraphicsItem |
|
48 | // from QGraphicsItem | |
49 | QRectF boundingRect() const; |
|
49 | QRectF boundingRect() const; | |
50 | QPainterPath shape() const; |
|
50 | QPainterPath shape() const; | |
51 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
51 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
52 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); |
|
52 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
53 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); |
|
53 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); | |
54 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
54 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
55 |
|
55 | |||
56 | void setLayout(const PieSliceData &sliceData); |
|
56 | void setLayout(const PieSliceData &sliceData); | |
57 | static QPointF sliceCenter(QPointF point, qreal radius, QPieSlice *slice); |
|
57 | static QPointF sliceCenter(QPointF point, qreal radius, QPieSlice *slice); | |
58 |
|
58 | |||
59 | Q_SIGNALS: |
|
59 | Q_SIGNALS: | |
60 | void clicked(Qt::MouseButtons buttons); |
|
60 | void clicked(Qt::MouseButtons buttons); | |
61 | void hovered(bool state); |
|
61 | void hovered(bool state); | |
62 |
|
62 | |||
63 | private: |
|
63 | private: | |
64 | void updateGeometry(); |
|
64 | void updateGeometry(); | |
65 | QPainterPath slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal *centerAngle, QPointF *armStart); |
|
65 | QPainterPath slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal *centerAngle, QPointF *armStart); | |
66 | QPainterPath labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF *textStart); |
|
66 | QPainterPath labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF *textStart); | |
67 | QRectF labelTextRect(QFont font, QString text); |
|
67 | QRectF labelTextRect(QFont font, QString text); | |
68 |
|
68 | |||
69 | private: |
|
69 | private: | |
70 | PieSliceData m_data; |
|
70 | PieSliceData m_data; | |
71 | QRectF m_boundingRect; |
|
71 | QRectF m_boundingRect; | |
72 | QPainterPath m_slicePath; |
|
72 | QPainterPath m_slicePath; | |
73 | QPainterPath m_labelArmPath; |
|
73 | QPainterPath m_labelArmPath; | |
74 | QRectF m_labelTextRect; |
|
74 | QRectF m_labelTextRect; | |
|
75 | bool m_hovered; | |||
75 | }; |
|
76 | }; | |
76 |
|
77 | |||
77 | QTCOMMERCIALCHART_END_NAMESPACE |
|
78 | QTCOMMERCIALCHART_END_NAMESPACE | |
78 |
|
79 | |||
79 | #endif // PIESLICEITEM_H |
|
80 | #endif // PIESLICEITEM_H |
General Comments 0
You need to be logged in to leave comments.
Login now