Debian Codegraph @

qml/components/OverlayBlur.qml

raw
1 /*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.12
18 import QtGraphicalEffects 1.0
19
20 FastBlur {
21 id: overlayBlurEffect
22
23 property var overlayItem
24 property var backgroundItem
25 property alias live: overlayBlurShader.live
26 property var offset: Qt.point(0,0)
27 property alias recursive: overlayBlurShader.recursive
28
29 anchors.fill:parent
30
31 QtObject {
32 id:_internal
33 property var overlayItemToGlobal: overlayBlurEffect.overlayItem ? overlayBlurEffect.overlayItem.mapToGlobal(offset.x,offset.y) : Qt.point(0,0);
34 property var overlayToBackgroundMapping: overlayBlurEffect.backgroundItem ? overlayBlurEffect.backgroundItem.mapFromGlobal(overlayItemToGlobal.x,overlayItemToGlobal.y) : Qt.point(0,0);
35
36 function updateOverlayMapping() {
37 _internal.overlayItemToGlobal = Qt.binding(function() {return overlayBlurEffect.overlayItem.mapToGlobal(offset.x,offset.y); });
38 }
39
40 function updateBkMapping() {
41 _internal.overlayToBackgroundMapping = Qt.binding(function() {return backgroundItem.mapFromGlobal(overlayItemToGlobal.x,overlayItemToGlobal.y);});
42 }
43
44 }
45
46 Component.onCompleted: overlayBlurShader.updateRect();
47
48 onOverlayItemChanged: overlayBlurShader.updateRect();
49 onBackgroundItemChanged: overlayBlurShader.updateRect();
50
51 Connections {
52 target:overlayItem
53 onXChanged: overlayBlurShader.updateRect();
54 onYChanged: overlayBlurShader.updateRect();
55 onWidthChanged: overlayBlurShader.updateRect();
56 onHeightChanged: overlayBlurShader.updateRect();
57 onScaleChanged: overlayBlurShader.updateRect();
58 }
59
60 Connections {
61 target:backgroundItem
62 onXChanged: overlayBlurShader.updateRect();
63 onYChanged: overlayBlurShader.updateRect();
64 onWidthChanged: overlayBlurShader.updateRect();
65 onHeightChanged: overlayBlurShader.updateRect();
66 onScaleChanged: overlayBlurShader.updateRect();
67 }
68
69 onOffsetChanged: overlayBlurShader.updateRect();
70
71 radius:units.gu(3)
72 source: ShaderEffectSource {
73 id:overlayBlurShader
74 clip: true
75 sourceItem: backgroundItem
76
77 recursive: false
78
79 function updateRect() {
80 _internal.updateOverlayMapping();
81 _internal.updateBkMapping();
82 if(_internal.overlayToBackgroundMapping && overlayItem) {
83 sourceRect = Qt.binding(function() {
84 return Qt.rect( _internal.overlayToBackgroundMapping.x,
85 _internal.overlayToBackgroundMapping.y,
86 overlayItem.width,
87 overlayItem.height );
88 });
89 }
90 }
91 }
92 }