Put editbubble below cursor when there's not enough space above it
Also clean up a bit here and there, removing redundancy
This commit is contained in:
parent
b6f545c433
commit
10b4ad517d
@ -25,13 +25,10 @@ PlasmaCore.FrameSvgItem {
|
|||||||
id: editBubble
|
id: editBubble
|
||||||
objectName: "editBubble"
|
objectName: "editBubble"
|
||||||
property int iconSize: 32;
|
property int iconSize: 32;
|
||||||
//property alias cursorPosition: textInput.cursorPosition;
|
|
||||||
property variant cursorPosition: "0,0"
|
|
||||||
|
|
||||||
imagePath: "dialogs/background"
|
imagePath: "dialogs/background"
|
||||||
width: (iconSize*2) + iconSize
|
width: (iconSize*2) + iconSize
|
||||||
height: iconSize*2
|
height: iconSize*2
|
||||||
z: 1
|
z: 100000
|
||||||
//anchors { top: parent.bottom; right: parent.right; topMargin: -(iconSize/4); }
|
//anchors { top: parent.bottom; right: parent.right; topMargin: -(iconSize/4); }
|
||||||
|
|
||||||
// fully dynamic show / hide
|
// fully dynamic show / hide
|
||||||
@ -79,12 +76,6 @@ 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: [
|
states: [
|
||||||
State {
|
State {
|
||||||
id: expanded
|
id: expanded
|
||||||
|
@ -188,7 +188,7 @@ Item {
|
|||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
print("clear button clicked");
|
//print("clear button clicked");
|
||||||
textInput.text = "";
|
textInput.text = "";
|
||||||
textInput.forceActiveFocus();
|
textInput.forceActiveFocus();
|
||||||
editBubble.state = "collapsed"
|
editBubble.state = "collapsed"
|
||||||
@ -203,24 +203,36 @@ Item {
|
|||||||
//onPressed: print(" MouseEventListener Pressed");
|
//onPressed: print(" MouseEventListener Pressed");
|
||||||
onPressAndHold: {
|
onPressAndHold: {
|
||||||
print(" *** MouseEventListener PressAndHold");
|
print(" *** MouseEventListener PressAndHold");
|
||||||
editBubble.cursorPosition = mouse;
|
placeEditBubble(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 = (textInput.activeFocus && (textInput.selectedText != "" || textInput.canPaste)) ? "expanded" : "collapsed";
|
||||||
//editBubble.state = "expanded"
|
|
||||||
}
|
}
|
||||||
onPositionChanged: {
|
onPositionChanged: {
|
||||||
//print(" positionChanged: " + mouse.x + "," + mouse.y);
|
placeEditBubble(mouse);
|
||||||
//if (typeof(mouse) == "undefined") return;
|
}
|
||||||
editBubble.cursorPosition = mouse;
|
}
|
||||||
|
|
||||||
|
function placeEditBubble(mouse) {
|
||||||
|
// Find the root item, then map our cursor position to it
|
||||||
|
// in order to check if the edit bubble could end up off-screen
|
||||||
|
var rootItem = parent;
|
||||||
|
while (rootItem.parent) {
|
||||||
|
rootItem = rootItem.parent;
|
||||||
|
}
|
||||||
|
var distanceToTop = mouseEventListener.mapToItem(rootItem, mouse.x, mouse.y);
|
||||||
|
print( " distanceToTop: " + distanceToTop.y);
|
||||||
|
if (distanceToTop.y > editBubble.height) {
|
||||||
editBubble.x = mouse.x-(editBubble.width/2)
|
editBubble.x = mouse.x-(editBubble.width/2)
|
||||||
editBubble.y = mouse.y-editBubble.height-8
|
editBubble.y = mouse.y-editBubble.height-8
|
||||||
|
} else {
|
||||||
|
editBubble.x = mouse.x-(editBubble.width/2)
|
||||||
|
editBubble.y = mouse.y+8
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
onActiveFocusChanged: {
|
onActiveFocusChanged: {
|
||||||
if (!activeFocus) {
|
if (!activeFocus) {
|
||||||
editBubble.state = "collapsed";
|
editBubble.state = "collapsed";
|
||||||
print("Hiding...");
|
//print("Hiding...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -181,7 +181,7 @@ Column {
|
|||||||
Timer {
|
Timer {
|
||||||
running: true
|
running: true
|
||||||
repeat: true
|
repeat: true
|
||||||
interval: 25
|
interval: 100
|
||||||
onTriggered: parent.value = (parent.value + 1) % 1.1
|
onTriggered: parent.value = (parent.value + 1) % 1.1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,12 +47,13 @@ PlasmaComponents.Page {
|
|||||||
|
|
||||||
Column {
|
Column {
|
||||||
id: editThing
|
id: editThing
|
||||||
anchors.centerIn: parent
|
anchors.top: parent.top
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
width: 300
|
width: 300
|
||||||
height: 300
|
height: 300
|
||||||
|
|
||||||
spacing: 12
|
spacing: 12
|
||||||
Item { height: 60; width: parent.width; }
|
Item { height: 4; width: parent.width; }
|
||||||
PlasmaComponents.TextField {
|
PlasmaComponents.TextField {
|
||||||
placeholderText: "Try copy & paste"
|
placeholderText: "Try copy & paste"
|
||||||
text: "The cat bites into the socks"
|
text: "The cat bites into the socks"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user