diff options
author | Christopher Ham <christopher.ham@nokia.com> | 2011-01-28 03:32:25 (GMT) |
---|---|---|
committer | Christopher Ham <christopher.ham@nokia.com> | 2011-01-28 03:32:25 (GMT) |
commit | 64c0ee4e5f1f05105ab6168ebb4cb188e8fd838f (patch) | |
tree | 2e0ffdfb7c9dbf702eed0609ebe46b77339b97e7 /src/declarative/graphicsitems/qdeclarativetext.cpp | |
parent | 57ddd7c69705dfbf3d06b8a0157e5e706120c818 (diff) | |
download | Qt-64c0ee4e5f1f05105ab6168ebb4cb188e8fd838f.zip Qt-64c0ee4e5f1f05105ab6168ebb4cb188e8fd838f.tar.gz Qt-64c0ee4e5f1f05105ab6168ebb4cb188e8fd838f.tar.bz2 |
Fixing right-to-left text in Text and TextInput
The Text and TextInput items should now automatically flip the
alignment of right-to-left text. Autotests also added to ensure the
text is on the correct side (added for TextInput also).
Task-number: QTBUG-15880
Reviewed-by: Martin Jones
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativetext.cpp')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativetext.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 1e0988d..5edfc31 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -268,7 +268,8 @@ void QDeclarativeTextPrivate::updateSize() singleline = false; // richtext can't elide or be optimized for single-line case ensureDoc(); doc->setDefaultFont(font); - QTextOption option((Qt::Alignment)int(hAlign | vAlign)); + QTextOption option; + option.setAlignment((Qt::Alignment)int(hAlign | vAlign)); option.setWrapMode(QTextOption::WrapMode(wrapMode)); doc->setDefaultTextOption(option); if (requireImplicitWidth && q->widthValid()) { @@ -341,6 +342,17 @@ QSize QDeclarativeTextPrivate::setupTextLayout() textOption.setWrapMode(QTextOption::WrapMode(wrapMode)); layout.setTextOption(textOption); + QDeclarativeText::HAlignment hAlignment = hAlign; + if(text.isRightToLeft()) { + if ((hAlign == QDeclarativeText::AlignLeft) || (hAlign == QDeclarativeText::AlignJustify)) { + hAlignment = QDeclarativeText::AlignRight; + } else if (hAlign == QDeclarativeText::AlignRight) { + hAlignment = QDeclarativeText::AlignLeft; + } else { + hAlignment = hAlign; + } + } + bool elideText = false; bool truncate = false; @@ -386,9 +398,9 @@ QSize QDeclarativeTextPrivate::setupTextLayout() // Need to correct for alignment line.setLineWidth(lineWidth-elideWidth); int x = line.naturalTextWidth(); - if (hAlign == QDeclarativeText::AlignRight) { + if (hAlignment == QDeclarativeText::AlignRight) { x = q->width()-elideWidth; - } else if (hAlign == QDeclarativeText::AlignHCenter) { + } else if (hAlignment == QDeclarativeText::AlignHCenter) { x = (q->width()+line.naturalTextWidth()-elideWidth)/2; } elidePos = QPointF(x, y + fm.ascent()); @@ -435,13 +447,13 @@ QSize QDeclarativeTextPrivate::setupTextLayout() height += line.height(); if (!cacheAllTextAsImage) { - if ((hAlign == QDeclarativeText::AlignLeft) || (hAlign == QDeclarativeText::AlignJustify)) { + if ((hAlignment == QDeclarativeText::AlignLeft) || (hAlignment == QDeclarativeText::AlignJustify)) { x = 0; - } else if (hAlign == QDeclarativeText::AlignRight) { + } else if (hAlignment == QDeclarativeText::AlignRight) { x = layoutWidth - line.naturalTextWidth(); if (elideText && i == layout.lineCount()-1) x -= elideWidth; // Correct for when eliding multilines - } else if (hAlign == QDeclarativeText::AlignHCenter) { + } else if (hAlignment == QDeclarativeText::AlignHCenter) { x = (layoutWidth - line.naturalTextWidth()) / 2; if (elideText && i == layout.lineCount()-1) x -= elideWidth/2; // Correct for when eliding multilines |