summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativetext.cpp
diff options
context:
space:
mode:
authorJoona Petrell <joona.t.petrell@nokia.com>2011-03-08 08:05:25 (GMT)
committerJoona Petrell <joona.t.petrell@nokia.com>2011-03-09 07:40:27 (GMT)
commitaeb330e3999ef3d7ae8d94b9330471f2a2a13554 (patch)
treeca612930c19dba6464d7af163a04405282d51cfb /src/declarative/graphicsitems/qdeclarativetext.cpp
parent0d6ce63ea84b076efbebfae0f6f39f492d8d7bcf (diff)
downloadQt-aeb330e3999ef3d7ae8d94b9330471f2a2a13554.zip
Qt-aeb330e3999ef3d7ae8d94b9330471f2a2a13554.tar.gz
Qt-aeb330e3999ef3d7ae8d94b9330471f2a2a13554.tar.bz2
Fix horizontal alignment of QTextDocument-based RTL text
Task-number: QTBUG-15880 Reviewed-by: Martin Jones Change-Id: If537d7c795dec46eedee62511e75bab862676ef1
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativetext.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index 3b5be9e..fdc1a71 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -50,7 +50,6 @@
#include <QTextLayout>
#include <QTextLine>
#include <QTextDocument>
-#include <QTextCursor>
#include <QGraphicsSceneMouseEvent>
#include <QPainter>
#include <QAbstractTextDocumentLayout>
@@ -102,7 +101,7 @@ QDeclarativeTextPrivate::QDeclarativeTextPrivate()
format(QDeclarativeText::AutoText), wrapMode(QDeclarativeText::NoWrap), lineHeight(1),
lineHeightMode(QDeclarativeText::ProportionalHeight), lineCount(1), truncated(false), maximumLineCount(INT_MAX),
maximumLineCountValid(false), imageCacheDirty(true), updateOnComponentComplete(true), richText(false), singleline(false),
- cacheAllTextAsImage(true), internalWidthUpdate(false), requireImplicitWidth(false), hAlignImplicit(true), naturalWidth(0), doc(0)
+ cacheAllTextAsImage(true), internalWidthUpdate(false), requireImplicitWidth(false), hAlignImplicit(true), rightToLeftText(false), naturalWidth(0), doc(0)
{
cacheAllTextAsImage = enableImageCache();
QGraphicsItemPrivate::acceptedMouseButtons = Qt::LeftButton;
@@ -292,8 +291,16 @@ void QDeclarativeTextPrivate::updateSize()
singleline = false; // richtext can't elide or be optimized for single-line case
ensureDoc();
doc->setDefaultFont(font);
+
+ QDeclarativeText::HAlignment horizontalAlignment = q->effectiveHAlign();
+ if (rightToLeftText) {
+ if (horizontalAlignment == QDeclarativeText::AlignLeft)
+ horizontalAlignment = QDeclarativeText::AlignRight;
+ else if (horizontalAlignment == QDeclarativeText::AlignRight)
+ horizontalAlignment = QDeclarativeText::AlignLeft;
+ }
QTextOption option;
- option.setAlignment((Qt::Alignment)int(q->effectiveHAlign() | vAlign));
+ option.setAlignment((Qt::Alignment)int(horizontalAlignment | vAlign));
option.setWrapMode(QTextOption::WrapMode(wrapMode));
doc->setDefaultTextOption(option);
if (requireImplicitWidth && q->widthValid()) {
@@ -909,15 +916,18 @@ void QDeclarativeText::setText(const QString &n)
return;
d->richText = d->format == RichText || (d->format == AutoText && Qt::mightBeRichText(n));
- if (d->richText && isComponentComplete()) {
- d->ensureDoc();
- d->doc->setText(n);
- }
-
d->text = n;
- d->determineHorizontalAlignment();
+ if (isComponentComplete()) {
+ if (d->richText) {
+ d->ensureDoc();
+ d->doc->setText(n);
+ d->rightToLeftText = d->doc->toPlainText().isRightToLeft();
+ } else {
+ d->rightToLeftText = d->text.isRightToLeft();
+ }
+ d->determineHorizontalAlignment();
+ }
d->updateLayout();
-
emit textChanged(d->text);
}
@@ -1122,9 +1132,8 @@ bool QDeclarativeTextPrivate::determineHorizontalAlignment()
{
Q_Q(QDeclarativeText);
if (hAlignImplicit && q->isComponentComplete()) {
- // if no explicit alignment has been set, follow the natural layout direction of the text
- bool isRightToLeft = text.isEmpty() ? QApplication::keyboardInputDirection() == Qt::RightToLeft : text.isRightToLeft();
- return setHAlign(isRightToLeft ? QDeclarativeText::AlignRight : QDeclarativeText::AlignLeft);
+ bool alignToRight = text.isEmpty() ? QApplication::keyboardInputDirection() == Qt::RightToLeft : rightToLeftText;
+ return setHAlign(alignToRight ? QDeclarativeText::AlignRight : QDeclarativeText::AlignLeft);
}
return false;
}
@@ -1140,6 +1149,11 @@ void QDeclarativeTextPrivate::mirrorChange()
}
}
+QTextDocument *QDeclarativeTextPrivate::textDocument()
+{
+ return doc;
+}
+
QDeclarativeText::VAlignment QDeclarativeText::vAlign() const
{
Q_D(const QDeclarativeText);
@@ -1585,11 +1599,14 @@ void QDeclarativeText::componentComplete()
QDeclarativeItem::componentComplete();
if (d->updateOnComponentComplete) {
d->updateOnComponentComplete = false;
- d->determineHorizontalAlignment();
if (d->richText) {
d->ensureDoc();
d->doc->setText(d->text);
+ d->rightToLeftText = d->doc->toPlainText().isRightToLeft();
+ } else {
+ d->rightToLeftText = d->text.isRightToLeft();
}
+ d->determineHorizontalAlignment();
d->updateLayout();
}
}