optional clear button in the lineedits

This commit is contained in:
Marco Martin 2011-11-14 18:55:29 +01:00
parent 8c0f8f0e5a
commit 9a0026969f

View File

@ -41,6 +41,9 @@ Item {
property alias text: textInput.text
property alias maximumLength: textInput.maximumLength
//Plasma api
property bool clearButtonShown: false
function copy() {
textInput.copy();
}
@ -158,4 +161,30 @@ Item {
Keys.onPressed: textField.Keys.pressed(event);
Keys.onReleased: textField.Keys.released(event);
}
PlasmaCore.SvgItem {
svg: PlasmaCore.Svg {imagePath: "widgets/lineedit"}
elementId: "clearbutton"
width: textInput.height
height: textInput.height
opacity: (textInput.text != "" && clearButtonShown) ? 1 : 0
Behavior on opacity {
NumberAnimation {
duration: 250
easing.type: Easing.InOutQuad
}
}
anchors {
right: parent.right
rightMargin: y
verticalCenter: textInput.verticalCenter
}
MouseArea {
anchors.fill: parent
onClicked: {
textInput.text = ""
textInput.forceActiveFocus()
}
}
}
}