mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-06 05:25:41 -05:00
also use shader for DankCircularImage
This commit is contained in:
@@ -1,94 +1,92 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Effects
|
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import qs.Common
|
import qs.Common
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
||||||
Rectangle {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property string imageSource: ""
|
property string imageSource: ""
|
||||||
property string fallbackIcon: "notifications"
|
property string fallbackIcon: "notifications"
|
||||||
property string fallbackText: ""
|
property string fallbackText: ""
|
||||||
property bool hasImage: imageSource !== ""
|
property bool hasImage: imageSource !== ""
|
||||||
property alias imageStatus: internalImage.status
|
property alias imageStatus: sourceImage.status
|
||||||
|
property color borderColor: "transparent"
|
||||||
|
property real borderWidth: 0
|
||||||
|
property real imageOpacity: 1.0
|
||||||
|
|
||||||
radius: width / 2
|
width: 64
|
||||||
color: Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.1)
|
height: 64
|
||||||
border.color: "transparent"
|
|
||||||
border.width: 0
|
|
||||||
|
|
||||||
Image {
|
Rectangle {
|
||||||
id: internalImage
|
id: background
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 2
|
color: Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.1)
|
||||||
asynchronous: true
|
radius: width * 0.5
|
||||||
fillMode: Image.PreserveAspectCrop
|
|
||||||
smooth: true
|
|
||||||
mipmap: true
|
|
||||||
cache: true
|
|
||||||
visible: false
|
|
||||||
source: root.imageSource
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
Image {
|
||||||
sourceSize.width = 128
|
id: sourceImage
|
||||||
sourceSize.height = 128
|
anchors.fill: parent
|
||||||
|
anchors.margins: 2
|
||||||
|
source: root.imageSource
|
||||||
|
visible: false
|
||||||
|
fillMode: Image.PreserveAspectCrop
|
||||||
|
smooth: true
|
||||||
|
mipmap: true
|
||||||
|
asynchronous: true
|
||||||
|
antialiasing: true
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
sourceSize.width = 128
|
||||||
|
sourceSize.height = 128
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
MultiEffect {
|
ShaderEffect {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 2
|
anchors.margins: 2
|
||||||
source: internalImage
|
visible: sourceImage.status === Image.Ready && root.imageSource !== ""
|
||||||
maskEnabled: true
|
|
||||||
maskSource: circularMask
|
|
||||||
visible: internalImage.status === Image.Ready && root.imageSource !== ""
|
|
||||||
maskThresholdMin: 0.5
|
|
||||||
maskSpreadAtMin: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
Item {
|
property var source: ShaderEffectSource {
|
||||||
id: circularMask
|
sourceItem: sourceImage
|
||||||
width: parent.width - 4
|
hideSource: true
|
||||||
height: parent.height - 4
|
live: true
|
||||||
anchors.centerIn: parent
|
recursive: false
|
||||||
layer.enabled: true
|
format: ShaderEffectSource.RGBA
|
||||||
layer.smooth: true
|
}
|
||||||
visible: false
|
|
||||||
|
property real imageOpacity: root.imageOpacity
|
||||||
|
|
||||||
|
fragmentShader: Qt.resolvedUrl("../Shaders/qsb/circled_image.frag.qsb")
|
||||||
|
supportsAtlasTextures: false
|
||||||
|
blending: true
|
||||||
|
}
|
||||||
|
|
||||||
|
DankIcon {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
name: root.fallbackIcon
|
||||||
|
size: parent.width * 0.5
|
||||||
|
color: Theme.surfaceVariantText
|
||||||
|
visible: sourceImage.status !== Image.Ready && root.imageSource === "" && root.fallbackIcon !== ""
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
visible: root.imageSource === "" && root.fallbackIcon === "" && root.fallbackText !== ""
|
||||||
|
text: root.fallbackText
|
||||||
|
font.pixelSize: Math.max(12, parent.width * 0.36)
|
||||||
|
font.weight: Font.Bold
|
||||||
|
color: Theme.primaryText
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
radius: width / 2
|
radius: width / 2
|
||||||
color: "black"
|
color: "transparent"
|
||||||
|
border.color: root.borderColor !== "transparent" ? root.borderColor : Theme.popupBackground()
|
||||||
|
border.width: root.hasImage && sourceImage.status === Image.Ready ? (root.borderWidth > 0 ? root.borderWidth : 3) : 0
|
||||||
antialiasing: true
|
antialiasing: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DankIcon {
|
|
||||||
anchors.centerIn: parent
|
|
||||||
name: root.fallbackIcon
|
|
||||||
size: parent.width * 0.5
|
|
||||||
color: Theme.surfaceVariantText
|
|
||||||
visible: internalImage.status !== Image.Ready && root.imageSource === "" && root.fallbackIcon !== ""
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: 0
|
|
||||||
radius: width / 2
|
|
||||||
color: "transparent"
|
|
||||||
border.color: Theme.popupBackground()
|
|
||||||
border.width: 3
|
|
||||||
visible: root.hasImage && internalImage.status === Image.Ready
|
|
||||||
antialiasing: true
|
|
||||||
}
|
|
||||||
|
|
||||||
StyledText {
|
|
||||||
anchors.centerIn: parent
|
|
||||||
visible: root.imageSource === "" && root.fallbackIcon === "" && root.fallbackText !== ""
|
|
||||||
text: root.fallbackText
|
|
||||||
font.pixelSize: Math.max(12, parent.width * 0.36)
|
|
||||||
font.weight: Font.Bold
|
|
||||||
color: Theme.primaryText
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user