summaryrefslogtreecommitdiff
path: root/bar/components/SimpleResource.qml
blob: 54564c3a316aa9059d29a9558fcf51f684c6eadd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import QtQuick
import Quickshell
import QtQuick.Layouts
import qs.config
import qs.components
import QtQuick.Controls

Item {
	id: root

	// TODO: use https://quickshell.org/docs/master/types/Quickshell/PopupWindow/ for tooltip

	required property real value
	required property string suffix // unit
	required property string icon
	property string altValue: value
	property string altSuffix: suffix
	property string altIcon: icon
	property string text: root.value + root.suffix
	property string altText: root.altValue + root.altSuffix
	property real thresholdL1: 40
	property real thresholdL2: thresholdL1 * 1.5
	property real thresholdL3: thresholdL2 * 1.5
	property color thresholdColorL1: Colors.cyan
	property color thresholdColorL2: Colors.yellow
	property color thresholdColorL3: Colors.red

	property bool alt: false

	property color color: value < thresholdL1 ? Colors.accentAlt : value >= thresholdL3 ? thresholdColorL3 : value >= thresholdL2 ? thresholdColorL2 : thresholdColorL1

	implicitWidth: layout.implicitWidth
	implicitHeight: layout.implicitHeight

	RowLayout {
		id: layout

		spacing: 0

		Item {
			Layout.fillWidth: true
		}

		IRect {
			Layout.fillWidth: true
			Layout.fillHeight: true
			implicitWidth: m_icon.width + General.rectMargin * 2
			implicitHeight: Bar.height - General.rectMargin
			color: "transparent"
			Slider {
				id: pBar
				anchors.fill: parent
				handle: Item
				from: 0
				to: 100
				value: !root.alt ? root.value : root.altValue
				background: IRect {
					anchors.fill: parent
					color: "transparent"
					// radius: Style.rounding.smaller
				}
				contentItem: Item {
					IRect {
						anchors.bottom: parent.bottom
						width: parent.width
						height: parent.height * pBar.visualPosition
						color: Qt.rgba(root.color.r, root.color.g, root.color.b, General.accentTransparency * 1.5)
						radius: Style.rounding.smaller

						Behavior on height {
							NumberAnimation {
								duration: General.animationDuration / 2
							}
						}
					}
				}
			}
			Icon {
				id: m_icon
				anchors {
					centerIn: parent
				}
				iconSize: Style.font.size.small
				text: !root.alt ? root.icon : root.altIcon
				color: root.value < root.thresholdL1 ? Colors.foreground2 : root.value >= root.thresholdL3 ? root.thresholdColorL3 : root.value >= root.thresholdL2 ? root.thresholdColorL2 : root.thresholdColorL1
			}
		}

		Item {
			Layout.fillWidth: true
		}
	}
	MouseArea {
		anchors.fill: parent
		cursorShape: altValue != value ? Qt.PointingHandCursor : Qt.ArrowCursor
		onClicked: {
			root.alt = !root.alt;
		}
	}
}