1/*
2    SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
3    SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6import QtQuick 2.1
7
8import org.kde.plasma.core 2.0 as PlasmaCore
9import QtGraphicalEffects 1.0
10
11Item{
12    id: shadowRoot
13
14    property int shadowDirection: PlasmaCore.Types.BottomEdge
15    property int shadowSize: 7
16    property real shadowOpacity: 1
17    property color shadowColor: "#040404"
18
19    readonly property bool isHorizontal : (shadowDirection !== PlasmaCore.Types.LeftEdge) && (shadowDirection !== PlasmaCore.Types.RightEdge)
20
21    readonly property int implicitWidth: shadow.width
22    readonly property int implicitHeight: shadow.height
23
24    Item{
25        id: shadow
26        width: isHorizontal ? shadowRoot.width + 2*shadowSize : shadowSize
27        height: isHorizontal ? shadowSize: shadowRoot.height + 2*shadowSize
28        opacity: shadowOpacity
29
30        clip: true
31
32        Rectangle{
33            id: editShadow
34            width: shadowRoot.width
35            height: shadowRoot.height
36            color: "white"
37
38            layer.enabled: true
39            layer.effect: DropShadow {
40                radius: shadowSize
41                fast: true
42                samples: 2 * radius
43                color: shadowRoot.shadowColor
44            }
45        }
46
47        states: [
48            ///topShadow
49            State {
50                name: "topShadow"
51                when: (shadowDirection === PlasmaCore.Types.BottomEdge)
52
53                AnchorChanges {
54                    target: editShadow
55                    anchors{ top:parent.top; bottom:undefined; left:parent.left; right:undefined}
56                }
57                PropertyChanges{
58                    target: editShadow
59                    anchors{ leftMargin: 0; rightMargin:0; topMargin:shadowSize; bottomMargin:0}
60                }
61            },
62            ///bottomShadow
63            State {
64                name: "bottomShadow"
65                when: (shadowDirection === PlasmaCore.Types.TopEdge)
66
67                AnchorChanges {
68                    target: editShadow
69                    anchors{ top:undefined; bottom:parent.bottom; left:parent.left; right:undefined}
70                }
71                PropertyChanges{
72                    target: editShadow
73                    anchors{ leftMargin: 0; rightMargin:0; topMargin:0; bottomMargin:shadowSize}
74                }
75            },
76            ///leftShadow
77            State {
78                name: "leftShadow"
79                when: (shadowDirection === PlasmaCore.Types.RightEdge)
80
81                AnchorChanges {
82                    target: editShadow
83                    anchors{ top:parent.top; bottom: undefined; left:parent.left; right:undefined}
84                }
85                PropertyChanges{
86                    target: editShadow
87                    anchors{ leftMargin: shadowSize; rightMargin:0; topMargin:0; bottomMargin:0}
88                }
89            },
90            ///rightShadow
91            State {
92                name: "rightShadow"
93                when: (shadowDirection === PlasmaCore.Types.LeftEdge)
94
95                AnchorChanges {
96                    target: editShadow
97                    anchors{top:parent.top; bottom:undefined; left:undefined; right:parent.right}
98                }
99                PropertyChanges{
100                    target: editShadow
101                    anchors{ leftMargin: 0; rightMargin:shadowSize; topMargin:0; bottomMargin:0}
102                }
103            }
104        ]
105    }
106}
107