import QtQuick 2.0 import "coordinate.js" as CONFIG import "../com/neusoft/auto/widgets" FocusScope { id: focusScope property string textOfInput: textInput.text property string defaultShowingText: textInput.text property var maxLengthOfInput; property int textInputWidth; property int textInputHeight; property alias maxnumlength: textInput.maximumLength; focus:false // BorderImage { // source: "../images/lineedit-bg.png" // width: parent.width; height: parent.height // border { left: 4; top: 4; right: 4; bottom: 4 } // } onVisibleChanged: { focusScope.focus = false } Text { id: defaultText anchors.fill: parent; verticalAlignment: Text.AlignTop text: defaultShowingText color: "grey" font.pixelSize:CONFIG.REMINDER_BTN_FONT_SIZE } MouseArea { anchors.fill: parent onClicked: { if(!focusScope.focus){ focusScope.focus = true; } textInput.cursorPosition = textInput.text.length; } } TextInput { id: textInput width:textInputWidth cursorVisible :focusScope.focus?true:false wrapMode: TextEdit.Wrap maximumLength:maxLengthOfInput focus: true font.pixelSize:CONFIG.REMINDER_BTN_FONT_SIZE color: "#ffffff" onCursorPositionChanged: { if(textInput.text.length == maximumLength) { console.debug("lengthlengthlengthlengthlengthlengthlengthlength") keyBoard.maximumState=true } else if(textInput.text.length < maximumLength) { keyBoard.maximumState=false } } } onFocusChanged:{ if(focusScope.focus){ textInput.focus=true systemCtrl.setTextInputHandle(textInput); } if(!keyBoard.visible) { keyBoard.visible=true; } } // Image { // id: clear // anchors { right: parent.right; rightMargin: 8; verticalCenter: parent.verticalCenter } // source: "../images/clear.png" // opacity: 0 // MouseArea { // anchors.fill: parent // onClicked: { textInput.text = ''; focusScope.focus = true; textInput.openSoftwareInputPanel(); } // } // } states: State { name: "hasText"; when: textInput.text != '' PropertyChanges { target: defaultText; opacity: 0 } //PropertyChanges { target: clear; opacity: 1 } } transitions: [ Transition { from: ""; to: "hasText" NumberAnimation { exclude: defaultText; properties: "opacity" } }, Transition { from: "hasText"; to: "" NumberAnimation { properties: "opacity" } } ] /*========================================Function Start==============================================*/ function clearText() { textInput.text = ""; } function setText(text) { textInput.text = text; } /*========================================Function End================================================*/ }