@@ -145,7 +145,7 QPointF PieSliceItem::sliceCenter(QPointF point, qreal radius, QPieSlice *slice) | |||||
145 | return point; |
|
145 | return point; | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 |
QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal* |
|
148 | QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal *centerAngle, QPointF* armStart) | |
149 | { |
|
149 | { | |
150 | // calculate center angle |
|
150 | // calculate center angle | |
151 | *centerAngle = startAngle + (angleSpan/2); |
|
151 | *centerAngle = startAngle + (angleSpan/2); | |
@@ -167,12 +167,20 QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAn | |||||
167 | return path; |
|
167 | return path; | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 |
QPainterPath PieSliceItem::labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF* |
|
170 | QPainterPath PieSliceItem::labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF *textStart) | |
171 | { |
|
171 | { | |
|
172 | // prevent label arm pointing straight down because it will look bad | |||
|
173 | if (angle < 180 && angle > 170) | |||
|
174 | angle = 170; | |||
|
175 | if (angle > 180 && angle < 190) | |||
|
176 | angle = 190; | |||
|
177 | ||||
|
178 | // line from slice to label | |||
172 | qreal dx = qSin(angle*(PI/180)) * length; |
|
179 | qreal dx = qSin(angle*(PI/180)) * length; | |
173 | qreal dy = -qCos(angle*(PI/180)) * length; |
|
180 | qreal dy = -qCos(angle*(PI/180)) * length; | |
174 | QPointF parm1 = start + QPointF(dx, dy); |
|
181 | QPointF parm1 = start + QPointF(dx, dy); | |
175 |
|
182 | |||
|
183 | // line to underline the label | |||
176 | QPointF parm2 = parm1; |
|
184 | QPointF parm2 = parm1; | |
177 | if (angle < 180) { // arm swings the other way on the left side |
|
185 | if (angle < 180) { // arm swings the other way on the left side | |
178 | parm2 += QPointF(textWidth, 0); |
|
186 | parm2 += QPointF(textWidth, 0); | |
@@ -184,7 +192,7 QPainterPath PieSliceItem::labelArmPath(QPointF start, qreal angle, qreal length | |||||
184 | } |
|
192 | } | |
185 |
|
193 | |||
186 | // elevate the text position a bit so that it does not hit the line |
|
194 | // elevate the text position a bit so that it does not hit the line | |
187 |
*textStart += QPointF(0, - |
|
195 | *textStart += QPointF(0, -3); | |
188 |
|
196 | |||
189 | QPainterPath path; |
|
197 | QPainterPath path; | |
190 | path.moveTo(start); |
|
198 | path.moveTo(start); |
@@ -62,9 +62,9 public: | |||||
62 | void setSliceData(PieSliceData sliceData); |
|
62 | void setSliceData(PieSliceData sliceData); | |
63 | void updateGeometry(); |
|
63 | void updateGeometry(); | |
64 | static QPointF sliceCenter(QPointF point, qreal radius, QPieSlice *slice); |
|
64 | static QPointF sliceCenter(QPointF point, qreal radius, QPieSlice *slice); | |
65 |
|
|
65 | QPainterPath slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal *centerAngle, QPointF *armStart); | |
66 |
|
|
66 | QPainterPath labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF *textStart); | |
67 |
|
|
67 | QRectF labelTextRect(QFont font, QString text); | |
68 |
|
68 | |||
69 | private: |
|
69 | private: | |
70 | PieSliceData m_data; |
|
70 | PieSliceData m_data; |
General Comments 0
You need to be logged in to leave comments.
Login now