##// END OF EJS Templates
Pie now actually withs the given rectangle and does not go over
Jani Honkonen -
r413:afa09ce7f031
parent child
Show More
@@ -123,12 +123,22 void PiePresenter::updateGeometry()
123 foreach (QPieSlice* s, m_series->m_slices) {
123 foreach (QPieSlice* s, m_series->m_slices) {
124
124
125 // calculate the farthest point in the slice from the pie center
125 // calculate the farthest point in the slice from the pie center
126
127 // the arm
126 qreal centerAngle = s->m_startAngle + (s->m_angleSpan / 2);
128 qreal centerAngle = s->m_startAngle + (s->m_angleSpan / 2);
127 qreal len = pieRadius + s->labelArmLength() + s->explodeDistance();
129 qreal len = pieRadius + PIESLICE_LABEL_GAP + s->labelArmLength() + s->explodeDistance();
128 QPointF dp(qSin(centerAngle*(PI/180)) * len, -qCos(centerAngle*(PI/180)) * len);
130 QPointF dp(qSin(centerAngle*(PI/180)) * len, -qCos(centerAngle*(PI/180)) * len);
129 QPointF p = pieRect.center() + dp;
131 QPointF p = pieRect.center() + dp;
130
132
131 // TODO: consider the label text
133 // the label text
134 QFontMetricsF fm(s->labelFont());
135 QRectF labelRect = fm.boundingRect(s->label());
136 if (centerAngle < 90 || centerAngle > 270)
137 p += QPointF(0, -labelRect.height());
138 if (centerAngle < 180)
139 p += QPointF(labelRect.width(), 0);
140 else
141 p += QPointF(-labelRect.width(), 0);
132
142
133 // calculate how much the radius must get smaller to fit that point in the base rectangle
143 // calculate how much the radius must get smaller to fit that point in the base rectangle
134 qreal dt = m_rect.top() - p.y();
144 qreal dt = m_rect.top() - p.y();
@@ -100,7 +100,7 void PieSlice::updateGeometry()
100
100
101 // update label position
101 // update label position
102 qreal radius = rect.height() / 2;
102 qreal radius = rect.height() / 2;
103 QPointF edgeCenter = rect.center() + offset(centerAngle, radius + 5);
103 QPointF edgeCenter = rect.center() + offset(centerAngle, radius + PIESLICE_LABEL_GAP);
104 m_slicelabel->setArmStartPoint(edgeCenter);
104 m_slicelabel->setArmStartPoint(edgeCenter);
105 m_slicelabel->setArmAngle(centerAngle);
105 m_slicelabel->setArmAngle(centerAngle);
106 m_slicelabel->updateGeometry();
106 m_slicelabel->updateGeometry();
@@ -9,6 +9,8
9 #include <QColor>
9 #include <QColor>
10 #include <QPen>
10 #include <QPen>
11
11
12 #define PIESLICE_LABEL_GAP 5
13
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13 class PiePresenter;
15 class PiePresenter;
14 class PieSliceLabel;
16 class PieSliceLabel;
General Comments 0
You need to be logged in to leave comments. Login now