Files
att_menu/components/VolumeGlyph.qml
T

115 lines
3.1 KiB
QML

import QtQuick
import QtQuick.Shapes
import qs.config
// The speaker, drawn for the same reason as the wifi fan: themes ship it
// symbolic-only, and drawing it lets the waves light up with the volume.
Item {
id: root
property color color: Theme.text
// Unlit waves stay drawn, faintly, so the glyph keeps one silhouette at
// every volume instead of changing shape as it moves.
property color dimColor: Theme.textDim
property int size: Theme.iconSize
// Lit waves, 0-2.
property int level: 2
// Struck through with a diagonal, for "muted".
property bool struck: false
implicitWidth: root.size
implicitHeight: root.size
readonly property real stroke: Math.max(1.5, root.size * 0.085)
Shape {
anchors.fill: parent
preferredRendererType: Shape.CurveRenderer
// Body and cone in one outline, starting at the top left of the body.
ShapePath {
fillColor: root.color
strokeWidth: -1
startX: root.size * 0.10
startY: root.size * 0.38
PathLine {
x: root.size * 0.28
y: root.size * 0.38
}
PathLine {
x: root.size * 0.50
y: root.size * 0.16
}
PathLine {
x: root.size * 0.50
y: root.size * 0.84
}
PathLine {
x: root.size * 0.28
y: root.size * 0.62
}
PathLine {
x: root.size * 0.10
y: root.size * 0.62
}
PathLine {
x: root.size * 0.10
y: root.size * 0.38
}
}
}
Repeater {
model: 2
Shape {
id: wave
required property int index
anchors.fill: parent
preferredRendererType: Shape.CurveRenderer
ShapePath {
strokeColor: root.level > wave.index ? root.color : root.dimColor
strokeWidth: root.stroke
fillColor: "transparent"
capStyle: ShapePath.RoundCap
// Centred on the cone's mouth, opening right: -45° to 45°.
PathAngleArc {
centerX: root.size * 0.50
centerY: root.size * 0.50
radiusX: root.size * (0.18 + wave.index * 0.14)
radiusY: root.size * (0.18 + wave.index * 0.14)
startAngle: -45
sweepAngle: 90
}
}
}
}
Shape {
anchors.fill: parent
visible: root.struck
preferredRendererType: Shape.CurveRenderer
ShapePath {
strokeColor: root.color
strokeWidth: root.stroke
fillColor: "transparent"
capStyle: ShapePath.RoundCap
startX: root.size * 0.12
startY: root.size * 0.88
PathLine {
x: root.size * 0.88
y: root.size * 0.12
}
}
}
}