use MouseListener for showing and positioning the EditBubble, basically works, needs polishing
This commit is contained in:
parent
2565770d2d
commit
296300085a
@ -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
|
||||
|
@ -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...");
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user