summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-11-20 00:43:33 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-11-20 00:43:33 (GMT)
commitc771dd1e4a84108e3c345cf2696a6bb4a3aa4157 (patch)
treefbdbfea14cb4148875d1ca8214242ffb7e337eb1
parent5439a148cc5045769c336cf8e8228bc0e8b8f746 (diff)
downloadQt-c771dd1e4a84108e3c345cf2696a6bb4a3aa4157.zip
Qt-c771dd1e4a84108e3c345cf2696a6bb4a3aa4157.tar.gz
Qt-c771dd1e4a84108e3c345cf2696a6bb4a3aa4157.tar.bz2
Implement TextInput::horizontalAlignment
Includes visual autotest.
-rw-r--r--src/declarative/graphicsitems/qmlgraphicstextinput.cpp18
-rw-r--r--tests/auto/declarative/visual/qmlgraphicstextinput/data/hAlign.0.pngbin0 -> 1245 bytes
-rw-r--r--tests/auto/declarative/visual/qmlgraphicstextinput/data/hAlign.qml107
-rw-r--r--tests/auto/declarative/visual/qmlgraphicstextinput/hAlign.qml39
4 files changed, 163 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);
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
--- /dev/null
+++ b/tests/auto/declarative/visual/qmlgraphicstextinput/data/hAlign.0.png
Binary files 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;
+ }
+ }
+}