File: Shadows.qml

package info (click to toggle)
plasma-framework 5.116.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,088 kB
  • sloc: cpp: 29,562; javascript: 637; sh: 517; python: 145; xml: 110; php: 27; makefile: 7
file content (209 lines) | stat: -rw-r--r-- 8,024 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
    SPDX-FileCopyrightText: 2013 Digia Plc and /or its subsidiary(-ies) <http://www.qt-project.org/legal>

    This file is part of the examples of the Qt Toolkit.

    SPDX-License-Identifier: BSD-3-Clause
*/

import QtQuick 2.0
//import QtQuick.Particles 2.0

import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras

ShaderExample {

    pageName: "Shadows"
    pageDescription: ""
    Grid {
        id: cfgrid
        columns: 2

        anchors.top: parent.top
        anchors.right: parent.right
        width: parent.width * 0.6
        height: 96
        spacing: 6
        columnSpacing: 12
        PlasmaComponents.Label {
            text: "Distance:";
            width: parent.width * 0.5;
            horizontalAlignment: Text.AlignRight
            elide: Text.ElideRight
        }
        PlasmaComponents.Slider {
            width: parent.width * 0.4
            id: distanceSlider
            stepSize: 1
            minimumValue: 0
            maximumValue: 25
            value: 8
        }

        PlasmaComponents.Label {
            text: "Opacity:";
            horizontalAlignment: Text.AlignRight
            elide: Text.ElideRight
            width: parent.width * 0.5;
        }
        PlasmaComponents.Slider {
            width: parent.width * 0.4
            id: opacitySlider
//             stepSize: 250
            minimumValue: 0
            maximumValue: 1.0
            stepSize: 0.05
            value: 0.4
        }
    }

    Item {
        anchors.fill: parent
        clip: true
        anchors.margins: -_s

        Item {
            id: theItem
            anchors.fill: parent
            anchors.topMargin: _s * 2

            Column {
                id: "txtCol"
                anchors.fill: parent
                anchors.margins: _s
                anchors.topMargin: _s * 2
                spacing: _s

                PlasmaExtras.Heading {
                    text: "Effects on Components"

                }
                PlasmaExtras.Paragraph {
                    text:"In Plasma 2, the user interface is based on an OpenGL scenegraph, composition of the UI happens on the graphics card. In the past weeks, we've been working on getting a Plasma 2 shell up and running, and on porting the QML imports of the Plasma Components."
                }

                PlasmaExtras.Heading {
                    font.pointSize: 48
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.topMargin: _s * 3
                    text: "This is shadowy text."
                }
                Row {
                    height: 48
                    width: parent.width
                    spacing: _s

                    PlasmaCore.IconItem {
                        source: "configure"
                        width: parent.height
                        height: width
                    }
                    PlasmaCore.IconItem {
                        source: "dialog-ok"
                        width: parent.height
                        height: width
                    }

                    PlasmaCore.SvgItem {
                        id: buttonItem
                        svg: PlasmaCore.Svg {
                            id: configIconsSvg
                            imagePath: "widgets/configuration-icons"
                        }
                        elementId: "maximize"
                        width: parent.height
                        height: width
                    }

                    PlasmaCore.IconItem {
                        source: "akonadi"
                        width: parent.height
                        height: width
                    }
                    PlasmaCore.IconItem {
                        source: "clock"
                        width: parent.height
                        height: width
                    }
                }
            }
        }
        ShaderEffectSource {
            id: theSource
            sourceItem: theItem
            hideSource: true
        }

        ShaderEffect {
            anchors.fill: theItem
            property ShaderEffectSource source: theSource
            property ShaderEffectSource shadow: ShaderEffectSource {
                sourceItem: ShaderEffect {
                    width: theItem.width
                    height: theItem.height
                    property size delta: Qt.size(0.0, 1.0 / height)
                    property ShaderEffectSource source: ShaderEffectSource {
                        sourceItem: ShaderEffect {
                            width: theItem.width
                            height: theItem.height
                            property size delta: Qt.size(1.0 / width, 0.0)
                            property ShaderEffectSource source: theSource
                            fragmentShader: "
                                uniform lowp float qt_Opacity;
                                uniform sampler2D source;
                                uniform highp vec2 delta;
                                varying highp vec2 qt_TexCoord0;
                                void main() {
                                    gl_FragColor =(0.0538 * texture2D(source, qt_TexCoord0 - 3.182 * delta)
                                                 + 0.3229 * texture2D(source, qt_TexCoord0 - 1.364 * delta)
                                                 + 0.2466 * texture2D(source, qt_TexCoord0)
                                                 + 0.3229 * texture2D(source, qt_TexCoord0 + 1.364 * delta)
                                                 + 0.0538 * texture2D(source, qt_TexCoord0 + 3.182 * delta)) * qt_Opacity;
                                }"
                        }
                    }
                    fragmentShader: "
                        uniform lowp float qt_Opacity;
                        uniform sampler2D source;
                        uniform highp vec2 delta;
                        varying highp vec2 qt_TexCoord0;
                        void main() {
                            gl_FragColor =(0.0538 * texture2D(source, qt_TexCoord0 - 3.182 * delta)
                                         + 0.3229 * texture2D(source, qt_TexCoord0 - 1.364 * delta)
                                         + 0.2466 * texture2D(source, qt_TexCoord0)
                                         + 0.3229 * texture2D(source, qt_TexCoord0 + 1.364 * delta)
                                         + 0.0538 * texture2D(source, qt_TexCoord0 + 3.182 * delta)) * qt_Opacity;
                        }"
                }
            }
            property real angle: 0
            property point offset: Qt.point(distanceSlider.value * Math.cos(angle), distanceSlider.value * Math.sin(angle))
            NumberAnimation on angle { loops: Animation.Infinite; from: 0; to: Math.PI * 2; duration: 6000 }
            property size delta: Qt.size(offset.x / width, offset.y / height)
            property real darkness: opacitySlider.value // Changeme
            fragmentShader: "
                uniform lowp float qt_Opacity;
                uniform highp vec2 offset;
                uniform sampler2D source;
                uniform sampler2D shadow;
                uniform highp float darkness;
                uniform highp vec2 delta;
                varying highp vec2 qt_TexCoord0;
                void main() {
                    lowp vec4 fg = texture2D(source, qt_TexCoord0);
                    lowp vec4 bg = texture2D(shadow, qt_TexCoord0 + delta);
                    gl_FragColor = (fg + vec4(0., 0., 0., darkness * bg.a) * (1. - fg.a)) * qt_Opacity;
                }"
//             Slider {
//                 id: shadowSlider
//                 anchors.left: parent.left
//                 anchors.right: parent.right
//                 anchors.bottom: parent.bottom
//                 height: 40
//             }
        }

    }
}