110 lines
3.6 KiB
QML
110 lines
3.6 KiB
QML
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
|
|
// Amber tint, a yellow rim and, with a shadow, a yellow glow.
|
|
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
|
|
|
|
Behavior on color {
|
|
ColorAnimation {
|
|
duration: root.theme.glassFadeDuration
|
|
}
|
|
}
|
|
|
|
// A GPU shadow instead of a hand-drawn one, so it stays cheap even
|
|
// with many glass panels on screen and animating at once. Selected
|
|
// glass turns it into a yellow glow all round.
|
|
layer.enabled: root.shadow
|
|
layer.effect: MultiEffect {
|
|
shadowEnabled: true
|
|
shadowColor: root.selected ? root.theme.glassGlow : root.theme.glassShadow
|
|
shadowVerticalOffset: root.selected ? 0 : root.theme.glassShadowOffset
|
|
// blurMax stays fixed, so the effect is not rebuilt on select.
|
|
shadowBlur: root.selected ? 1.0 : root.theme.glassShadowBlur / root.theme.glassGlowBlur
|
|
blurMax: root.theme.glassGlowBlur
|
|
}
|
|
}
|
|
|
|
// 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
|
|
|
|
property color rimTop: root.selected ? root.theme.accentColor : root.theme.glassRimTop
|
|
property color rimBottom: root.selected ? root.theme.glassSelectedRimBottom : root.theme.glassRimBottom
|
|
readonly property real rimWidth: root.selected ? 2 : 1
|
|
|
|
anchors.fill: parent
|
|
|
|
Behavior on rimTop {
|
|
ColorAnimation {
|
|
duration: root.theme.glassFadeDuration
|
|
}
|
|
}
|
|
Behavior on rimBottom {
|
|
ColorAnimation {
|
|
duration: root.theme.glassFadeDuration
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|