@@ -145,7 +145,7 QPointF PieSliceItem::sliceCenter(QPointF point, qreal radius, QPieSlice *slice) | |||
|
145 | 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 | 150 | // calculate center angle |
|
151 | 151 | *centerAngle = startAngle + (angleSpan/2); |
@@ -167,12 +167,20 QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAn | |||
|
167 | 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 | 179 | qreal dx = qSin(angle*(PI/180)) * length; |
|
173 | 180 | qreal dy = -qCos(angle*(PI/180)) * length; |
|
174 | 181 | QPointF parm1 = start + QPointF(dx, dy); |
|
175 | 182 | |
|
183 | // line to underline the label | |
|
176 | 184 | QPointF parm2 = parm1; |
|
177 | 185 | if (angle < 180) { // arm swings the other way on the left side |
|
178 | 186 | parm2 += QPointF(textWidth, 0); |
@@ -184,7 +192,7 QPainterPath PieSliceItem::labelArmPath(QPointF start, qreal angle, qreal length | |||
|
184 | 192 | } |
|
185 | 193 | |
|
186 | 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 | 197 | QPainterPath path; |
|
190 | 198 | path.moveTo(start); |
@@ -62,9 +62,9 public: | |||
|
62 | 62 | void setSliceData(PieSliceData sliceData); |
|
63 | 63 | void updateGeometry(); |
|
64 | 64 | static QPointF sliceCenter(QPointF point, qreal radius, QPieSlice *slice); |
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
|
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); | |
|
67 | QRectF labelTextRect(QFont font, QString text); | |
|
68 | 68 | |
|
69 | 69 | private: |
|
70 | 70 | PieSliceData m_data; |
General Comments 0
You need to be logged in to leave comments.
Login now