summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoona Petrell <joona.t.petrell@nokia.com>2011-03-07 03:10:08 (GMT)
committerJoona Petrell <joona.t.petrell@nokia.com>2011-03-07 05:20:12 (GMT)
commit27e4302b7f45f22180693d26747f419177c81e27 (patch)
tree5d25d8460e785cd6ac3db10d2516ebd1667bf7ae /src
parent7872985cc2eb21ae9283aa8e6779f490b500dff0 (diff)
downloadQt-27e4302b7f45f22180693d26747f419177c81e27.zip
Qt-27e4302b7f45f22180693d26747f419177c81e27.tar.gz
Qt-27e4302b7f45f22180693d26747f419177c81e27.tar.bz2
Reverse horizontal alignment of QML editors when the layout mirroring is enabled
Task-number: QTBUG-15880 Reviewed-by: Martin Jones Change-Id: Ie9cebd7bc6d40f5f555bfd83ddc3a24a55c6cb4d
Diffstat (limited to 'src')
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp95
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext_p.h3
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext_p_p.h4
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit.cpp98
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit_p.h3
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit_p_p.h4
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp96
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p.h4
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p_p.h4
9 files changed, 226 insertions, 85 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index e66a83e..4a931fd 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -210,18 +210,6 @@ qreal QDeclarativeTextPrivate::implicitWidth() const
return mImplicitWidth;
}
-void QDeclarativeTextPrivate::determineHorizontalAlignment()
-{
- Q_Q(QDeclarativeText);
- if (hAlignImplicit && q->isComponentComplete()) {
- // if no explicit alignment has been set, follow the natural layout direction of the text
- QDeclarativeText::HAlignment previousAlign = hAlign;
- hAlign = text.isRightToLeft() ? QDeclarativeText::AlignRight : QDeclarativeText::AlignLeft;
- if (previousAlign != hAlign)
- emit q->horizontalAlignmentChanged(hAlign);
- }
-}
-
void QDeclarativeTextPrivate::updateLayout()
{
Q_Q(QDeclarativeText);
@@ -305,7 +293,7 @@ void QDeclarativeTextPrivate::updateSize()
ensureDoc();
doc->setDefaultFont(font);
QTextOption option;
- option.setAlignment((Qt::Alignment)int(hAlign | vAlign));
+ option.setAlignment((Qt::Alignment)int(q->effectiveHAlign() | vAlign));
option.setWrapMode(QTextOption::WrapMode(wrapMode));
doc->setDefaultTextOption(option);
if (requireImplicitWidth && q->widthValid()) {
@@ -371,7 +359,7 @@ QSize QDeclarativeTextPrivate::setupTextLayout()
lineWidth = q->width();
QTextOption textOption = layout.textOption();
- textOption.setAlignment(Qt::Alignment(hAlign));
+ textOption.setAlignment(Qt::Alignment(q->effectiveHAlign()));
textOption.setWrapMode(QTextOption::WrapMode(wrapMode));
layout.setTextOption(textOption);
@@ -1049,6 +1037,7 @@ void QDeclarativeText::setStyleColor(const QColor &color)
/*!
\qmlproperty enumeration Text::horizontalAlignment
\qmlproperty enumeration Text::verticalAlignment
+ \qmlproperty enumeration Text::effectiveHorizontalAlignment
Sets the horizontal and vertical alignment of the text within the Text items
width and height. By default, the text is vertically aligned to the top. Horizontal
@@ -1063,6 +1052,11 @@ void QDeclarativeText::setStyleColor(const QColor &color)
all alignments are equivalent. If you want the text to be, say, centered in its parent, then you will
need to either modify the Item::anchors, or set horizontalAlignment to Text.AlignHCenter and bind the width to
that of the parent.
+
+ When using the attached property LayoutMirroring::enabled to mirror application
+ layouts, the horizontal alignment of text will also be mirrored. However, the property
+ \c horizontalAlignment will remain unchanged. To query the effective horizontal alignment
+ of Text, use the read-only property \c effectiveHorizontalAlignment.
*/
QDeclarativeText::HAlignment QDeclarativeText::hAlign() const
{
@@ -1073,29 +1067,72 @@ QDeclarativeText::HAlignment QDeclarativeText::hAlign() const
void QDeclarativeText::setHAlign(HAlignment align)
{
Q_D(QDeclarativeText);
+ bool forceAlign = d->hAlignImplicit && d->effectiveLayoutMirror;
d->hAlignImplicit = false;
- if (d->hAlign == align)
- return;
-
- if (isComponentComplete())
- prepareGeometryChange();
-
- d->hAlign = align;
- d->updateLayout();
-
- emit horizontalAlignmentChanged(align);
+ if (d->setHAlign(align, forceAlign) && isComponentComplete())
+ d->updateLayout();
}
void QDeclarativeText::resetHAlign()
{
Q_D(QDeclarativeText);
d->hAlignImplicit = true;
- QDeclarativeText::HAlignment oldAlignment = d->hAlign;
- d->determineHorizontalAlignment();
- if (oldAlignment != d->hAlign) {
- prepareGeometryChange();
+ if (d->determineHorizontalAlignment() && isComponentComplete())
d->updateLayout();
- emit horizontalAlignmentChanged(d->hAlign);
+}
+
+QDeclarativeText::HAlignment QDeclarativeText::effectiveHAlign() const
+{
+ Q_D(const QDeclarativeText);
+ QDeclarativeText::HAlignment effectiveAlignment = d->hAlign;
+ if (!d->hAlignImplicit && d->effectiveLayoutMirror) {
+ switch (d->hAlign) {
+ case QDeclarativeText::AlignLeft:
+ effectiveAlignment = QDeclarativeText::AlignRight;
+ break;
+ case QDeclarativeText::AlignRight:
+ effectiveAlignment = QDeclarativeText::AlignLeft;
+ break;
+ default:
+ break;
+ }
+ }
+ return effectiveAlignment;
+}
+
+bool QDeclarativeTextPrivate::setHAlign(QDeclarativeText::HAlignment alignment, bool forceAlign)
+{
+ Q_Q(QDeclarativeText);
+ if (hAlign != alignment || forceAlign) {
+ QDeclarativeText::HAlignment oldEffectiveHAlign = q->effectiveHAlign();
+ hAlign = alignment;
+
+ emit q->horizontalAlignmentChanged(hAlign);
+ if (oldEffectiveHAlign != q->effectiveHAlign())
+ emit q->effectiveHorizontalAlignmentChanged();
+ return true;
+ }
+ return false;
+}
+
+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
+ return setHAlign(text.isRightToLeft() ? QDeclarativeText::AlignRight : QDeclarativeText::AlignLeft);
+ }
+ return false;
+}
+
+void QDeclarativeTextPrivate::mirrorChange()
+{
+ Q_Q(QDeclarativeText);
+ if (q->isComponentComplete()) {
+ if (!hAlignImplicit && (hAlign == QDeclarativeText::AlignRight || hAlign == QDeclarativeText::AlignLeft)) {
+ updateLayout();
+ emit q->effectiveHorizontalAlignmentChanged();
+ }
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativetext_p.h b/src/declarative/graphicsitems/qdeclarativetext_p.h
index 92c2eab..a1153c2 100644
--- a/src/declarative/graphicsitems/qdeclarativetext_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetext_p.h
@@ -70,6 +70,7 @@ class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeText : public QDeclarativeImplici
Q_PROPERTY(TextStyle style READ style WRITE setStyle NOTIFY styleChanged)
Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor NOTIFY styleColorChanged)
Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
+ Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged REVISION 1)
Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged REVISION 1)
@@ -134,6 +135,7 @@ public:
HAlignment hAlign() const;
void setHAlign(HAlignment align);
void resetHAlign();
+ HAlignment effectiveHAlign() const;
VAlignment vAlign() const;
void setVAlign(VAlignment align);
@@ -189,6 +191,7 @@ Q_SIGNALS:
void paintedSizeChanged();
Q_REVISION(1) void lineHeightChanged(qreal lineHeight);
Q_REVISION(1) void lineHeightModeChanged(LineHeightMode mode);
+ Q_REVISION(1) void effectiveHorizontalAlignmentChanged();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
diff --git a/src/declarative/graphicsitems/qdeclarativetext_p_p.h b/src/declarative/graphicsitems/qdeclarativetext_p_p.h
index 6886d91..0864c8f 100644
--- a/src/declarative/graphicsitems/qdeclarativetext_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetext_p_p.h
@@ -76,7 +76,9 @@ public:
void updateSize();
void updateLayout();
- void determineHorizontalAlignment();
+ bool determineHorizontalAlignment();
+ bool setHAlign(QDeclarativeText::HAlignment, bool forceAlign = false);
+ void mirrorChange();
QString text;
QFont font;
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
index e4cd66c..7a75ece 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
@@ -458,6 +458,7 @@ void QDeclarativeTextEdit::setSelectedTextColor(const QColor &color)
/*!
\qmlproperty enumeration TextEdit::horizontalAlignment
\qmlproperty enumeration TextEdit::verticalAlignment
+ \qmlproperty enumeration TextEdit::effectiveHorizontalAlignment
Sets the horizontal and vertical alignment of the text within the TextEdit item's
width and height. By default, the text alignment follows the natural alignment
@@ -476,8 +477,13 @@ void QDeclarativeTextEdit::setSelectedTextColor(const QColor &color)
\list
\o TextEdit.AlignTop (default)
\o TextEdit.AlignBottom
- \c TextEdit.AlignVCenter
+ \o TextEdit.AlignVCenter
\endlist
+
+ When using the attached property LayoutMirroring::enabled to mirror application
+ layouts, the horizontal alignment of text will also be mirrored. However, the property
+ \c horizontalAlignment will remain unchanged. To query the effective horizontal alignment
+ of TextEdit, use the read-only property \c effectiveHorizontalAlignment.
*/
QDeclarativeTextEdit::HAlignment QDeclarativeTextEdit::hAlign() const
{
@@ -485,28 +491,79 @@ QDeclarativeTextEdit::HAlignment QDeclarativeTextEdit::hAlign() const
return d->hAlign;
}
-void QDeclarativeTextEdit::setHAlign(QDeclarativeTextEdit::HAlignment alignment)
+void QDeclarativeTextEdit::setHAlign(HAlignment align)
{
Q_D(QDeclarativeTextEdit);
+ bool forceAlign = d->hAlignImplicit && d->effectiveLayoutMirror;
d->hAlignImplicit = false;
- if (alignment == d->hAlign)
- return;
- d->hAlign = alignment;
- d->updateDefaultTextOption();
- updateSize();
- emit horizontalAlignmentChanged(d->hAlign);
+ if (d->setHAlign(align, forceAlign) && isComponentComplete()) {
+ d->updateDefaultTextOption();
+ updateSize();
+ }
}
void QDeclarativeTextEdit::resetHAlign()
{
Q_D(QDeclarativeTextEdit);
d->hAlignImplicit = true;
- QDeclarativeTextEdit::HAlignment oldAlignment = d->hAlign;
- d->determineHorizontalAlignment();
- if (oldAlignment != d->hAlign) {
+ if (d->determineHorizontalAlignment() && isComponentComplete()) {
d->updateDefaultTextOption();
updateSize();
+ }
+}
+QDeclarativeTextEdit::HAlignment QDeclarativeTextEdit::effectiveHAlign() const
+{
+ Q_D(const QDeclarativeTextEdit);
+ QDeclarativeTextEdit::HAlignment effectiveAlignment = d->hAlign;
+ if (!d->hAlignImplicit && d->effectiveLayoutMirror) {
+ switch (d->hAlign) {
+ case QDeclarativeTextEdit::AlignLeft:
+ effectiveAlignment = QDeclarativeTextEdit::AlignRight;
+ break;
+ case QDeclarativeTextEdit::AlignRight:
+ effectiveAlignment = QDeclarativeTextEdit::AlignLeft;
+ break;
+ default:
+ break;
+ }
+ }
+ return effectiveAlignment;
+}
+
+bool QDeclarativeTextEditPrivate::setHAlign(QDeclarativeTextEdit::HAlignment alignment, bool forceAlign)
+{
+ Q_Q(QDeclarativeTextEdit);
+ if (hAlign != alignment || forceAlign) {
+ QDeclarativeTextEdit::HAlignment oldEffectiveHAlign = q->effectiveHAlign();
+ hAlign = alignment;
+ emit q->horizontalAlignmentChanged(alignment);
+ if (oldEffectiveHAlign != q->effectiveHAlign())
+ emit q->effectiveHorizontalAlignmentChanged();
+ return true;
+ }
+ return false;
+}
+
+bool QDeclarativeTextEditPrivate::determineHorizontalAlignment()
+{
+ Q_Q(QDeclarativeTextEdit);
+ if (hAlignImplicit && q->isComponentComplete()) {
+ // if no explicit alignment has been set, follow the natural layout direction of the text
+ return setHAlign(text.isRightToLeft() ? QDeclarativeTextEdit::AlignRight : QDeclarativeTextEdit::AlignLeft);
+ }
+ return false;
+}
+
+void QDeclarativeTextEditPrivate::mirrorChange()
+{
+ Q_Q(QDeclarativeTextEdit);
+ if (q->isComponentComplete()) {
+ if (!hAlignImplicit && (hAlign == QDeclarativeTextEdit::AlignRight || hAlign == QDeclarativeTextEdit::AlignLeft)) {
+ updateDefaultTextOption();
+ q->updateSize();
+ emit q->effectiveHorizontalAlignmentChanged();
+ }
}
}
@@ -1538,18 +1595,6 @@ void QDeclarativeTextEdit::moveCursorDelegate()
d->cursor->setY(cursorRect.y());
}
-void QDeclarativeTextEditPrivate::determineHorizontalAlignment()
-{
- Q_Q(QDeclarativeTextEdit);
- if (hAlignImplicit && q->isComponentComplete()) {
- // if no explicit alignment has been set, follow the natural layout direction of the text
- QDeclarativeTextEdit::HAlignment previousAlign = hAlign;
- hAlign = rightToLeftText ? QDeclarativeTextEdit::AlignRight : QDeclarativeTextEdit::AlignLeft;
- if (previousAlign != hAlign)
- emit q->horizontalAlignmentChanged(hAlign);
- }
-}
-
void QDeclarativeTextEditPrivate::updateSelection()
{
Q_Q(QDeclarativeTextEdit);
@@ -1698,14 +1743,15 @@ void QDeclarativeTextEdit::updateTotalLines()
void QDeclarativeTextEditPrivate::updateDefaultTextOption()
{
+ Q_Q(QDeclarativeTextEdit);
QTextOption opt = document->defaultTextOption();
int oldAlignment = opt.alignment();
- QDeclarativeTextEdit::HAlignment horizontalAlignment = hAlign;
+ QDeclarativeTextEdit::HAlignment horizontalAlignment = q->effectiveHAlign();
if (rightToLeftText) {
- if (hAlign == QDeclarativeTextEdit::AlignLeft)
+ if (horizontalAlignment == QDeclarativeTextEdit::AlignLeft)
horizontalAlignment = QDeclarativeTextEdit::AlignRight;
- else if (hAlign == QDeclarativeTextEdit::AlignRight)
+ else if (horizontalAlignment == QDeclarativeTextEdit::AlignRight)
horizontalAlignment = QDeclarativeTextEdit::AlignLeft;
}
opt.setAlignment((Qt::Alignment)(int)(horizontalAlignment | vAlign));
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
index 471b201..25ca1e7 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
@@ -73,6 +73,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextEdit : public QDeclarativeImplicitSizePa
Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
+ Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged REVISION 1)
Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged REVISION 1)
@@ -154,6 +155,7 @@ public:
HAlignment hAlign() const;
void setHAlign(HAlignment align);
void resetHAlign();
+ HAlignment effectiveHAlign() const;
VAlignment vAlign() const;
void setVAlign(VAlignment align);
@@ -247,6 +249,7 @@ Q_SIGNALS:
Q_REVISION(1) void linkActivated(const QString &link);
Q_REVISION(1) void canPasteChanged();
Q_REVISION(1) void inputMethodComposingChanged();
+ Q_REVISION(1) void effectiveHorizontalAlignmentChanged();
public Q_SLOTS:
void selectAll();
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h
index f4a6c0e..36e1b51 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h
@@ -88,7 +88,9 @@ public:
void updateDefaultTextOption();
void relayoutDocument();
void updateSelection();
- void determineHorizontalAlignment();
+ bool determineHorizontalAlignment();
+ bool setHAlign(QDeclarativeTextEdit::HAlignment, bool forceAlign = false);
+ void mirrorChange();
qreal implicitWidth() const;
void focusChanged(bool);
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 0c021db..0deffe9 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -326,6 +326,7 @@ void QDeclarativeTextInput::setSelectedTextColor(const QColor &color)
/*!
\qmlproperty enumeration TextInput::horizontalAlignment
+ \qmlproperty enumeration TextInput::effectiveHorizontalAlignment
Sets the horizontal alignment of the text within the TextInput item's
width and height. By default, the text alignment follows the natural alignment
@@ -340,6 +341,11 @@ void QDeclarativeTextInput::setSelectedTextColor(const QColor &color)
The valid values for \c horizontalAlignment are \c TextInput.AlignLeft, \c TextInput.AlignRight and
\c TextInput.AlignHCenter.
+
+ When using the attached property LayoutMirroring::enabled to mirror application
+ layouts, the horizontal alignment of text will also be mirrored. However, the property
+ \c horizontalAlignment will remain unchanged. To query the effective horizontal alignment
+ of TextInput, use the read-only property \c effectiveHorizontalAlignment.
*/
QDeclarativeTextInput::HAlignment QDeclarativeTextInput::hAlign() const
{
@@ -350,25 +356,75 @@ QDeclarativeTextInput::HAlignment QDeclarativeTextInput::hAlign() const
void QDeclarativeTextInput::setHAlign(HAlignment align)
{
Q_D(QDeclarativeTextInput);
+ bool forceAlign = d->hAlignImplicit && d->effectiveLayoutMirror;
d->hAlignImplicit = false;
- if(align == d->hAlign || align > QDeclarativeTextInput::AlignHCenter) // justify not supported
- return;
- d->hAlign = align;
- updateRect();
- d->updateHorizontalScroll();
- emit horizontalAlignmentChanged(d->hAlign);
+ if (d->setHAlign(align, forceAlign) && isComponentComplete()) {
+ updateRect();
+ d->updateHorizontalScroll();
+ }
}
void QDeclarativeTextInput::resetHAlign()
{
Q_D(QDeclarativeTextInput);
d->hAlignImplicit = true;
- QDeclarativeTextInput::HAlignment oldAlignment = d->hAlign;
- d->determineHorizontalAlignment();
- if (oldAlignment != d->hAlign) {
+ if (d->determineHorizontalAlignment() && isComponentComplete()) {
updateRect();
d->updateHorizontalScroll();
- emit horizontalAlignmentChanged(d->hAlign);
+ }
+}
+
+QDeclarativeTextInput::HAlignment QDeclarativeTextInput::effectiveHAlign() const
+{
+ Q_D(const QDeclarativeTextInput);
+ QDeclarativeTextInput::HAlignment effectiveAlignment = d->hAlign;
+ if (!d->hAlignImplicit && d->effectiveLayoutMirror) {
+ switch (d->hAlign) {
+ case QDeclarativeTextInput::AlignLeft:
+ effectiveAlignment = QDeclarativeTextInput::AlignRight;
+ break;
+ case QDeclarativeTextInput::AlignRight:
+ effectiveAlignment = QDeclarativeTextInput::AlignLeft;
+ break;
+ default:
+ break;
+ }
+ }
+ return effectiveAlignment;
+}
+
+bool QDeclarativeTextInputPrivate::setHAlign(QDeclarativeTextInput::HAlignment alignment, bool forceAlign)
+{
+ Q_Q(QDeclarativeTextInput);
+ if ((hAlign != alignment || forceAlign) && alignment <= QDeclarativeTextInput::AlignHCenter) { // justify not supported
+ QDeclarativeTextInput::HAlignment oldEffectiveHAlign = q->effectiveHAlign();
+ hAlign = alignment;
+ return true;
+ emit q->horizontalAlignmentChanged(alignment);
+ if (oldEffectiveHAlign != q->effectiveHAlign())
+ emit q->effectiveHorizontalAlignmentChanged();
+ }
+ return false;
+}
+
+bool QDeclarativeTextInputPrivate::determineHorizontalAlignment()
+{
+ if (hAlignImplicit) {
+ // if no explicit alignment has been set, follow the natural layout direction of the text
+ return setHAlign(control->text().isRightToLeft() ? QDeclarativeTextInput::AlignRight : QDeclarativeTextInput::AlignLeft);
+ }
+ return false;
+}
+
+void QDeclarativeTextInputPrivate::mirrorChange()
+{
+ Q_Q(QDeclarativeTextInput);
+ if (q->isComponentComplete()) {
+ if (!hAlignImplicit && (hAlign == QDeclarativeTextInput::AlignRight || hAlign == QDeclarativeTextInput::AlignLeft)) {
+ q->updateRect();
+ updateHorizontalScroll();
+ emit q->effectiveHorizontalAlignmentChanged();
+ }
}
}
@@ -1226,10 +1282,11 @@ void QDeclarativeTextInputPrivate::updateHorizontalScroll()
QRect br(q->boundingRect().toRect());
int widthUsed = calculateTextWidth();
+ QDeclarativeTextInput::HAlignment effectiveHAlign = q->effectiveHAlign();
if (autoScroll) {
if (widthUsed <= br.width()) {
// text fits in br; use hscroll for alignment
- switch (hAlign & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
+ switch (effectiveHAlign & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
case Qt::AlignRight:
hscroll = widthUsed - br.width() - 1;
break;
@@ -1261,7 +1318,7 @@ void QDeclarativeTextInputPrivate::updateHorizontalScroll()
hscroll = cix;
}
} else {
- switch (hAlign) {
+ switch (effectiveHAlign) {
case QDeclarativeTextInput::AlignRight:
hscroll = q->width() - widthUsed;
break;
@@ -1276,19 +1333,6 @@ void QDeclarativeTextInputPrivate::updateHorizontalScroll()
}
}
-void QDeclarativeTextInputPrivate::determineHorizontalAlignment()
-{
- Q_Q(QDeclarativeTextInput);
- if (hAlignImplicit) {
- QString text = control->text();
- // if no explicit alignment has been set, follow the natural layout direction of the text
- QDeclarativeTextInput::HAlignment previousAlign = hAlign;
- hAlign = text.isRightToLeft() ? QDeclarativeTextInput::AlignRight : QDeclarativeTextInput::AlignLeft;
- if (previousAlign != hAlign)
- emit q->horizontalAlignmentChanged(hAlign);
- }
-}
-
void QDeclarativeTextInput::drawContents(QPainter *p, const QRect &r)
{
Q_D(QDeclarativeTextInput);
@@ -1874,8 +1918,8 @@ void QDeclarativeTextInput::q_textChanged()
{
Q_D(QDeclarativeTextInput);
updateSize();
- d->updateHorizontalScroll();
d->determineHorizontalAlignment();
+ d->updateHorizontalScroll();
updateMicroFocus();
emit textChanged();
emit displayTextChanged();
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
index ce5f267..8c873b3 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
@@ -71,7 +71,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextInput : public QDeclarativeImplicitSizeP
Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
-
+ Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged REVISION 1)
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
@@ -154,6 +154,7 @@ public:
HAlignment hAlign() const;
void setHAlign(HAlignment align);
void resetHAlign();
+ HAlignment effectiveHAlign() const;
bool isReadOnly() const;
void setReadOnly(bool);
@@ -242,6 +243,7 @@ Q_SIGNALS:
Q_REVISION(1) void mouseSelectionModeChanged(SelectionMode mode);
Q_REVISION(1) void canPasteChanged();
Q_REVISION(1) void inputMethodComposingChanged();
+ Q_REVISION(1) void effectiveHorizontalAlignmentChanged();
protected:
virtual void geometryChanged(const QRectF &newGeometry,
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
index 60eeb76..fd4da2e 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
@@ -103,7 +103,9 @@ public:
void startCreatingCursor();
void focusChanged(bool hasFocus);
void updateHorizontalScroll();
- void determineHorizontalAlignment();
+ bool determineHorizontalAlignment();
+ bool setHAlign(QDeclarativeTextInput::HAlignment, bool forceAlign = false);
+ void mirrorChange();
int calculateTextWidth();
bool sendMouseEventToInputContext(QGraphicsSceneMouseEvent *event, QEvent::Type eventType);