Krolyxon
Commit ed4e5ea

Branches

Refs →

aurora.configquickshellauroraSegmented.qml

76 lines · 2.6 KB · QML

1import QtQuick
2
3// One-of-n choice: a pill track where the white cell slides to the selected option.
4// options: [{value, label, ticks}] (ticks = optional strength marks, how many of 4 are lit, like glyph's power modes).
5// Ported from glyph-rice (github.com/Nebelung-cloud/glyph-rice, GPL-3.0), quick/Quick.qml (power modes).
6Rectangle {
7 id: root
8
9 property var options: []
10 property var value
11 signal picked(var v)
12
13 readonly property int at: {
14 for (var i = 0; i < options.length; i++) if (options[i].value === value) return i
15 return -1
16 }
17 readonly property real cell: (width - 12) / Math.max(1, options.length)
18
19 implicitHeight: 54
20 radius: height / 2
21 color: Theme.s2
22
23 Rectangle {
24 visible: root.at >= 0
25 x: 6 + root.cell * Math.max(0, root.at)
26 y: 6
27 width: root.cell
28 height: root.height - 12
29 radius: height / 2
30 color: Theme.fill
31 Behavior on x {
32 enabled: Theme.motion
33 NumberAnimation { duration: Theme.t; easing.type: Easing.BezierSpline; easing.bezierCurve: Theme.glide }
34 }
35 }
36 Repeater {
37 model: root.options
38 Item {
39 id: c
40 required property var modelData
41 required property int index
42 readonly property bool on: root.at === index
43 x: 6 + root.cell * index
44 width: root.cell
45 height: root.height
46 Row {
47 anchors.centerIn: parent
48 spacing: 9
49 Row {
50 visible: c.modelData.ticks !== undefined
51 anchors.verticalCenter: parent.verticalCenter
52 spacing: 3
53 Repeater {
54 model: 4
55 Rectangle {
56 required property int index
57 anchors.bottom: parent.bottom
58 width: 4
59 height: 6 + index * 4
60 radius: 2
61 color: index < (c.modelData.ticks || 0) ? (c.on ? Theme.fillFg : Theme.fg) : (c.on ? Theme.fade(Theme.fillFg, 0.3) : Theme.s3)
62 }
63 }
64 }
65 Lb {
66 anchors.verticalCenter: parent.verticalCenter
67 text: c.modelData.label
68 px: 11
69 color: c.on ? Theme.fillFg : hov.hovered ? Theme.fg : Theme.grey
70 }
71 }
72 HoverHandler { id: hov; cursorShape: Qt.PointingHandCursor }
73 TapHandler { onTapped: root.picked(c.modelData.value) }
74 }
75 }
76}