diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-05-28 01:55:11 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-05-30 23:57:20 (GMT) |
commit | e66fe7ea65b218dd320cb553bf6669d2a2021657 (patch) | |
tree | a25bb5c271ba5ea6e6826e3900607813db52b6e7 /tests/auto/declarative | |
parent | 81b73d11e3d147f97d20af220721617bcf3c412f (diff) | |
download | Qt-e66fe7ea65b218dd320cb553bf6669d2a2021657.zip Qt-e66fe7ea65b218dd320cb553bf6669d2a2021657.tar.gz Qt-e66fe7ea65b218dd320cb553bf6669d2a2021657.tar.bz2 |
Add selection methods to TextEdit
Sufficient to allow different selection look and feel (see whacky example)
Task-number: QTBUG-10968
Reviewed-by: Michael Brasser
Reviewed-by: Alan Alpert
Diffstat (limited to 'tests/auto/declarative')
3 files changed, 89 insertions, 2 deletions
diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml new file mode 100644 index 0000000..0273282 --- /dev/null +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/MultilineEdit.qml @@ -0,0 +1,74 @@ +import Qt 4.7 + +Item { + id:lineedit + property alias text: textEdit.text + + width: 240 + 11 //Should be set manually in most cases + height: textEdit.height + 11 + + Rectangle{ + color: 'lightsteelblue' + anchors.fill: parent + } + clip: true + Component.onCompleted: textEdit.cursorPosition = 0; + TextEdit{ + id:textEdit + cursorDelegate: Item{ + Rectangle{ + visible: parent.parent.focus + color: "#009BCE" + height: 13 + width: 2 + y: 1 + } + } + property int leftMargin: 6 + property int topMargin: 6 + property int rightMargin: 6 + property int bottomMargin: 6 + x: leftMargin + width: parent.width - leftMargin - rightMargin; + y: 5 + //Below function implements all scrolling logic + onCursorPositionChanged: { + if(cursorRectangle.y < topMargin - textEdit.y){//Cursor went off the front + textEdit.y = topMargin - Math.max(0, cursorRectangle.y); + }else if(cursorRectangle.y > parent.height - topMargin - bottomMargin - textEdit.y){//Cursor went off the end + textEdit.y = topMargin - Math.max(0, cursorRectangle.y - (parent.height - topMargin - bottomMargin)) - cursorRectangle.height; + } + } + + text:"" + horizontalAlignment: TextInput.AlignLeft + wrapMode: TextEdit.WordWrap + font.pixelSize:15 + } + MouseArea{ + //Implements all line edit mouse handling + id: mainMouseArea + anchors.fill: parent; + function translateY(y){ + return y - textEdit.y + } + function translateX(x){ + return x - textEdit.x + } + onPressed: { + textEdit.focus = true; + textEdit.cursorPosition = textEdit.positionAt(translateX(mouse.x), translateY(mouse.y)); + } + onPositionChanged: { + textEdit.moveCursorSelection(textEdit.positionAt(translateX(mouse.x), translateY(mouse.y))); + } + onReleased: { + } + onDoubleClicked: { + textEdit.selectionStart=0; + textEdit.selectionEnd=textEdit.text.length; + } + z: textEdit.z + 1 + } + +} diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/usingMultilineEdit.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/usingMultilineEdit.qml new file mode 100644 index 0000000..47b48d8 --- /dev/null +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/usingMultilineEdit.qml @@ -0,0 +1,13 @@ +import Qt 4.7 + +Rectangle{ + width: 600 + height: 200 + Column{ + MultilineEdit{ + text: 'I am the very model of a modern major general. I\'ve information vegetable, animal and mineral. I know the kings of england and I quote the fights historical - from Marathon to Waterloo in order categorical.'; + width: 182; height: 60; + } + MultilineEdit{text: 'Hello world'} + } +} diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml index 31f24ec..cc0ad3c 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml @@ -50,10 +50,10 @@ Item { } onPressed: { textInp.focus = true; - textInp.cursorPosition = textInp.xToPosition(translateX(mouse.x)); + textInp.cursorPosition = textInp.positionAt(translateX(mouse.x)); } onPositionChanged: { - textInp.moveCursorSelection(textInp.xToPosition(translateX(mouse.x))); + textInp.moveCursorSelection(textInp.positionAt(translateX(mouse.x))); } onReleased: { } |