Debian Codegraph @

src/qml/outline/plasma/outline.qml

raw
1 /*
2 SPDX-FileCopyrightText: 2014 Martin Gräßlin <[email protected]>
3 SPDX-FileCopyrightText: 2017 Kai Uwe Broulik <[email protected]>
4
5 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
6 */
7 import QtQuick
8 import QtQuick.Window
9 import org.kde.kwin
10 import org.kde.ksvg 1.0 as KSvg
11 import org.kde.kirigami 2 as Kirigami
12
13 Window {
14 id: window
15
16 readonly property int animationDuration: Kirigami.Units.longDuration
17 property bool animationEnabled: false
18
19 flags: Qt.BypassWindowManagerHint | Qt.FramelessWindowHint
20 color: "transparent"
21
22 // outline is a context property
23 x: outline.unifiedGeometry.x
24 y: outline.unifiedGeometry.y
25 width: outline.unifiedGeometry.width
26 height: outline.unifiedGeometry.height
27
28 visible: outline.active
29
30 onVisibleChanged: {
31 if (visible) {
32 if (outline.visualParentGeometry.width > 0 && outline.visualParentGeometry.height > 0) {
33 window.animationEnabled = false
34 // move our frame to the visual parent geometry
35 svg.setGeometry(outline.visualParentGeometry)
36 window.animationEnabled = true
37 // and then animate it nicely to its destination
38 svg.setGeometry(outline.geometry)
39 } else {
40 // no visual parent? just move it to its destination right away
41 window.animationEnabled = false
42 svg.setGeometry(outline.geometry)
43 window.animationEnabled = true
44 }
45 }
46 }
47
48 Connections {
49 target: outline
50 // when unified geometry changes, this means our window position changed and any
51 // animation will potentially be offset and/or cut off, skip the animation in this case
52 function onUnifiedGeometryChanged() {
53 if (window.visible) {
54 window.animationEnabled = false
55 svg.setGeometry(outline.geometry)
56 window.animationEnabled = true
57 }
58 }
59 }
60
61 KSvg.FrameSvgItem {
62 id: svg
63
64 // takes into account the offset inside unified geometry
65 function setGeometry(geometry) {
66 x = geometry.x - outline.unifiedGeometry.x
67 y = geometry.y - outline.unifiedGeometry.y
68 width = geometry.width
69 height = geometry.height
70 }
71
72 imagePath: "widgets/translucentbackground"
73
74 x: 0
75 y: 0
76 width: 0
77 height: 0
78
79 enabledBorders: {
80 var maximizedArea = Workspace.clientArea(Workspace.MaximizeArea, Workspace.screenAt(Qt.point(outline.geometry.x, outline.geometry.y)), Workspace.currentDesktop);
81
82 var left = outline.geometry.x === maximizedArea.x;
83 var right = outline.geometry.x + outline.geometry.width === maximizedArea.x + maximizedArea.width;
84 var top = outline.geometry.y === maximizedArea.y;
85 var bottom = outline.geometry.y + outline.geometry.height === maximizedArea.y + maximizedArea.height;
86
87 var borders = KSvg.FrameSvgItem.AllBorders;
88 if (left) {
89 borders = borders & ~KSvg.FrameSvgItem.LeftBorder;
90 }
91 if (right) {
92 borders = borders & ~KSvg.FrameSvgItem.RightBorder;
93 }
94 if (top) {
95 borders = borders & ~KSvg.FrameSvgItem.TopBorder;
96 }
97 if (bottom) {
98 borders = borders & ~KSvg.FrameSvgItem.BottomBorder;
99 }
100 if (left && right && bottom && top) {
101 borders = KSvg.FrameSvgItem.AllBorders;
102 }
103 return borders;
104 }
105
106 Behavior on x {
107 NumberAnimation { duration: window.animationDuration; easing.type: Easing.InOutCubic; }
108 enabled: window.animationEnabled
109 }
110 Behavior on y {
111 NumberAnimation { duration: window.animationDuration; easing.type: Easing.InOutCubic; }
112 enabled: window.animationEnabled
113 }
114 Behavior on width {
115 NumberAnimation { duration: window.animationDuration; easing.type: Easing.InOutCubic; }
116 enabled: window.animationEnabled
117 }
118 Behavior on height {
119 NumberAnimation { duration: window.animationDuration; easing.type: Easing.InOutCubic; }
120 enabled: window.animationEnabled
121 }
122 }
123 }