diff --git a/declarativeimports/plasmacomponents/platformcomponents/touch/EditBubble.qml b/declarativeimports/plasmacomponents/platformcomponents/touch/EditBubble.qml index 313f512df..527b1866a 100644 --- a/declarativeimports/plasmacomponents/platformcomponents/touch/EditBubble.qml +++ b/declarativeimports/plasmacomponents/platformcomponents/touch/EditBubble.qml @@ -25,14 +25,19 @@ PlasmaCore.FrameSvgItem { id: editBubble objectName: "editBubble" property int iconSize: 32; + //property alias cursorPosition: textInput.cursorPosition; + property variant cursorPosition: "0,0" imagePath: "dialogs/background" width: (iconSize*2) + iconSize height: iconSize*2 z: 1 - anchors { top: parent.bottom; right: parent.right; topMargin: -(iconSize/4); } + //anchors { top: parent.bottom; right: parent.right; topMargin: -(iconSize/4); } - state: (textInput.activeFocus && (textInput.selectedText != "" || textInput.canPaste)) ? "expanded" : "collapsed"; + // fully dynamic show / hide + //state: (textInput.activeFocus && (textInput.selectedText != "" || textInput.canPaste)) ? "expanded" : "collapsed"; + // state controlled externally + state: "collapsed" Row { id: buttonRow @@ -74,6 +79,12 @@ PlasmaCore.FrameSvgItem { } } } + onCursorPositionChanged: { + //if (typeof(cursorPosition == "undefined")) return; + //print(" new cursorPosition: " + cursorPosition.x + "," + cursorPosition.y); + x = cursorPosition.x - parent.width/2 + y = cursorPosition.y - parent.height + } states: [ State { id: expanded diff --git a/declarativeimports/plasmacomponents/platformcomponents/touch/TextField.qml b/declarativeimports/plasmacomponents/platformcomponents/touch/TextField.qml index 6b4ff17c8..7888f8f43 100644 --- a/declarativeimports/plasmacomponents/platformcomponents/touch/TextField.qml +++ b/declarativeimports/plasmacomponents/platformcomponents/touch/TextField.qml @@ -139,12 +139,14 @@ Item { font.underline: theme.defaultFont.underline font.weight: theme.defaultFont.weight font.wordSpacing: theme.defaultFont.wordSpacing + } - EditBubble { iconSize: 32 } + EditBubble { id: editBubble; iconSize: 32 } TextInput { id: textInput + parent: mouseEventListener anchors { left: parent.left @@ -166,6 +168,7 @@ Item { } PlasmaCore.SvgItem { + parent: mouseEventListener // reparent to the MouseFilter for MouseArea to work svg: PlasmaCore.Svg {imagePath: "widgets/lineedit"} elementId: "clearbutton" width: textInput.height @@ -180,14 +183,44 @@ Item { anchors { right: parent.right rightMargin: y - verticalCenter: textInput.verticalCenter + verticalCenter: parent.verticalCenter } MouseArea { anchors.fill: parent onClicked: { - textInput.text = "" - textInput.forceActiveFocus() + print("clear button clicked"); + textInput.text = ""; + textInput.forceActiveFocus(); + editBubble.state = "collapsed" } + //Rectangle { anchors.fill: parent; color: "green"; opacity: 0.3; } + } + } + + MouseEventListener { + id: mouseEventListener + anchors.fill: parent + //onPressed: print(" MouseEventListener Pressed"); + onPressAndHold: { + print(" *** MouseEventListener PressAndHold"); + editBubble.cursorPosition = mouse; + editBubble.x = mouse.x-(editBubble.width/2) + editBubble.y = mouse.y-editBubble.height-8 + editBubble.state = (textInput.activeFocus && (textInput.selectedText != "" || textInput.canPaste)) ? "expanded" : "collapsed"; + //editBubble.state = "expanded" + } + onPositionChanged: { + //print(" positionChanged: " + mouse.x + "," + mouse.y); + //if (typeof(mouse) == "undefined") return; + editBubble.cursorPosition = mouse; + editBubble.x = mouse.x-(editBubble.width/2) + editBubble.y = mouse.y-editBubble.height-8 + } + } + onActiveFocusChanged: { + if (!activeFocus) { + editBubble.state = "collapsed"; + print("Hiding..."); } } } \ No newline at end of file diff --git a/declarativeimports/test/gallery/TextEditing.qml b/declarativeimports/test/gallery/TextEditing.qml index 08db3262b..b2445f247 100644 --- a/declarativeimports/test/gallery/TextEditing.qml +++ b/declarativeimports/test/gallery/TextEditing.qml @@ -23,6 +23,7 @@ import org.kde.plasma.components 0.1 as PlasmaComponents PlasmaComponents.Page { height: editThing.height property int implicitHeight: childrenRect.height + //scale: 1.25 tools: PlasmaComponents.ToolBarLayout { spacing: 5 @@ -39,7 +40,6 @@ PlasmaComponents.Page { text: "Text fields page" } } - MouseArea { anchors.fill: editThing onClicked: editThing.forceActiveFocus(); @@ -53,9 +53,11 @@ PlasmaComponents.Page { spacing: 12 Item { height: 60; width: parent.width; } - PlasmaComponents.TextField { placeholderText: "Try copy & paste" + text: "The cat bites into the socks" + width: parent.width + clearButtonShown: true } PlasmaComponents.TextArea { width: parent.width