import QtQuick import QtQuick.Effects // A see-through glass panel: a light tint, a soft shine over the top half, // a rim that catches the light along the top and a shadow underneath. // It only draws the glass; put the content on top of it. Item { id: root required property Theme theme required property real radius required property color tint // Blue tint and a glowing blue rim. required property bool selected // Soft shadow underneath. Off where the window is too small to hold it. required property bool shadow Rectangle { anchors.fill: parent radius: root.radius color: root.selected ? root.theme.glassSelectedTint : root.tint antialiasing: true // A GPU shadow instead of a hand-drawn one, so it stays cheap even // with many glass panels on screen and animating at once. layer.enabled: root.shadow layer.effect: MultiEffect { shadowEnabled: true shadowColor: root.theme.glassShadow shadowVerticalOffset: root.theme.glassShadowOffset shadowBlur: 1.0 blurMax: root.theme.glassShadowBlur } } // Shine over the top half, like light on curved glass. Rectangle { anchors.fill: parent radius: root.radius antialiasing: true gradient: Gradient { GradientStop { position: 0 color: root.theme.glassShine } GradientStop { position: 0.55 color: Qt.rgba(1, 1, 1, 0) } } } // The rim, bright at the top and fading down. No blur here, so this // stays a small, cheap stroke. Canvas { id: edge readonly property color rimTop: root.selected ? root.theme.fieldBorder : root.theme.glassRimTop readonly property color rimBottom: root.selected ? root.theme.glassSelectedRimBottom : root.theme.glassRimBottom readonly property real rimWidth: root.selected ? 2 : 1 anchors.fill: parent onWidthChanged: edge.requestPaint() onHeightChanged: edge.requestPaint() onRimTopChanged: edge.requestPaint() onRimBottomChanged: edge.requestPaint() onRimWidthChanged: edge.requestPaint() onPaint: { const ctx = edge.getContext("2d"); ctx.reset(); const w = edge.width; const h = edge.height; const r = Math.min(root.radius, w / 2, h / 2); if (w <= 0 || h <= 0) return; const half = edge.rimWidth / 2; const rim = ctx.createLinearGradient(0, 0, 0, h); rim.addColorStop(0, edge.rimTop); rim.addColorStop(1, edge.rimBottom); ctx.strokeStyle = rim; ctx.lineWidth = edge.rimWidth; ctx.beginPath(); ctx.roundedRect(half, half, w - edge.rimWidth, h - edge.rimWidth, r - half, r - half); ctx.stroke(); } } }