From dfd05e587e3177615d8280f18a447329ac794be7 2013-09-09 06:47:05 From: Titta Heikkala Date: 2013-09-09 06:47:05 Subject: [PATCH] Fix multiline alignment For multiline texts the alignment can be set in the following way: - title: axisY->setTitleText("

Sunspotscount"); - label format: axisX->setFormat("

dd-MM-yyyyh:mm

"); Task-number: QTRD-2058 Change-Id: Ic7afd29ed3b1f9d1cd2f424888196ce743acd8eb Reviewed-by: Miikka Heikkinen --- diff --git a/src/axis/horizontalaxis.cpp b/src/axis/horizontalaxis.cpp index 4aef626..06122db 100644 --- a/src/axis/horizontalaxis.cpp +++ b/src/axis/horizontalaxis.cpp @@ -77,6 +77,7 @@ void HorizontalAxis::updateGeometry() title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), gridRect.width(), titleSpace, titleBoundingRect)); + title->setTextWidth(titleBoundingRect.width()); titleBoundingRect = title->boundingRect(); @@ -106,9 +107,13 @@ void HorizontalAxis::updateGeometry() labelItem->setHtml(text); } else { qreal labelWidth = axisRect.width() / layout.count() - (2 * labelPadding()); - labelItem->setHtml(ChartPresenter::truncatedText(axis()->labelsFont(), text, - axis()->labelsAngle(), labelWidth, - availableSpace, boundingRect)); + QString truncatedText = ChartPresenter::truncatedText(axis()->labelsFont(), text, + axis()->labelsAngle(), + labelWidth, + availableSpace, boundingRect); + labelItem->setTextWidth(ChartPresenter::textBoundingRect(axis()->labelsFont(), + truncatedText).width()); + labelItem->setHtml(truncatedText); } //label transformation origin point diff --git a/src/axis/polarchartaxisangular.cpp b/src/axis/polarchartaxisangular.cpp index 69af03c..9fa99ac 100644 --- a/src/axis/polarchartaxisangular.cpp +++ b/src/axis/polarchartaxisangular.cpp @@ -120,11 +120,14 @@ void PolarChartAxisAngular::updateGeometry() // Angular axis label if (axis()->labelsVisible() && labelVisible) { + QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), + labelList.at(i), + axis()->labelsAngle()); + labelItem->setTextWidth(boundingRect.width()); labelItem->setHtml(labelList.at(i)); const QRectF &rect = labelItem->boundingRect(); QPointF labelCenter = rect.center(); labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y()); - QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle()); boundingRect.moveCenter(labelCenter); QPointF positionDiff(rect.topLeft() - boundingRect.topLeft()); @@ -221,13 +224,14 @@ void PolarChartAxisAngular::updateGeometry() // Title, centered above the chart QString titleText = axis()->titleText(); if (!titleText.isEmpty() && axis()->isTitleVisible()) { - QRectF dummyRect; + QRectF truncatedRect; qreal availableTitleHeight = axisGeometry().height() - labelPadding() - titlePadding() * 2.0; qreal minimumLabelHeight = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...").height(); availableTitleHeight -= minimumLabelHeight; title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), axisGeometry().width(), availableTitleHeight, - dummyRect)); + truncatedRect)); + title->setTextWidth(truncatedRect.width()); QRectF titleBoundingRect = title->boundingRect(); QPointF titleCenter = center - titleBoundingRect.center(); diff --git a/src/axis/polarchartaxisradial.cpp b/src/axis/polarchartaxisradial.cpp index 2587b91..53544fd 100644 --- a/src/axis/polarchartaxisradial.cpp +++ b/src/axis/polarchartaxisradial.cpp @@ -107,11 +107,14 @@ void PolarChartAxisRadial::updateGeometry() // Radial axis label if (axis()->labelsVisible() && labelVisible) { + QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), + labelList.at(i), + axis()->labelsAngle()); + labelItem->setTextWidth(boundingRect.width()); labelItem->setHtml(labelList.at(i)); QRectF labelRect = labelItem->boundingRect(); QPointF labelCenter = labelRect.center(); labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y()); - QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle()); boundingRect.moveCenter(labelCenter); QPointF positionDiff(labelRect.topLeft() - boundingRect.topLeft()); QPointF labelPoint = center; @@ -204,9 +207,10 @@ void PolarChartAxisRadial::updateGeometry() // Title, along the 0 axis QString titleText = axis()->titleText(); if (!titleText.isEmpty() && axis()->isTitleVisible()) { - QRectF dummyRect; + QRectF truncatedRect; title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), - radius, radius, dummyRect)); + radius, radius, truncatedRect)); + title->setTextWidth(truncatedRect.width()); QRectF titleBoundingRect = title->boundingRect(); QPointF titleCenter = titleBoundingRect.center(); diff --git a/src/axis/verticalaxis.cpp b/src/axis/verticalaxis.cpp index 2986b51..9cf80b3 100644 --- a/src/axis/verticalaxis.cpp +++ b/src/axis/verticalaxis.cpp @@ -78,6 +78,7 @@ void VerticalAxis::updateGeometry() title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(90.0), titleSpace, gridRect.height(), titleBoundingRect)); + title->setTextWidth(titleBoundingRect.height()); titleBoundingRect = title->boundingRect(); @@ -110,9 +111,13 @@ void VerticalAxis::updateGeometry() labelItem->setHtml(text); } else { qreal labelHeight = (axisRect.height() / layout.count()) - (2 * labelPadding()); - labelItem->setHtml(ChartPresenter::truncatedText(axis()->labelsFont(), text, - axis()->labelsAngle(), availableSpace, - labelHeight, boundingRect)); + QString truncatedText = ChartPresenter::truncatedText(axis()->labelsFont(), text, + axis()->labelsAngle(), + availableSpace, + labelHeight, boundingRect); + labelItem->setTextWidth(ChartPresenter::textBoundingRect(axis()->labelsFont(), + truncatedText).width()); + labelItem->setHtml(truncatedText); } //label transformation origin point diff --git a/src/charttitle.cpp b/src/charttitle.cpp index d6fd0e0..b65e037 100644 --- a/src/charttitle.cpp +++ b/src/charttitle.cpp @@ -50,10 +50,11 @@ QString ChartTitle::text() const void ChartTitle::setGeometry(const QRectF &rect) { - QRectF dummyRect; + QRectF truncatedRect; QGraphicsTextItem::setHtml(ChartPresenter::truncatedText(font(), m_text, qreal(0.0), rect.width(), rect.height(), - dummyRect)); + truncatedRect)); + QGraphicsTextItem::setTextWidth(truncatedRect.width()); setPos(rect.topLeft()); } diff --git a/src/legend/legendmarkeritem.cpp b/src/legend/legendmarkeritem.cpp index 0fe48a9..c74b151 100644 --- a/src/legend/legendmarkeritem.cpp +++ b/src/legend/legendmarkeritem.cpp @@ -118,6 +118,7 @@ void LegendMarkerItem::setGeometry(const QRectF &rect) m_textItem->setHtml(ChartPresenter::truncatedText(m_textItem->font(), m_label, qreal(0.0), width - x, rect.height(), truncatedRect)); + m_textItem->setTextWidth(truncatedRect.width()); qreal y = qMax(m_markerRect.height() + 2 * m_margin, truncatedRect.height() + 2 * m_margin);