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 @@ -42,16 +42,44 @@ property bool hasBackground: false property bool handleMerged: (height > minimumHandleHeight && !appletHandle.forceFloating) property bool animationsEnabled: false + property bool floating: true // turns off layoutManagment space handling for appletItem + + property alias innerEndHeight: mouseListener.endHeight + property alias innerEndWidth: mouseListener.endWidth + property alias innerHeight: mouseListener.height + property alias innerWidth: mouseListener.width + + // bindings needed for handling situation when minimum > maximum + // they would not break in js assignment + property int minimumWidth + Binding on minimumWidth { + value: Math.max(root.layoutManager.cellSize.width, + appletContainer.minimumWidth + + appletContainer.anchors.leftMargin + + appletContainer.anchors.rightMargin - handleWidth); + } - property int minimumWidth: Math.max(root.layoutManager.cellSize.width, - appletContainer.minimumWidth + - appletItem.contents.anchors.leftMargin + - appletItem.contents.anchors.rightMargin) + property int minimumHeight + Binding on minimumHeight { + value: Math.max(root.layoutManager.cellSize.height, + appletContainer.minimumHeight + + appletContainer.anchors.topMargin + + appletContainer.anchors.bottomMargin); + } - property int minimumHeight: Math.max(root.layoutManager.cellSize.height, - appletContainer.minimumHeight + - appletItem.contents.anchors.topMargin + - appletItem.contents.anchors.bottomMargin) + property int maximumWidth + Binding on maximumWidth { + value: appletContainer.maximumWidth + + appletContainer.anchors.leftMargin + + appletContainer.anchors.rightMargin - handleWidth; + } + + property int maximumHeight + Binding on maximumHeight { + value: appletContainer.maximumHeight + + appletContainer.anchors.topMargin + + appletContainer.anchors.bottomMargin; + } property alias applet: appletContainer.applet @@ -61,8 +89,120 @@ visible: false - onMinimumWidthChanged: if (!widthAnimation.running) appletItem.width = Math.max(minimumWidth, width); - onMinimumHeightChanged: if (!heightAnimation.running) appletItem.height = Math.max(minimumHeight, height); + QtObject { + id: d + + property real lastX: 0 + property real lastY: 0 + } + + onMinimumWidthChanged: { + if (minimumWidth > maximumWidth) + maximumWidth = minimumWidth; + if (width < minimumWidth) { + releasePosition(); + width = minimumWidth; + positionItem(); + if (showAppletHandle && !handleMerged) + appletHandle.positionHandle(); + } + } + onMinimumHeightChanged: { + if (minimumHeight > maximumHeight) + maximumHeight = minimumHeight; + if (height < minimumHeight) { + releasePosition(); + height = minimumHeight; + positionItem(); + if (showAppletHandle && !handleMerged) + appletHandle.positionHandle(); + } + } + + onMaximumWidthChanged: { + if (maximumWidth < minimumWidth) + minimumWidth = maximumWidth; + if (width > maximumWidth) { + releasePosition(); + width = maximumWidth; + positionItem(); + if (showAppletHandle && !handleMerged) + appletHandle.positionHandle(); + } + } + onMaximumHeightChanged: { + if (maximumHeight < minimumHeight) + minimumHeight = maximumHeight; + if (height > maximumHeight) { + releasePosition(); + height = maximumHeight; + positionItem(); + if (showAppletHandle && !handleMerged) + appletHandle.positionHandle(); + } + } + + onHeightChanged: { + if (height > maximumHeight) + innerEndHeight = maximumHeight; + else if (height < minimumHeight) + innerEndHeight = minimumHeight; + else + innerEndHeight = height; + } + onWidthChanged: { + if (width > maximumWidth) + innerEndWidth = maximumWidth; + else if (width < minimumWidth) + innerEndWidth = minimumWidth; + else + innerEndWidth = width; + } + + onXChanged: { + if (animationsEnabled) { + animationsEnabled = false; + mouseListener.x += d.lastX - x; + animationsEnabled = true; + } + mouseListener.x = mouseListener.endX = (width - innerEndWidth)/2; + d.lastX = x; + } + onYChanged: { + if (animationsEnabled) { + animationsEnabled = false; + mouseListener.y += d.lastY - y; + animationsEnabled = true; + } + mouseListener.y = mouseListener.endY = (height - innerEndHeight)/2; + d.lastY = y; + } + + // use this function to position appletItem instead of root.layoutManager.positionItem(appletItem) + function positionItem() { + if (floating) + return; + var tempItem = { + x: appletItem.x, + y: appletItem.y, + width: appletItem.innerEndWidth, + height: appletItem.innerEndHeight, + minimumHeight: appletItem.minimumHeight, + minimumWidth: appletItem.minimumWidth }; + root.layoutManager.positionItem(tempItem); + x = tempItem.x; + y = tempItem.y; + height = tempItem.height; + width = tempItem.width; + root.layoutManager.saveItem(appletItem); + } + + // use this function to free appletItem position instead of + // root.layoutManager.setSpaceAvailable(appletItem.x, appletItem.y, appletItem.width, appletItem.height, true) + function releasePosition() { + if (!floating) + root.layoutManager.setSpaceAvailable(x, y, width, height, true); + } function updateBackgroundHints() { hasBackground = (applet.backgroundHints != "NoBackground"); @@ -84,17 +224,24 @@ KQuickControlsAddons.MouseEventListener { id: mouseListener + // used as inner applet (which would not be sized over or under size limits ) + // centered in appletItem.onXChanged and onYChanged due to allow animations on X and Y - anchors { - fill: parent - } + property int pressX: -1 + property int pressY: -1 + + // for animations + property int endHeight: minimumHeight + property int endWidth: minimumWidth + property int endX: 0 + property int endY: 0 + + height: endHeight + width: endWidth z: 10 hoverEnabled: true - property int pressX: -1 - property int pressY: -1 - onPressed: { pressX = mouse.x; pressY = mouse.y; @@ -143,7 +290,6 @@ Item { anchors { left: parent.left; top: parent.top; bottom: parent.bottom; } width: parent.width+handleWidth; - z: mouseListener.z + 4 PlasmaCore.FrameSvgItem { @@ -175,7 +321,7 @@ if (applet.id == appletItem.applet.id) { // print("Destroying Applet-" + applet.id) root.layoutManager.saveRotation(appletItem); - root.layoutManager.setSpaceAvailable(appletItem.x, appletItem.y, appletItem.width, appletItem.height, true) + appletItem.releasePosition(); //applet.action("remove").trigger(); //appletItem.destroy() appletItem.destroy(); @@ -214,7 +360,8 @@ repositionTimer.running = false; placeHolderPaint.opacity = 0; animationsEnabled = true; - root.layoutManager.positionItem(appletItem); + appletItem.floating = false; + appletItem.positionItem(); root.layoutManager.save(); dragging = false; } @@ -225,9 +372,10 @@ onPressed: { appletItem.z = appletItem.z + zoffset; - animationsEnabled = plasmoid.configuration.pressToMove ? true : false; + animationsEnabled = false; mouse.accepted = true; - root.layoutManager.setSpaceAvailable(appletItem.x, appletItem.y, appletItem.width, appletItem.height, true); + appletItem.releasePosition(); + appletItem.floating = true; placeHolder.syncWithItem(appletItem); placeHolderPaint.opacity = root.haloOpacity; @@ -283,24 +431,46 @@ return size; } + property var maximumSize: { + var size; + if (applet && applet.Layout) { + var layout = applet.Layout + size = { 'width': layout.maximumWidth, + 'height': layout.maximumHeight }; + } else { + size = { 'width': Number.POSITIVE_INFINITY, + 'height': Number.POSITIVE_INFINITY }; + + } + var maxInt = 1000000; // dirty hack to convert js number to qml int + if (size.width > maxInt) + size.width = maxInt; + if (size.height > maxInt) + size.height = maxInt; + + return size; + } + property int minimumWidth: minimumSize.width; property int minimumHeight: minimumSize.height; + property int maximumWidth: maximumSize.width; + property int maximumHeight: maximumSize.height; + function appletDestroyed() { // print("Applet DESTROYED."); - root.layoutManager.setSpaceAvailable(appletItem.x, appletItem.y, appletItem.width, appletItem.height, true) + appletItem.releasePosition(); applet.action("remove").trigger(); appletItem.destroy() } onAppletChanged: { if (!applet) { return; } - applet.parent = appletContainer; applet.anchors.fill = appletContainer; - + updateBackgroundHints(); } Connections { @@ -378,9 +548,9 @@ { // 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 x = Math.min(Math.max(0, appletItem.x + mouseListener.endX), available.width - appletItem.width + mouseListener.endX); + var y = Math.min(Math.max(0, appletItem.y + mouseListener.endY), available.height - appletItem.height + mouseListener.endY); + var verticalCenter = (y + mouseListener.endHeight / 2); var topOutside = (verticalCenter - minimumHandleHeight / 2); var bottomOutside = verticalCenter + minimumHandleHeight / 2 - available.height; if (bottomOutside > 0) { @@ -390,52 +560,54 @@ } else { anchors.verticalCenterOffset = 0; } - var rightOutside = x + appletItem.width + handleWidth - available.width; + var rightOutside = x + mouseListener.endWidth + handleWidth - available.width; appletHandle.anchors.rightMargin = appletItem.margins.right + Math.max(0, rightOutside); appletHandle.forceFloating = rightOutside > 0; } } } - } - Behavior on controlsOpacity { - NumberAnimation { - duration: units.longDuration - easing.type: Easing.InOutQuad + Behavior on x { + enabled: animationsEnabled + NumberAnimation { + duration: units.longDuration + easing.type: Easing.InOutQuad + } } - } - Behavior on x { - enabled: animationsEnabled - NumberAnimation { - duration: units.longDuration - easing.type: Easing.InOutQuad + Behavior on y { + enabled: animationsEnabled + NumberAnimation { + duration: units.longDuration + easing.type: Easing.InOutQuad + } } - } - Behavior on y { - enabled: animationsEnabled - NumberAnimation { - duration: units.longDuration - easing.type: Easing.InOutQuad + Behavior on width { + enabled: animationsEnabled + NumberAnimation { + id: widthAnimation + duration: units.longDuration + easing.type: Easing.InOutQuad + } } - } - Behavior on width { - enabled: animationsEnabled - NumberAnimation { - id: widthAnimation - duration: units.longDuration - easing.type: Easing.InOutQuad + Behavior on height { + enabled: animationsEnabled + NumberAnimation { + id: heightAnimation + duration: units.longDuration + easing.type: Easing.InOutQuad + } } } - Behavior on height { - enabled: animationsEnabled + + Behavior on controlsOpacity { NumberAnimation { - id: heightAnimation duration: units.longDuration easing.type: Easing.InOutQuad } } Component.onCompleted: { + floating = false; layoutTimer.running = true layoutTimer.restart() visible = false 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 @@ -31,7 +31,7 @@ opacity: appletItem.controlsOpacity visible: opacity > 0 width: appletItem.handleWidth - height: Math.max(appletItem.height - appletItem.margins.top - appletItem.margins.bottom, buttonColumn.implicitHeight) + height: Math.max(appletItem.innerHeight - appletItem.margins.top - appletItem.margins.bottom, buttonColumn.implicitHeight) hoverEnabled: true onContainsMouseChanged: { if (!containsMouse && !pressed) { @@ -43,6 +43,7 @@ hoverTracker.restart() } } + //z: dragMouseArea.z + 1 property int buttonMargin: 6 @@ -89,7 +90,7 @@ } ColumnLayout { id: buttonColumn - width: handleWidth + width: appletItem.handleWidth anchors { top: parent.top @@ -120,31 +121,30 @@ animationsEnabled = false; startX = mouse.x; startY = mouse.y; - root.layoutManager.setSpaceAvailable(appletItem.x, appletItem.y, appletItem.width, appletItem.height, true) + appletItem.releasePosition(); + appletItem.floating = true; appletContainer.clip = true } onPositionChanged: { - var minimumWidth = appletItem.minimumWidth + appletHandle.width; - var minimumHeight = appletItem.minimumHeight; - var xDelta = startX - mouse.x; var yDelta = startY - mouse.y; - + if (LayoutMirroring.enabled) { var oldRight = appletItem.x + appletItem.width; - appletItem.width = Math.max(minimumWidth, appletItem.width + xDelta); + appletItem.width = Math.min(Math.max(appletItem.minimumWidth, appletItem.width + xDelta), appletItem.maximumWidth); appletItem.x = oldRight - appletItem.width; } else { - appletItem.width = Math.max(minimumWidth, appletItem.width - xDelta); + appletItem.width = Math.min(Math.max(appletItem.minimumWidth, appletItem.width - xDelta), appletItem.maximumWidth); } var oldBottom = appletItem.y + appletItem.height; - appletItem.height = Math.max(minimumHeight, appletItem.height + yDelta); + appletItem.height = Math.min(Math.max(appletItem.minimumHeight, appletItem.height + yDelta), appletItem.maximumHeight); appletItem.y = oldBottom - appletItem.height; } onReleased: { animationsEnabled = true - root.layoutManager.positionItem(appletItem) + appletItem.floating = false; + appletItem.positionItem(); root.layoutManager.save() appletContainer.clip = false } @@ -272,7 +272,8 @@ appletItem.z = appletItem.z + zoffset; animationsEnabled = false mouse.accepted = true - root.layoutManager.setSpaceAvailable(appletItem.x, appletItem.y, appletItem.width, appletItem.height, true) + appletItem.releasePosition(); + appletItem.floating = true; placeHolder.syncWithItem(appletItem) placeHolderPaint.opacity = root.haloOpacity; @@ -295,7 +296,8 @@ repositionTimer.running = false placeHolderPaint.opacity = 0 animationsEnabled = true - root.layoutManager.positionItem(appletItem) + appletItem.floating = false; + appletItem.positionItem(); root.layoutManager.save() appletHandle.moveFinished() }