Warning, /plasma/latte-dock/declarativeimports/components/GlowPoint.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * Copyright 2019 Michail Vourlakos <mvourlakos@gmail.com> 0003 * 0004 * This file is part of Latte-Dock 0005 * 0006 * Latte-Dock is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * Latte-Dock is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 import QtQuick 2.0 0021 import QtGraphicalEffects 1.0 0022 0023 import org.kde.plasma.components 2.0 as Components 0024 import org.kde.plasma.core 2.0 as PlasmaCore 0025 import org.kde.plasma.plasmoid 2.0 0026 0027 Item{ 0028 // property string color 0029 id: glowItem 0030 0031 property bool glow3D: true 0032 property bool roundCorners: true 0033 property bool showBorder: false 0034 property bool showAttention: false 0035 property bool showGlow: false 0036 0037 property int animation: 250 0038 property int location: PlasmaCore.Types.BottomEdge 0039 property int size: 10 0040 0041 property real glowOpacity: 0.75 0042 0043 property color attentionColor: "red" 0044 property color basicColor: "blue" 0045 property color contrastColor: "#b0b0b0" 0046 property color currentColor: glowItem.showAttention ? animationColorAlpha : basicColorAlpha 0047 0048 property color animationColor: "red" // it is used only internally for the animation 0049 readonly property color basicColorAlpha: Qt.rgba(basicColor.r, basicColor.g, basicColor.b, glowOpacity) 0050 readonly property color animationColorAlpha: Qt.rgba(animationColor.r, animationColor.g, animationColor.b, glowOpacity) 0051 readonly property color contrastColorAlpha: Qt.rgba(contrastColor.r, contrastColor.g, contrastColor.b, Math.min(glowOpacity+0.25,1)) 0052 readonly property color contrastColorAlpha2: Qt.rgba(contrastColor.r, contrastColor.g, contrastColor.b, 0.3) 0053 0054 readonly property bool isVertical: (location === PlasmaCore.Types.LeftEdge) || (location === PlasmaCore.Types.RightEdge) 0055 readonly property bool isHorizontal: !isVertical 0056 0057 Grid{ 0058 id: mainGlow 0059 anchors.horizontalCenter: parent.horizontalCenter 0060 anchors.verticalCenter: parent.verticalCenter 0061 visible: glowItem.showGlow 0062 0063 rows: isHorizontal ? 1 : 0 0064 columns: isVertical ? 1 : 0 0065 0066 property int halfCorner: 3*glowItem.size 0067 property int fullCorner: 6*glowItem.size 0068 0069 Item { 0070 id: firstGlowCorner 0071 width: isHorizontal ? mainGlow.halfCorner : mainGlow.fullCorner 0072 height: isHorizontal ? mainGlow.fullCorner : mainGlow.halfCorner 0073 clip: true 0074 0075 Item { 0076 id: firstGlowCornerFull 0077 width: mainGlow.fullCorner 0078 height: mainGlow.fullCorner 0079 0080 RadialGradient { 0081 anchors.fill: parent 0082 gradient: Gradient { 0083 GradientStop { position: 0.0; color: "transparent" } 0084 GradientStop { position: 0.07; color: glowItem.contrastColorAlpha } 0085 GradientStop { position: 0.125; color: glowItem.currentColor } 0086 GradientStop { position: 0.4; color: "transparent" } 0087 GradientStop { position: 1; color: "transparent" } 0088 } 0089 } 0090 0091 states: [ 0092 State{ 0093 name: "*" 0094 when: isHorizontal 0095 0096 AnchorChanges{ 0097 target:firstGlowCornerFull; 0098 anchors{ bottom: undefined; left:parent.left;} 0099 } 0100 }, 0101 State{ 0102 name: "vertical" 0103 when: isVertical 0104 0105 AnchorChanges{ 0106 target:firstGlowCornerFull; 0107 anchors{ top: parent.top; left:undefined;} 0108 } 0109 } 0110 ] 0111 } 0112 } 0113 0114 Item { 0115 id:mainGlowPart 0116 width: isHorizontal ? glowItem.width - glowItem.size : mainGlow.fullCorner 0117 height: isHorizontal ? mainGlow.fullCorner : glowItem.height - glowItem.size 0118 0119 LinearGradient { 0120 anchors.fill: parent 0121 start: { 0122 if (location === PlasmaCore.Types.BottomEdge || location === PlasmaCore.Types.Floating) 0123 return Qt.point(0, 0); 0124 else if (location === PlasmaCore.Types.TopEdge) 0125 return Qt.point(0, mainGlow.fullCorner); 0126 else if (location === PlasmaCore.Types.LeftEdge) 0127 return Qt.point(mainGlow.fullCorner, 0); 0128 else if (location === PlasmaCore.Types.RightEdge) 0129 return Qt.point(0, 0); 0130 0131 return Qt.point(mainGlow.fullCorner, 0); 0132 } 0133 end: { 0134 if (location === PlasmaCore.Types.BottomEdge || location === PlasmaCore.Types.Floating) 0135 return Qt.point(0, mainGlow.fullCorner); 0136 else if (location === PlasmaCore.Types.TopEdge) 0137 return Qt.point(0, 0); 0138 else if (location === PlasmaCore.Types.LeftEdge) 0139 return Qt.point(0,0); 0140 else if (location === PlasmaCore.Types.RightEdge) 0141 return Qt.point(mainGlow.fullCorner, 0); 0142 0143 return Qt.point(0,0); 0144 } 0145 0146 gradient: Gradient { 0147 GradientStop { position: 0.0; color: "transparent" } 0148 GradientStop { position: 0.08; color: "transparent" } 0149 GradientStop { position: 0.37; color: glowItem.currentColor } 0150 GradientStop { position: 0.43; color: glowItem.contrastColorAlpha } 0151 GradientStop { position: 0.57; color: glowItem.contrastColorAlpha } 0152 GradientStop { position: 0.63; color: glowItem.currentColor } 0153 GradientStop { position: 0.92; color: "transparent" } 0154 GradientStop { position: 1; color: "transparent" } 0155 } 0156 } 0157 } 0158 0159 Item { 0160 id:lastGlowCorner 0161 width: isHorizontal ? mainGlow.halfCorner : mainGlow.fullCorner 0162 height: isHorizontal ? mainGlow.fullCorner : mainGlow.halfCorner 0163 clip: true 0164 0165 Item { 0166 id: lastGlowCornerFull 0167 width: mainGlow.fullCorner 0168 height: mainGlow.fullCorner 0169 0170 RadialGradient { 0171 anchors.fill: parent 0172 gradient: Gradient { 0173 GradientStop { position: 0.0; color: "transparent" } 0174 GradientStop { position: 0.07; color: glowItem.contrastColorAlpha } 0175 GradientStop { position: 0.125; color: glowItem.currentColor } 0176 GradientStop { position: 0.4; color: "transparent"} 0177 GradientStop { position: 1; color: "transparent" } 0178 } 0179 } 0180 0181 states: [ 0182 State{ 0183 name: "*" 0184 when: isHorizontal 0185 0186 AnchorChanges{ 0187 target:lastGlowCornerFull; 0188 anchors{ bottom: undefined; right:parent.right;} 0189 } 0190 }, 0191 State{ 0192 name: "vertical" 0193 when: isVertical 0194 0195 AnchorChanges{ 0196 target:lastGlowCornerFull; 0197 anchors{ bottom: parent.bottom; right:undefined;} 0198 } 0199 } 0200 ] 0201 } 0202 } 0203 } 0204 0205 //! add border around indicator without reducing its size 0206 Loader{ 0207 anchors.centerIn: mainElement 0208 active: glowItem.showBorder 0209 0210 sourceComponent:Rectangle { 0211 width: mainElement.width + size 0212 height: mainElement.height + size 0213 anchors.centerIn: parent 0214 0215 color: contrastColorAlpha2 0216 radius: glowItem.roundCorners ? Math.min(width,height) / 2 : 0 0217 0218 property int size: Math.min(2*Math.max(1,mainElement.width/5 ), 0219 2*Math.max(1,mainElement.height/5 )) 0220 } 0221 } 0222 0223 Item{ 0224 id:mainElement 0225 0226 width: Math.max(glowItem.size, parent.width) 0227 height: Math.max(glowItem.size, parent.height) 0228 anchors.centerIn: parent 0229 0230 Rectangle { 0231 id: smallCircle 0232 anchors.centerIn: parent 0233 anchors.fill: parent 0234 0235 color: glowItem.basicColor 0236 radius: glowItem.roundCorners ? Math.min(width,height) / 2 : 0 0237 visible: !glowItem.showAttention 0238 } 0239 0240 Loader{ 0241 anchors.centerIn: parent 0242 anchors.fill: parent 0243 0244 active: glowItem.showAttention 0245 0246 sourceComponent:Rectangle { 0247 id: smallCircleInAttention 0248 0249 color: glowItem.animationColor 0250 radius: smallCircle.radius 0251 0252 SequentialAnimation{ 0253 running: glowItem.showAttention 0254 loops: Animation.Infinite 0255 alwaysRunToEnd: true 0256 0257 PropertyAnimation { 0258 target: glowItem 0259 property: "animationColor" 0260 to: glowItem.animationColor 0261 duration: glowItem.animation 0262 easing.type: Easing.InOutQuad 0263 } 0264 0265 PropertyAnimation { 0266 target: glowItem 0267 property: "animationColor" 0268 to: glowItem.basicColor 0269 duration: glowItem.animation 0270 easing.type: Easing.InOutQuad 0271 } 0272 } 0273 } 0274 } 0275 0276 Rectangle { 0277 visible: glowItem.showGlow && glowItem.glow3D 0278 anchors.horizontalCenter: parent.horizontalCenter 0279 anchors.verticalCenter: parent.verticalCenter 0280 0281 anchors.horizontalCenterOffset: { 0282 if (isHorizontal) 0283 return 0; 0284 else if (location === PlasmaCore.Types.LeftEdge) 0285 return -glowItem.width / 7; 0286 else if (location === PlasmaCore.Types.RightEdge) 0287 return glowItem.width / 7; 0288 0289 return 0; 0290 } 0291 anchors.verticalCenterOffset: { 0292 if (isVertical) 0293 return 0; 0294 else if (location === PlasmaCore.Types.BottomEdge) 0295 return glowItem.height / 7; 0296 else if (location === PlasmaCore.Types.TopEdge) 0297 return -glowItem.height / 7; 0298 0299 return 0; 0300 } 0301 0302 width: isHorizontal ? Math.max(mainGlowPart.width, shadow) : shadow 0303 height: isHorizontal ? shadow : Math.max(mainGlowPart.height, shadow) 0304 radius: isHorizontal ? height/2 : width/2 0305 0306 property int shadow: glowItem.size / 3 0307 0308 color: glowItem.contrastColorAlpha 0309 opacity: 0.2 0310 } 0311 } 0312 }