tests/auto/declarative/qmlvisual/qdeclarativetextinput/LineEdit.qml
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
       
     1 import Qt 4.7
       
     2 
       
     3 Item {
       
     4     id:lineedit
       
     5     property alias text: textInp.text
       
     6 
       
     7     width: textInp.width + 11 
       
     8     height: 13 + 11 
       
     9 
       
    10     Rectangle{
       
    11         color: 'lightsteelblue'
       
    12         anchors.fill: parent
       
    13     }
       
    14     clip: true
       
    15     Component.onCompleted: textInp.cursorPosition = 0;
       
    16     TextInput{
       
    17         id:textInp
       
    18         cursorDelegate: Item{
       
    19             Rectangle{
       
    20                 visible: parent.parent.focus
       
    21                 color: "#009BCE"
       
    22                 height: 13
       
    23                 width: 2
       
    24                 y: 1
       
    25             }
       
    26         }
       
    27         property int leftMargin: 6 
       
    28         property int rightMargin: 6 
       
    29         x: leftMargin
       
    30         y: 5
       
    31         //Below function implements all scrolling logic
       
    32         onCursorPositionChanged: {
       
    33             if(cursorRect.x < leftMargin - textInp.x){//Cursor went off the front
       
    34                 textInp.x = leftMargin - Math.max(0, cursorRect.x);
       
    35             }else if(cursorRect.x > parent.width - leftMargin - rightMargin - textInp.x){//Cusor went off the end
       
    36                 textInp.x = leftMargin - Math.max(0, cursorRect.x - (parent.width - leftMargin - rightMargin));
       
    37             }
       
    38         }
       
    39 
       
    40         text:""
       
    41         horizontalAlignment: TextInput.AlignLeft
       
    42         font.pixelSize:15
       
    43     }
       
    44     MouseArea{
       
    45         //Implements all line edit mouse handling
       
    46         id: mainMouseArea
       
    47         anchors.fill: parent;
       
    48         function translateX(x){
       
    49             return x - textInp.x
       
    50         }
       
    51         onPressed: {
       
    52             textInp.focus = true;
       
    53             textInp.cursorPosition = textInp.xToPosition(translateX(mouse.x));
       
    54         }
       
    55         onPositionChanged: {
       
    56             textInp.moveCursorSelection(textInp.xToPosition(translateX(mouse.x)));
       
    57         }
       
    58         onReleased: {
       
    59         }
       
    60         onDoubleClicked: {
       
    61             textInp.selectionStart=0;
       
    62             textInp.selectionEnd=textInp.text.length;
       
    63         }
       
    64         z: textInp.z + 1
       
    65     }
       
    66 
       
    67 }