summaryrefslogtreecommitdiffstats
path: root/src/gui/painting
diff options
context:
space:
mode:
authorJiang Jiang <jiang.jiang@nokia.com>2011-03-30 12:55:34 (GMT)
committerJiang Jiang <jiang.jiang@nokia.com>2011-03-31 08:54:41 (GMT)
commitb92a31da01ee50fed4b10282e79f812167faf659 (patch)
tree9197678d184a459ca5ffe858b59b07b4272bb6f7 /src/gui/painting
parent918b0fbd8673d3d6d74c655207e9b1688357254b (diff)
downloadQt-b92a31da01ee50fed4b10282e79f812167faf659.zip
Qt-b92a31da01ee50fed4b10282e79f812167faf659.tar.gz
Qt-b92a31da01ee50fed4b10282e79f812167faf659.tar.bz2
Fix horizontal centered text drawing without word wrap
In this case we can't use line width to align the text, we have to use the rectangle width given in QPainter::drawText for alignment instead. Reviewed-by: Eskil
Diffstat (limited to 'src/gui/painting')
-rw-r--r--src/gui/painting/qpainter.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index 14fb772..64ef549 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -8149,10 +8149,6 @@ start_lengthVariant:
engine.option.setTextDirection(layout_direction);
if (tf & Qt::AlignJustify)
engine.option.setAlignment(Qt::AlignJustify);
- else if (tf & Qt::AlignRight)
- engine.option.setAlignment(Qt::AlignRight);
- else if (tf & Qt::AlignHCenter)
- engine.option.setAlignment(Qt::AlignHCenter);
else
engine.option.setAlignment(Qt::AlignLeft); // do not do alignment twice
@@ -8248,7 +8244,18 @@ start_lengthVariant:
for (int i = 0; i < textLayout.lineCount(); i++) {
QTextLine line = textLayout.lineAt(i);
- line.draw(painter, QPointF(r.x(), r.y() + yoff));
+
+ qreal advance = line.horizontalAdvance();
+ xoff = 0;
+ if (tf & Qt::AlignRight) {
+ QTextEngine *eng = textLayout.engine();
+ xoff = r.width() - advance -
+ eng->leadingSpaceWidth(eng->lines[line.lineNumber()]).toReal();
+ }
+ else if (tf & Qt::AlignHCenter)
+ xoff = (r.width() - advance) / 2;
+
+ line.draw(painter, QPointF(r.x() + xoff, r.y() + yoff));
}
if (restore) {