Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qmlvisual / qdeclarativetextinput / LineEdit.qml
1 import QtQuick 1.0
2 import "../shared" 1.0
3
4 Item {
5     id:lineedit
6     property alias text: textInp.text
7
8     width: textInp.width + 11 
9     height: 13 + 11 
10
11     Rectangle {
12         color: 'lightsteelblue'
13         anchors.fill: parent
14     }
15     clip: true
16     Component.onCompleted: textInp.cursorPosition = 0;
17     TestTextInput {
18         id:textInp
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 rightMargin: 6 
30         x: leftMargin
31         y: 5
32         //Below function implements all scrolling logic
33         onCursorPositionChanged: {
34             if(cursorRectangle.x < leftMargin - textInp.x){//Cursor went off the front
35                 textInp.x = leftMargin - Math.max(0, cursorRectangle.x);
36             }else if(cursorRectangle.x > parent.width - leftMargin - rightMargin - textInp.x){//Cusor went off the end
37                 textInp.x = leftMargin - Math.max(0, cursorRectangle.x - (parent.width - leftMargin - rightMargin));
38             }
39         }
40
41         autoScroll: false //It is preferable to implement your own scrolling
42         text:""
43         horizontalAlignment: TextInput.AlignLeft
44         font.pixelSize:15
45         selectionColor: 'steelblue'
46     }
47     MouseArea {
48         //Implements all line edit mouse handling
49         id: mainMouseArea
50         anchors.fill: parent;
51         function translateX(x){
52             return x - textInp.x
53         }
54         onPressed: {
55             textInp.focus = true;
56             textInp.cursorPosition = textInp.positionAt(translateX(mouse.x));
57         }
58         onPositionChanged: {
59             textInp.moveCursorSelection(textInp.positionAt(translateX(mouse.x)));
60         }
61         onReleased: {
62         }
63         onDoubleClicked: {
64             textInp.selectAll()
65         }
66         z: textInp.z + 1
67     }
68
69 }