Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qmlvisual / qdeclarativetextedit / MultilineEdit.qml
1 import QtQuick 1.0
2 import "../shared" 1.0
3
4 Item {
5     id:lineedit
6     property alias text: textEdit.text
7
8     width: 240 + 11 //Should be set manually in most cases
9     height: textEdit.height + 11 
10
11     Rectangle {
12         color: 'lightsteelblue'
13         anchors.fill: parent
14     }
15     clip: true
16     Component.onCompleted: textEdit.cursorPosition = 0;
17     TestTextEdit {
18         id:textEdit
19         cursorDelegate: Item {
20             Rectangle {
21                 visible: parent.parent.focus
22                 color: "#009BCE"
23                 height: 13
24                 width: 2
25                 y: 1
26             }
27         }
28         property int leftMargin: 6 
29         property int topMargin: 6 
30         property int rightMargin: 6 
31         property int bottomMargin: 6 
32         x: leftMargin
33         width: parent.width - leftMargin - rightMargin;
34         y: 5
35         //Below function implements all scrolling logic
36         onCursorPositionChanged: {
37             if(cursorRectangle.y < topMargin - textEdit.y){//Cursor went off the front
38                 textEdit.y = topMargin - Math.max(0, cursorRectangle.y);
39             }else if(cursorRectangle.y > parent.height - topMargin - bottomMargin - textEdit.y){//Cursor went off the end
40                 textEdit.y = topMargin - Math.max(0, cursorRectangle.y - (parent.height - topMargin - bottomMargin) + cursorRectangle.height);
41             }
42         }
43         onHeightChanged: y=topMargin//reset scroll
44
45         text:""
46         horizontalAlignment: TextInput.AlignLeft
47         wrapMode: TextEdit.WordWrap
48         font.pixelSize:15
49         selectionColor: 'steelblue'
50     }
51     MouseArea {
52         //Implements all line edit mouse handling
53         id: mainMouseArea
54         anchors.fill: parent;
55         function translateY(y){
56             return y - textEdit.y
57         }
58         function translateX(x){
59             return x - textEdit.x
60         }
61         onPressed: {
62             textEdit.focus = true;
63             textEdit.cursorPosition = textEdit.positionAt(translateX(mouse.x), translateY(mouse.y));
64         }
65         onPositionChanged: {
66             textEdit.moveCursorSelection(textEdit.positionAt(translateX(mouse.x), translateY(mouse.y)));
67         }
68         onReleased: {
69         }
70         onDoubleClicked: {
71             textEdit.selectAll()
72         }
73         z: textEdit.z + 1
74     }
75
76 }