Changeset View
Changeset View
Standalone View
Standalone View
qml/outline/plasma/outline.qml
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright 2014 Martin Gräßlin <mgraesslin@kde.org> | 2 | * Copyright 2014 Martin Gräßlin <mgraesslin@kde.org> | ||
3 | * Copyright 2017 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | 4 | * | ||
4 | * This program is free software; you can redistribute it and/or | 5 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License as | 6 | * modify it under the terms of the GNU General Public License as | ||
6 | * published by the Free Software Foundation; either version 2 of | 7 | * published by the Free Software Foundation; either version 2 of | ||
7 | * the License or (at your option) version 3 or any later version | 8 | * the License or (at your option) version 3 or any later version | ||
8 | * accepted by the membership of KDE e.V. (or its successor approved | 9 | * accepted by the membership of KDE e.V. (or its successor approved | ||
9 | * by the membership of KDE e.V.), which shall act as a proxy | 10 | * by the membership of KDE e.V.), which shall act as a proxy | ||
10 | * defined in Section 14 of version 3 of the license. | 11 | * defined in Section 14 of version 3 of the license. | ||
11 | * | 12 | * | ||
12 | * This program is distributed in the hope that it will be useful, | 13 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | 16 | * GNU General Public License for more details. | ||
16 | * | 17 | * | ||
17 | * You should have received a copy of the GNU General Public License | 18 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 20 | */ | ||
20 | import QtQuick 2.1; | 21 | import QtQuick 2.1 | ||
21 | import QtQuick.Window 2.1; | 22 | import QtQuick.Window 2.1 | ||
22 | import org.kde.plasma.core 2.0 as PlasmaCore; | 23 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
23 | 24 | | |||
24 | Window { | 25 | Window { | ||
25 | id: window | 26 | id: window | ||
27 | | ||||
28 | readonly property int animationDuration: units.longDuration | ||||
29 | property bool animationEnabled: false | ||||
30 | | ||||
26 | flags: Qt.BypassWindowManagerHint | Qt.FramelessWindowHint | 31 | flags: Qt.BypassWindowManagerHint | Qt.FramelessWindowHint | ||
27 | color: "transparent" | 32 | color: "transparent" | ||
28 | 33 | | |||
29 | // outline is a context property | 34 | // outline is a context property | ||
30 | x: outline.geometry.x | 35 | x: outline.unifiedGeometry.x | ||
31 | y: outline.geometry.y | 36 | y: outline.unifiedGeometry.y | ||
32 | width: outline.geometry.width | 37 | width: outline.unifiedGeometry.width | ||
33 | height: outline.geometry.height | 38 | height: outline.unifiedGeometry.height | ||
39 | | ||||
34 | visible: outline.active | 40 | visible: outline.active | ||
35 | 41 | | |||
36 | PlasmaCore.FrameSvgItem { | 42 | onVisibleChanged: { | ||
37 | function updateBorders() { | 43 | if (visible) { | ||
38 | var maximizedArea = workspace.clientArea(workspace.MaximizeArea, Qt.point(outline.geometry.x, outline.geometry.y), workspace.currentDesktop); | 44 | if (outline.visualParentGeometry.width > 0 && outline.visualParentGeometry.height > 0) { | ||
39 | var left = false; | 45 | window.animationEnabled = false | ||
40 | var right = false; | 46 | // move our frame to the visual parent geometry | ||
41 | var top = false; | 47 | svg.setGeometry(outline.visualParentGeometry) | ||
42 | var bottom = false; | 48 | window.animationEnabled = true | ||
43 | if (outline.geometry.x == maximizedArea.x) { | 49 | // and then animate it nicely to its destination | ||
44 | left = true; | 50 | svg.setGeometry(outline.geometry) | ||
51 | } else { | ||||
52 | // no visual parent? just move it to its destination right away | ||||
53 | window.animationEnabled = false | ||||
54 | svg.setGeometry(outline.geometry) | ||||
55 | window.animationEnabled = true | ||||
56 | } | ||||
57 | } | ||||
45 | } | 58 | } | ||
46 | if (outline.geometry.y == maximizedArea.y) { | 59 | | ||
47 | top = true; | 60 | Connections { | ||
61 | target: outline | ||||
62 | // when unified geometry changes, this means our window position changed and any | ||||
63 | // animation will potentially be offset and/or cut off, skip the animation in this case | ||||
64 | onUnifiedGeometryChanged: { | ||||
65 | if (window.visible) { | ||||
66 | window.animationEnabled = false | ||||
67 | svg.setGeometry(outline.geometry) | ||||
68 | window.animationEnabled = true | ||||
48 | } | 69 | } | ||
49 | if (outline.geometry.x + outline.geometry.width == maximizedArea.x + maximizedArea.width) { | | |||
50 | right = true; | | |||
51 | } | 70 | } | ||
52 | if (outline.geometry.y + outline.geometry.height == maximizedArea.y + maximizedArea.height) { | | |||
53 | bottom = true; | | |||
54 | } | 71 | } | ||
72 | | ||||
73 | PlasmaCore.FrameSvgItem { | ||||
74 | id: svg | ||||
75 | | ||||
76 | // takes into account the offset inside unified geometry | ||||
77 | function setGeometry(geometry) { | ||||
78 | x = geometry.x - outline.unifiedGeometry.x | ||||
79 | y = geometry.y - outline.unifiedGeometry.y | ||||
80 | width = geometry.width | ||||
81 | height = geometry.height | ||||
82 | } | ||||
83 | | ||||
84 | imagePath: "widgets/translucentbackground" | ||||
85 | | ||||
86 | x: 0 | ||||
87 | y: 0 | ||||
88 | width: 0 | ||||
89 | height: 0 | ||||
90 | | ||||
91 | enabledBorders: { | ||||
92 | var maximizedArea = workspace.clientArea(workspace.MaximizeArea, Qt.point(outline.geometry.x, outline.geometry.y), workspace.currentDesktop); | ||||
93 | | ||||
94 | var left = outline.geometry.x === maximizedArea.x; | ||||
95 | var right = outline.geometry.x + outline.geometry.width === maximizedArea.x + maximizedArea.width; | ||||
96 | var top = outline.geometry.y === maximizedArea.y; | ||||
97 | var bottom = outline.geometry.y + outline.geometry.height === maximizedArea.y + maximizedArea.height; | ||||
98 | | ||||
55 | var borders = PlasmaCore.FrameSvgItem.AllBorders; | 99 | var borders = PlasmaCore.FrameSvgItem.AllBorders; | ||
56 | if (left) { | 100 | if (left) { | ||
57 | borders = borders & ~PlasmaCore.FrameSvgItem.LeftBorder; | 101 | borders = borders & ~PlasmaCore.FrameSvgItem.LeftBorder; | ||
58 | } | 102 | } | ||
59 | if (right) { | 103 | if (right) { | ||
60 | borders = borders & ~PlasmaCore.FrameSvgItem.RightBorder; | 104 | borders = borders & ~PlasmaCore.FrameSvgItem.RightBorder; | ||
61 | } | 105 | } | ||
62 | if (top) { | 106 | if (top) { | ||
63 | borders = borders & ~PlasmaCore.FrameSvgItem.TopBorder; | 107 | borders = borders & ~PlasmaCore.FrameSvgItem.TopBorder; | ||
64 | } | 108 | } | ||
65 | if (bottom) { | 109 | if (bottom) { | ||
66 | borders = borders & ~PlasmaCore.FrameSvgItem.BottomBorder; | 110 | borders = borders & ~PlasmaCore.FrameSvgItem.BottomBorder; | ||
67 | } | 111 | } | ||
68 | if (left && right && bottom && top) { | 112 | if (left && right && bottom && top) { | ||
69 | borders = PlasmaCore.FrameSvgItem.AllBorders; | 113 | borders = PlasmaCore.FrameSvgItem.AllBorders; | ||
70 | } | 114 | } | ||
71 | svg.enabledBorders = borders; | 115 | return borders; | ||
72 | } | 116 | } | ||
73 | id: svg | 117 | | ||
74 | imagePath: "widgets/translucentbackground" | 118 | Behavior on x { | ||
75 | anchors.fill: parent | 119 | NumberAnimation { duration: window.animationDuration; easing.type: Easing.InOutQuad; } | ||
76 | Connections { | 120 | enabled: window.animationEnabled | ||
77 | target: outline | 121 | } | ||
78 | onGeometryChanged: svg.updateBorders() | 122 | Behavior on y { | ||
123 | NumberAnimation { duration: window.animationDuration; easing.type: Easing.InOutQuad; } | ||||
124 | enabled: window.animationEnabled | ||||
125 | } | ||||
126 | Behavior on width { | ||||
127 | NumberAnimation { duration: window.animationDuration; easing.type: Easing.InOutQuad; } | ||||
128 | enabled: window.animationEnabled | ||||
129 | } | ||||
130 | Behavior on height { | ||||
131 | NumberAnimation { duration: window.animationDuration; easing.type: Easing.InOutQuad; } | ||||
132 | enabled: window.animationEnabled | ||||
79 | } | 133 | } | ||
80 | Component.onCompleted: svg.updateBorders() | | |||
81 | } | 134 | } | ||
82 | } | 135 | } |