##// END OF EJS Templates
Fix pie chart label clipping...
Titta Heikkala -
r2596:1427ecd2e391
parent child
Show More
@@ -85,11 +85,20 void PieSliceItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
85 painter->setBrush(m_data.m_labelBrush);
85 painter->setBrush(m_data.m_labelBrush);
86 painter->setFont(m_data.m_labelFont);
86 painter->setFont(m_data.m_labelFont);
87
87
88 QFontMetricsF fm(m_data.m_labelFont);
89 QString label = m_data.m_labelText;
90 QRectF labelBoundingRect;
91
88 switch (m_data.m_labelPosition) {
92 switch (m_data.m_labelPosition) {
89 case QPieSlice::LabelOutside:
93 case QPieSlice::LabelOutside:
90 painter->setClipRect(parentItem()->boundingRect());
94 painter->setClipRect(parentItem()->boundingRect());
91 painter->strokePath(m_labelArmPath, m_data.m_labelBrush.color());
95 painter->strokePath(m_labelArmPath, m_data.m_labelBrush.color());
92 painter->drawText(m_labelTextRect, Qt::AlignCenter, m_data.m_labelText);
96 if (fm.width(m_data.m_labelText) > m_labelTextRect.width()) {
97 label = ChartPresenter::truncatedText(m_data.m_labelFont, m_data.m_labelText,
98 qreal(0.0), m_labelTextRect.width(),
99 Qt::Horizontal, labelBoundingRect);
100 }
101 painter->drawText(m_labelTextRect, Qt::AlignCenter, label);
93 break;
102 break;
94 case QPieSlice::LabelInsideHorizontal:
103 case QPieSlice::LabelInsideHorizontal:
95 painter->setClipPath(m_slicePath);
104 painter->setClipPath(m_slicePath);
@@ -165,6 +174,10 void PieSliceItem::updateGeometry()
165 switch (m_data.m_labelPosition) {
174 switch (m_data.m_labelPosition) {
166 case QPieSlice::LabelOutside:
175 case QPieSlice::LabelOutside:
167 m_labelTextRect.moveBottomLeft(labelTextStart);
176 m_labelTextRect.moveBottomLeft(labelTextStart);
177 if (m_labelTextRect.left() < 0)
178 m_labelTextRect.setLeft(0);
179 if (m_labelTextRect.right() > parentItem()->boundingRect().right())
180 m_labelTextRect.setRight(parentItem()->boundingRect().right());
168 break;
181 break;
169 case QPieSlice::LabelInsideHorizontal:
182 case QPieSlice::LabelInsideHorizontal:
170 case QPieSlice::LabelInsideTangential: {
183 case QPieSlice::LabelInsideTangential: {
General Comments 0
You need to be logged in to leave comments. Login now