diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2009-11-20 00:43:33 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2009-11-20 00:43:33 (GMT) |
commit | c771dd1e4a84108e3c345cf2696a6bb4a3aa4157 (patch) | |
tree | fbdbfea14cb4148875d1ca8214242ffb7e337eb1 /src/declarative/graphicsitems/qmlgraphicstextinput.cpp | |
parent | 5439a148cc5045769c336cf8e8228bc0e8b8f746 (diff) | |
download | Qt-c771dd1e4a84108e3c345cf2696a6bb4a3aa4157.zip Qt-c771dd1e4a84108e3c345cf2696a6bb4a3aa4157.tar.gz Qt-c771dd1e4a84108e3c345cf2696a6bb4a3aa4157.tar.bz2 |
Implement TextInput::horizontalAlignment
Includes visual autotest.
Diffstat (limited to 'src/declarative/graphicsitems/qmlgraphicstextinput.cpp')
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicstextinput.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicstextinput.cpp b/src/declarative/graphicsitems/qmlgraphicstextinput.cpp index 56f59d8..b7d4e8c 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextinput.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstextinput.cpp @@ -212,8 +212,9 @@ QmlGraphicsTextInput::HAlignment QmlGraphicsTextInput::hAlign() const void QmlGraphicsTextInput::setHAlign(HAlignment align) { Q_D(QmlGraphicsTextInput); + if(align == d->hAlign) + return; d->hAlign = align; - //TODO: implement } bool QmlGraphicsTextInput::isReadOnly() const @@ -650,6 +651,21 @@ void QmlGraphicsTextInput::drawContents(QPainter *p, const QRect &r) } QPoint offset = QPoint(0,0); + if(d->hAlign != AlignLeft){ + QFontMetrics fm = QFontMetrics(d->font); + //###Is this using bearing appropriately? + int minLB = qMax(0, -fm.minLeftBearing()); + int minRB = qMax(0, -fm.minRightBearing()); + int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB; + int hOffset = 0; + if(d->hAlign == AlignRight){ + hOffset = width() - widthUsed; + }else if(d->hAlign == AlignHCenter){ + hOffset = (width() - widthUsed) / 2; + } + hOffset -= minLB; + offset = QPoint(hOffset, 0); + } QRect clipRect = r; d->control->draw(p, offset, clipRect, flags); |