summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2013-05-31 14:37:41 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2013-06-03 08:07:33 +0300
commit9f0ff996f5284ca0b814e5c7eb52940dd5511f42 (patch)
tree166e6f90108775e7d2964765da665dc9f0e4b93e /src
parent979fe974d5e4faec3ff09d892ec990ba4e564a90 (diff)
Fix legend markers truncation
Geometry calculation was using different font than sizehint calculation. Also, sizehint calculation was still using QFontMetrics instead of textBoundingRect(). Task-number: QTRD-1927 Change-Id: Ibfda7847cbc1f8e22377b01a4fdd946095302aba Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/legend/legendmarkeritem.cpp35
-rw-r--r--src/legend/legendmarkeritem_p.h1
2 files changed, 20 insertions, 16 deletions
diff --git a/src/legend/legendmarkeritem.cpp b/src/legend/legendmarkeritem.cpp
index 9586ba12..533308d3 100644
--- a/src/legend/legendmarkeritem.cpp
+++ b/src/legend/legendmarkeritem.cpp
@@ -110,11 +110,11 @@ QBrush LegendMarkerItem::labelBrush() const
void LegendMarkerItem::setGeometry(const QRectF &rect)
{
- int width = rect.width();
+ qreal width = rect.width();
qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
QRectF truncatedRect;
- m_textItem->setHtml(ChartPresenter::truncatedText(m_font, m_label, qreal(0.0), width - x, Qt::Horizontal, truncatedRect));
+ m_textItem->setHtml(ChartPresenter::truncatedText(m_textItem->font(), m_label, qreal(0.0), width - x, Qt::Horizontal, truncatedRect));
qreal y = qMax(m_markerRect.height() + 2 * m_margin, truncatedRect.height() + 2 * m_margin);
@@ -144,21 +144,26 @@ QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint)
{
Q_UNUSED(constraint)
- QFontMetrics fn(m_textItem->font());
QSizeF sh;
- switch (which) {
- case Qt::MinimumSize:
- 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));
- break;
- case Qt::PreferredSize:
- 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));
- break;
- default:
- break;
- }
-
- return sh;
+ switch (which) {
+ case Qt::MinimumSize: {
+ QRectF labelRect = ChartPresenter::textBoundingRect(m_textItem->font(), "...");
+ sh = QSizeF(labelRect.width() + (2.0 * m_margin) + m_space + m_markerRect.width(),
+ qMax(m_markerRect.height(), labelRect.height()) + (2.0 * m_margin));
+ break;
+ }
+ case Qt::PreferredSize: {
+ QRectF labelRect = ChartPresenter::textBoundingRect(m_textItem->font(), m_label);
+ sh = QSizeF(labelRect.width() + (2.0 * m_margin) + m_space + m_markerRect.width(),
+ qMax(m_markerRect.height(), labelRect.height()) + (2.0 * m_margin));
+ break;
+ }
+ default:
+ break;
+ }
+
+ return sh;
}
void LegendMarkerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
diff --git a/src/legend/legendmarkeritem_p.h b/src/legend/legendmarkeritem_p.h
index 2f7340f7..e9d37176 100644
--- a/src/legend/legendmarkeritem_p.h
+++ b/src/legend/legendmarkeritem_p.h
@@ -85,7 +85,6 @@ protected:
QString m_label;
QBrush m_labelBrush;
- QFont m_font;
QPen m_pen;
QBrush m_brush;
bool m_hovering;