summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems
diff options
context:
space:
mode:
authorChristopher Ham <christopher.ham@nokia.com>2011-01-28 03:32:25 (GMT)
committerChristopher Ham <christopher.ham@nokia.com>2011-01-28 03:32:25 (GMT)
commit64c0ee4e5f1f05105ab6168ebb4cb188e8fd838f (patch)
tree2e0ffdfb7c9dbf702eed0609ebe46b77339b97e7 /src/declarative/graphicsitems
parent57ddd7c69705dfbf3d06b8a0157e5e706120c818 (diff)
downloadQt-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')
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp24
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext_p_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp15
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p_p.h6
4 files changed, 35 insertions, 12 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
diff --git a/src/declarative/graphicsitems/qdeclarativetext_p_p.h b/src/declarative/graphicsitems/qdeclarativetext_p_p.h
index bae2d85..01e0ab5 100644
--- a/src/declarative/graphicsitems/qdeclarativetext_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetext_p_p.h
@@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE
class QTextLayout;
class QTextDocumentWithImageResources;
-class QDeclarativeTextPrivate : public QDeclarativeImplicitSizeItemPrivate
+class Q_AUTOTEST_EXPORT QDeclarativeTextPrivate : public QDeclarativeImplicitSizeItemPrivate
{
Q_DECLARE_PUBLIC(QDeclarativeText)
public:
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 911c68c..3d2466d 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -51,6 +51,7 @@
#include <QFontMetrics>
#include <QPainter>
#include <QTextBoundaryFinder>
+#include <qstyle.h>
#ifndef QT_NO_LINEEDIT
@@ -1094,10 +1095,11 @@ void QDeclarativeTextInputPrivate::updateHorizontalScroll()
int cix = qRound(control->cursorToX());
QRect br(q->boundingRect().toRect());
int widthUsed = calculateTextWidth();
+ Qt::Alignment va = QStyle::visualAlignment(control->layoutDirection(), QFlag(Qt::Alignment(hAlign)));
if (autoScroll) {
if (widthUsed <= br.width()) {
// text fits in br; use hscroll for alignment
- switch (hAlign & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
+ switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
case Qt::AlignRight:
hscroll = widthUsed - br.width() - 1;
break;
@@ -1121,12 +1123,17 @@ void QDeclarativeTextInputPrivate::updateHorizontalScroll()
hscroll = widthUsed - br.width() + 1;
}
} else {
- if(hAlign == QDeclarativeTextInput::AlignRight){
+ switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
+ case Qt::AlignRight:
hscroll = q->width() - widthUsed;
- }else if(hAlign == QDeclarativeTextInput::AlignHCenter){
+ break;
+ case Qt::AlignHCenter:
hscroll = (q->width() - widthUsed) / 2;
- } else {
+ break;
+ default:
+ // Left
hscroll = 0;
+ break;
}
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
index 9644410..1f45c11 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
@@ -66,7 +66,7 @@
QT_BEGIN_NAMESPACE
-class QDeclarativeTextInputPrivate : public QDeclarativeImplicitSizePaintedItemPrivate
+class Q_AUTOTEST_EXPORT QDeclarativeTextInputPrivate : public QDeclarativeImplicitSizePaintedItemPrivate
{
Q_DECLARE_PUBLIC(QDeclarativeTextInput)
public:
@@ -132,6 +132,10 @@ public:
bool autoScroll;
bool selectByMouse;
bool canPaste;
+
+ static inline QDeclarativeTextInputPrivate *get(QDeclarativeTextInput *t) {
+ return t->d_func();
+ }
};
QT_END_NAMESPACE