##// END OF EJS Templates
pieslice: fix slice labels turning the wrong way...
Jani Honkonen -
r1327:39a357025ee6
parent child
Show More
@@ -31,12 +31,10
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 #define PI 3.14159265 // TODO: is this defined in some header?
35
36 QPointF offset(qreal angle, qreal length)
34 QPointF offset(qreal angle, qreal length)
37 {
35 {
38 qreal dx = qSin(angle*(PI/180)) * length;
36 qreal dx = qSin(angle*(M_PI/180)) * length;
39 qreal dy = qCos(angle*(PI/180)) * length;
37 qreal dy = qCos(angle*(M_PI/180)) * length;
40 return QPointF(dx, -dy);
38 return QPointF(dx, -dy);
41 }
39 }
42
40
@@ -149,9 +147,7 QPointF PieSliceItem::sliceCenter(QPointF point, qreal radius, QPieSlice *slice)
149 if (slice->isExploded()) {
147 if (slice->isExploded()) {
150 qreal centerAngle = slice->startAngle() + (slice->angleSpan()/2);
148 qreal centerAngle = slice->startAngle() + (slice->angleSpan()/2);
151 qreal len = radius * slice->explodeDistanceFactor();
149 qreal len = radius * slice->explodeDistanceFactor();
152 qreal dx = qSin(centerAngle*(PI/180)) * len;
150 point += offset(centerAngle, len);
153 qreal dy = -qCos(centerAngle*(PI/180)) * len;
154 point += QPointF(dx, dy);
155 }
151 }
156 return point;
152 return point;
157 }
153 }
@@ -180,6 +176,18 QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAn
180
176
181 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)
182 {
178 {
179 // Normalize the angle to 0-360 range
180 // NOTE: We are using int here on purpose. Depenging on platform and hardware
181 // qreal can be a double, float or something the user gives to the Qt configure
182 // (QT_COORD_TYPE). Compilers do not seem to support modulo for double or float
183 // but there are fmod() and fmodf() functions for that. So instead of some #ifdef
184 // that might break we just use int. Precision for this is just fine for our needs.
185 int normalized = angle * 10.0;
186 normalized = normalized % 3600;
187 if (normalized < 0)
188 normalized += 3600;
189 angle = (qreal) normalized / 10.0;
190
183 // prevent label arm pointing straight down because it will look bad
191 // prevent label arm pointing straight down because it will look bad
184 if (angle < 180 && angle > 170)
192 if (angle < 180 && angle > 170)
185 angle = 170;
193 angle = 170;
@@ -187,9 +195,7 QPainterPath PieSliceItem::labelArmPath(QPointF start, qreal angle, qreal length
187 angle = 190;
195 angle = 190;
188
196
189 // line from slice to label
197 // line from slice to label
190 qreal dx = qSin(angle*(PI/180)) * length;
198 QPointF parm1 = start + offset(angle, length);
191 qreal dy = -qCos(angle*(PI/180)) * length;
192 QPointF parm1 = start + QPointF(dx, dy);
193
199
194 // line to underline the label
200 // line to underline the label
195 QPointF parm2 = parm1;
201 QPointF parm2 = parm1;
General Comments 0
You need to be logged in to leave comments. Login now