##// END OF EJS Templates
Fix legend markers truncation...
Miikka Heikkinen -
r2544:9f0ff996f528
parent child
Show More
@@ -110,11 +110,11 QBrush LegendMarkerItem::labelBrush() const
110
110
111 void LegendMarkerItem::setGeometry(const QRectF &rect)
111 void LegendMarkerItem::setGeometry(const QRectF &rect)
112 {
112 {
113 int width = rect.width();
113 qreal width = rect.width();
114 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
114 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
115 QRectF truncatedRect;
115 QRectF truncatedRect;
116
116
117 m_textItem->setHtml(ChartPresenter::truncatedText(m_font, m_label, qreal(0.0), width - x, Qt::Horizontal, truncatedRect));
117 m_textItem->setHtml(ChartPresenter::truncatedText(m_textItem->font(), m_label, qreal(0.0), width - x, Qt::Horizontal, truncatedRect));
118
118
119 qreal y = qMax(m_markerRect.height() + 2 * m_margin, truncatedRect.height() + 2 * m_margin);
119 qreal y = qMax(m_markerRect.height() + 2 * m_margin, truncatedRect.height() + 2 * m_margin);
120
120
@@ -144,21 +144,26 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint)
144 {
144 {
145 Q_UNUSED(constraint)
145 Q_UNUSED(constraint)
146
146
147 QFontMetrics fn(m_textItem->font());
148 QSizeF sh;
147 QSizeF sh;
149
148
150 switch (which) {
149 switch (which) {
151 case Qt::MinimumSize:
150 case Qt::MinimumSize: {
152 sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
151 QRectF labelRect = ChartPresenter::textBoundingRect(m_textItem->font(), "...");
153 break;
152 sh = QSizeF(labelRect.width() + (2.0 * m_margin) + m_space + m_markerRect.width(),
154 case Qt::PreferredSize:
153 qMax(m_markerRect.height(), labelRect.height()) + (2.0 * m_margin));
155 sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
154 break;
156 break;
155 }
157 default:
156 case Qt::PreferredSize: {
158 break;
157 QRectF labelRect = ChartPresenter::textBoundingRect(m_textItem->font(), m_label);
159 }
158 sh = QSizeF(labelRect.width() + (2.0 * m_margin) + m_space + m_markerRect.width(),
160
159 qMax(m_markerRect.height(), labelRect.height()) + (2.0 * m_margin));
161 return sh;
160 break;
161 }
162 default:
163 break;
164 }
165
166 return sh;
162 }
167 }
163
168
164 void LegendMarkerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
169 void LegendMarkerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
@@ -85,7 +85,6 protected:
85 QString m_label;
85 QString m_label;
86
86
87 QBrush m_labelBrush;
87 QBrush m_labelBrush;
88 QFont m_font;
89 QPen m_pen;
88 QPen m_pen;
90 QBrush m_brush;
89 QBrush m_brush;
91 bool m_hovering;
90 bool m_hovering;
General Comments 0
You need to be logged in to leave comments. Login now