diff options
author | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2019-03-20 09:38:31 +0200 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@qt.io> | 2019-03-20 09:01:39 +0000 |
commit | 1204de9281bccedf2c877eaaa4ae06343d69747c (patch) | |
tree | 2bdbd1bbdd46752e889d0a895fe6472c6ffd9846 | |
parent | 667f031953b94714f77765405905e6636fee038c (diff) |
Fix text alignment with fixed size text area
Task-number: QT3DS-3137
Change-Id: Ie9758698a35e936c7c8c651b0d42196fd167e48c
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Janne Kangas <janne.kangas@qt.io>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r-- | src/runtime/q3dstextrenderer.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/runtime/q3dstextrenderer.cpp b/src/runtime/q3dstextrenderer.cpp index cddca08..443a50c 100644 --- a/src/runtime/q3dstextrenderer.cpp +++ b/src/runtime/q3dstextrenderer.cpp @@ -195,6 +195,7 @@ void Q3DSTextRenderer::renderText(QPainter *painter, Q3DSTextNode *text3DS) { Q3DSTextRenderer::Font *font = findFont(text3DS->font()); Q_ASSERT(font); + int horizontalAlignmentFlag = Qt::AlignLeft; updateFontInfo(font, text3DS); @@ -229,9 +230,11 @@ void Q3DSTextRenderer::renderText(QPainter *painter, Q3DSTextNode *text3DS) qreal tracking = 0.0; switch (text3DS->horizontalAlignment()) { case Q3DSTextNode::Center: + horizontalAlignmentFlag = Qt::AlignHCenter; tracking += qreal(text3DS->tracking()) / 2.0; break; case Q3DSTextNode::Right: + horizontalAlignmentFlag = Qt::AlignRight; tracking += qreal(text3DS->tracking()); break; case Q3DSTextNode::Left: @@ -303,12 +306,12 @@ void Q3DSTextRenderer::renderText(QPainter *painter, Q3DSTextNode *text3DS) qreal(lineWidths.at(i)), lineHeight); // shadow is a darker shade of the given font color painter->setPen(QColor(shadowRgb, shadowRgb, shadowRgb)); - painter->drawText(boundShadow, mapVertAlign(text3DS) | wordWrapFlags | Qt::AlignLeft, - line, &actualBound); + painter->drawText(boundShadow, mapVertAlign(text3DS) | wordWrapFlags + | horizontalAlignmentFlag, line, &actualBound); painter->setPen(Qt::white); // coloring is done in the shader } - painter->drawText(bound, mapVertAlign(text3DS) | wordWrapFlags | Qt::AlignLeft, line, - &actualBound); + painter->drawText(bound, mapVertAlign(text3DS) | wordWrapFlags | horizontalAlignmentFlag, + line, &actualBound); nextHeight += lineHeight + qreal(text3DS->leading()); } } |