diff --git a/containments/desktop/package/contents/ui/AppletAppearance.qml b/containments/desktop/package/contents/ui/AppletAppearance.qml --- a/containments/desktop/package/contents/ui/AppletAppearance.qml +++ b/containments/desktop/package/contents/ui/AppletAppearance.qml @@ -40,7 +40,7 @@ property real controlsOpacity: (plasmoid.immutable || !showAppletHandle) ? 0 : 1 property string backgroundHints: "NoBackground" property bool hasBackground: false - property bool handleMerged: (height > minimumHandleHeight) + property bool handleMerged: (height > minimumHandleHeight && !appletHandle.forceFloating) property bool animationsEnabled: false property int minimumWidth: Math.max(root.layoutManager.cellSize.width, @@ -249,8 +249,15 @@ } } - onCanceled: endDrag() - onReleased: endDrag() + onCanceled: { + endDrag(); + appletHandle.positionHandle(); + } + + onReleased: { + endDrag(); + appletHandle.positionHandle(); + } } Item { @@ -337,21 +344,49 @@ Loader { id: appletHandle z: appletContainer.z + 1 + property bool forceFloating : false anchors { verticalCenter: parent.verticalCenter right: plasmoidBackground.right - rightMargin: appletItem.margins.right } Connections { target: appletItem onShowAppletHandleChanged: { - if (appletItem.showAppletHandle && appletHandle.source == "") { - //print("Loading applethandle "); - appletHandle.source = "AppletHandle.qml"; + if (appletItem.showAppletHandle) { + appletHandle.positionHandle(); + if (appletHandle.source == "") { + appletHandle.source = "AppletHandle.qml"; + } } } } + Connections { + target: appletHandle.item + onMoveFinished: { + appletHandle.positionHandle(); + } + } + function positionHandle() + { + // Don't show handle outside of desktop + var available = plasmoid.availableScreenRect; + var x = Math.min(Math.max(0, appletItem.x), available.width - appletItem.width); + var y = Math.min(Math.max(0, appletItem.y), available.height - appletItem.height); + var verticalCenter = (y + appletItem.height / 2); + var topOutside = (verticalCenter - minimumHandleHeight / 2) - available.y; + var bottomOutside = verticalCenter + minimumHandleHeight / 2 + available.y - available.height; + if (bottomOutside > 0) { + anchors.verticalCenterOffset = -bottomOutside; + } else if (topOutside < 0) { + anchors.verticalCenterOffset = -topOutside; + } else { + anchors.verticalCenterOffset = 0; + } + var rightOutside = x + appletItem.width + handleWidth - available.width; + appletHandle.anchors.rightMargin = appletItem.margins.right + Math.max(0, rightOutside); + appletHandle.forceFloating = rightOutside > 0; + } } // Rectangle { color: "orange"; opacity: 0.1; visible: debug; anchors.fill: parent; } diff --git a/containments/desktop/package/contents/ui/AppletHandle.qml b/containments/desktop/package/contents/ui/AppletHandle.qml --- a/containments/desktop/package/contents/ui/AppletHandle.qml +++ b/containments/desktop/package/contents/ui/AppletHandle.qml @@ -49,6 +49,7 @@ property int minimumHeight: 6 * (root.iconSize + buttonMargin) signal removeApplet + signal moveFinished transform: Translate { x: handleMerged ? 0 : controlsOpacity * appletHandle.width @@ -289,6 +290,7 @@ animationsEnabled = true root.layoutManager.positionItem(appletItem) root.layoutManager.save() + appletHandle.moveFinished() } }