From beb610abee80a8cb890807f60dd7f6e616d796bc Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sat, 13 Apr 2019 19:02:23 +0300 Subject: [PATCH] imrove click animation placement --- .../package/ui/FrontLayer.qml | 103 +++++++++++++++++- 1 file changed, 101 insertions(+), 2 deletions(-) diff --git a/indicators/org.kde.latte.plasma/package/ui/FrontLayer.qml b/indicators/org.kde.latte.plasma/package/ui/FrontLayer.qml index f5d81b563..94a7410b7 100644 --- a/indicators/org.kde.latte.plasma/package/ui/FrontLayer.qml +++ b/indicators/org.kde.latte.plasma/package/ui/FrontLayer.qml @@ -19,6 +19,7 @@ import QtQuick 2.0 +import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.latte 0.2 as Latte @@ -27,11 +28,57 @@ Item { anchors.fill: parent Item { + id: relevantItem anchors.fill: parent clip: true Item{ id: clickedCenter + + readonly property int center: plasmoid.formFactor === PlasmaCore.Types.Horizontal ? parent.width/2 : parent.height/2 + + states:[ + State { + name: "bottom" + when: (plasmoid.location === PlasmaCore.Types.BottomEdge) + + AnchorChanges { + target: clickedCenter + anchors{ top:undefined; bottom:parent.bottom; left:undefined; right:undefined; + horizontalCenter:parent.horizontalCenter; verticalCenter:undefined} + } + }, + State { + name: "left" + when: (plasmoid.location === PlasmaCore.Types.LeftEdge) + + AnchorChanges { + target: clickedCenter + anchors{ top:undefined; bottom:undefined; left:parent.left; right:undefined; + horizontalCenter:undefined; verticalCenter:parent.verticalCenter} + } + }, + State { + name: "right" + when: (plasmoid.location === PlasmaCore.Types.RightEdge) + + AnchorChanges { + target: clickedCenter + anchors{ top:undefined; bottom:undefined; left:undefined; right:parent.right; + horizontalCenter:undefined; verticalCenter:parent.verticalCenter} + } + }, + State { + name: "top" + when: (plasmoid.location === PlasmaCore.Types.TopEdge) + + AnchorChanges { + target: clickedCenter + anchors{ top:parent.top; bottom:undefined; left:undefined; right:undefined; + horizontalCenter:parent.horizontalCenter; verticalCenter:undefined} + } + } + ] } Rectangle { @@ -51,6 +98,12 @@ Item { script: { clickedRectangle.width = 0; clickedRectangle.opacity = 0.85; + clickedRectangle.anchors.rightMargin = 0; + clickedRectangle.anchors.leftMargin = 0; + clickedRectangle.anchors.topMargin = 0; + clickedRectangle.anchors.bottomMargin = 0; + clickedRectangle.anchors.horizontalCenterOffset = 0; + clickedRectangle.anchors.verticalCenterOffset = 0; } } @@ -75,8 +128,54 @@ Item { Connections { target: level onMousePressed: { - clickedCenter.x = x; - clickedCenter.y = y; + var fixedX = 0; + var fixedY = 0; + + if (plasmoid.formFactor === PlasmaCore.Types.Horizontal) { + fixedX = x - clickedCenter.center; + } else { + if (plasmoid.location === PlasmaCore.Types.RightEdge) { + fixedX = relevantItem.width - x; + } else { + fixedX = x; + } + } + + if (plasmoid.formFactor === PlasmaCore.Types.Vertical) { + fixedY = y - clickedCenter.center; + } else { + if (plasmoid.location === PlasmaCore.Types.BottomEdge) { + fixedY = relevantItem.height - y; + } else { + fixedY = y; + } + } + + if (plasmoid.formFactor === PlasmaCore.Types.Horizontal) { + clickedCenter.anchors.horizontalCenterOffset = fixedX; + } else { + if (plasmoid.location === PlasmaCore.Types.LeftEdge) { + clickedCenter.anchors.leftMargin = fixedX; + } else if (plasmoid.location === PlasmaCore.Types.RightEdge) { + clickedCenter.anchors.rightMargin = fixedX; + } + } + + if (plasmoid.formFactor === PlasmaCore.Types.Vertical) { + clickedCenter.anchors.verticalCenterOffset = fixedY; + } else { + if (plasmoid.location === PlasmaCore.Types.BottomEdge) { + clickedCenter.anchors.bottomMargin = fixedY; + } else if (plasmoid.location === PlasmaCore.Types.TopEdge) { + clickedCenter.anchors.topMargin = fixedY; + } + } + + + + + clickedCenter.anchors.verticalCenterOffset = fixedY; + clickedAnimation.start(); } }