diff options
author | Frederik Gladhorn <frederik.gladhorn@nokia.com> | 2012-06-21 17:41:03 +0200 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@nokia.com> | 2012-06-27 10:03:05 +0200 |
commit | 0d64802fc0db6f4da6194e222fc2d2c01e0f140b (patch) | |
tree | c655b10a103f0448808d0f3d83ca7860c1d3b6a0 | |
parent | e29963b9528ed1778c124cd3497593a148a5afe2 (diff) | |
download | qtquickcontrols-0d64802fc0db6f4da6194e222fc2d2c01e0f140b.tar.gz |
Improve TextArea margins
Remove some extra item and other confusing things.
Now the margins should be right and the right aligned
text works properly.
Thanks to Gabriel for doing the actual work.
Change-Id: I1ef0cebb2e2c6678cef9a420fb8015474ac7305d
Reviewed-by: Gabriel de Dietrich <gabriel.dietrich-de@nokia.com>
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@nokia.com>
-rw-r--r-- | components/TextArea.qml | 69 |
1 files changed, 32 insertions, 37 deletions
diff --git a/components/TextArea.qml b/components/TextArea.qml index 951df94a..6441aa97 100644 --- a/components/TextArea.qml +++ b/components/TextArea.qml @@ -43,7 +43,7 @@ import "custom" as Components import QtDesktop 0.2 ScrollArea { - id:area + id: area color: "white" width: 280 height: 120 @@ -70,46 +70,43 @@ ScrollArea { // FIXME: probably implement text interface Accessible.name: text - Item { - anchors.left: parent.left - anchors.top: parent.top - height: edit.paintedHeight + area.height - viewportHeight + 2 * documentMargins + 4 - anchors.margins: documentMargins + TextEdit { + id: edit + wrapMode: TextEdit.WordWrap; + width: area.viewportWidth - (2 * documentMargins) + x: documentMargins + y: documentMargins + // height has to be big enough to handle mouse focus + height: Math.max(area.height, paintedHeight) - TextEdit { - id: edit - wrapMode: TextEdit.WordWrap; - width: area.width - height: area.height - selectByMouse: true - readOnly: false - color: syspal.text + selectByMouse: true + readOnly: false + color: syspal.text - SystemPalette { - id: syspal - colorGroup: enabled ? SystemPalette.Active : SystemPalette.Disabled - } + SystemPalette { + id: syspal + colorGroup: enabled ? SystemPalette.Active : SystemPalette.Disabled + } - KeyNavigation.priority: KeyNavigation.BeforeItem - KeyNavigation.tab: area.tabChangesFocus ? area.KeyNavigation.tab : null - KeyNavigation.backtab: area.tabChangesFocus ? area.KeyNavigation.backtab : null + KeyNavigation.priority: KeyNavigation.BeforeItem + KeyNavigation.tab: area.tabChangesFocus ? area.KeyNavigation.tab : null + KeyNavigation.backtab: area.tabChangesFocus ? area.KeyNavigation.backtab : null - onContentSizeChanged: { - area.contentWidth = paintedWidth + (2 * documentMargins) - } + onContentSizeChanged: { + area.contentWidth = paintedWidth + (2 * documentMargins) + } - // keep textcursor within scrollarea - onCursorPositionChanged: { - if (cursorRectangle.y >= area.contentY + area.viewportHeight - 1.5*cursorRectangle.height - documentMargins) - area.contentY = cursorRectangle.y - area.viewportHeight + 1.5*cursorRectangle.height + documentMargins - else if (cursorRectangle.y < area.contentY) - area.contentY = cursorRectangle.y + // keep textcursor within scrollarea + onCursorPositionChanged: { + if (cursorRectangle.y >= area.contentY + area.viewportHeight - 1.5*cursorRectangle.height - documentMargins) + area.contentY = cursorRectangle.y - area.viewportHeight + 1.5*cursorRectangle.height + documentMargins + else if (cursorRectangle.y < area.contentY) + area.contentY = cursorRectangle.y - if (cursorRectangle.x >= area.contentX + area.viewportWidth - documentMargins) { - area.contentX = cursorRectangle.x - area.viewportWidth + documentMargins - } else if (cursorRectangle.x < area.contentX) - area.contentX = cursorRectangle.x - } + if (cursorRectangle.x >= area.contentX + area.viewportWidth - documentMargins) { + area.contentX = cursorRectangle.x - area.viewportWidth + documentMargins + } else if (cursorRectangle.x < area.contentX) + area.contentX = cursorRectangle.x } } @@ -119,6 +116,4 @@ ScrollArea { } else if (event.key == Qt.Key_PageDown) verticalValue = verticalValue + area.height } - - Component.onCompleted: edit.width = area.viewportWidth - (2 * documentMargins) } |