From c771dd1e4a84108e3c345cf2696a6bb4a3aa4157 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Fri, 20 Nov 2009 10:43:33 +1000 Subject: Implement TextInput::horizontalAlignment Includes visual autotest. --- .../graphicsitems/qmlgraphicstextinput.cpp | 18 +++- .../visual/qmlgraphicstextinput/data/hAlign.0.png | Bin 0 -> 1245 bytes .../visual/qmlgraphicstextinput/data/hAlign.qml | 107 +++++++++++++++++++++ .../visual/qmlgraphicstextinput/hAlign.qml | 39 ++++++++ 4 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/visual/qmlgraphicstextinput/data/hAlign.0.png create mode 100644 tests/auto/declarative/visual/qmlgraphicstextinput/data/hAlign.qml create mode 100644 tests/auto/declarative/visual/qmlgraphicstextinput/hAlign.qml 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); diff --git a/tests/auto/declarative/visual/qmlgraphicstextinput/data/hAlign.0.png b/tests/auto/declarative/visual/qmlgraphicstextinput/data/hAlign.0.png new file mode 100644 index 0000000..87c2e07 Binary files /dev/null and b/tests/auto/declarative/visual/qmlgraphicstextinput/data/hAlign.0.png differ diff --git a/tests/auto/declarative/visual/qmlgraphicstextinput/data/hAlign.qml b/tests/auto/declarative/visual/qmlgraphicstextinput/data/hAlign.qml new file mode 100644 index 0000000..e29ac56 --- /dev/null +++ b/tests/auto/declarative/visual/qmlgraphicstextinput/data/hAlign.qml @@ -0,0 +1,107 @@ +import Qt.VisualTest 4.6 + +VisualTest { + Frame { + msec: 0 + } + Frame { + msec: 16 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 32 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 48 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 64 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 80 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 96 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 112 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 128 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 144 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 160 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 176 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 192 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 208 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 224 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 240 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 256 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 272 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 288 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 304 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 320 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 336 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 352 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 368 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 384 + hash: "7619ed68aca3544f373777e11a4bfefa" + } + Frame { + msec: 400 + hash: "7619ed68aca3544f373777e11a4bfefa" + } +} diff --git a/tests/auto/declarative/visual/qmlgraphicstextinput/hAlign.qml b/tests/auto/declarative/visual/qmlgraphicstextinput/hAlign.qml new file mode 100644 index 0000000..2d65adf --- /dev/null +++ b/tests/auto/declarative/visual/qmlgraphicstextinput/hAlign.qml @@ -0,0 +1,39 @@ +import Qt 4.6 + +Item{ + width:600; + height:300; + Column{ + TextInput{ + text: "Jackdaws love my big sphinx of quartz"; + horizontalAlignment: TextInput.AlignLeft; + } + TextInput{ + text: "Jackdaws love my big sphinx of quartz"; + horizontalAlignment: TextInput.AlignHCenter; + } + TextInput{ + text: "Jackdaws love my big sphinx of quartz"; + horizontalAlignment: TextInput.AlignRight; + } + Rectangle{ width: 600; height: 10; color: "pink" } + TextInput{ + height: 30; + width: 600; + text: "Jackdaws love my big sphinx of quartz"; + horizontalAlignment: TextInput.AlignLeft; + } + TextInput{ + height: 30; + width: 600; + text: "Jackdaws love my big sphinx of quartz"; + horizontalAlignment: TextInput.AlignHCenter; + } + TextInput{ + height: 30; + width: 600; + text: "Jackdaws love my big sphinx of quartz"; + horizontalAlignment: TextInput.AlignRight; + } + } +} -- cgit v0.12