summaryrefslogtreecommitdiff
path: root/bar/components/SimpleResource.qml
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-07-29 17:54:31 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-07-29 17:56:57 +0800
commite0b139d4afe566f57574fae15668ba297ed7334e (patch)
tree8a503433041eb3cc6b5bb3f98c1f94b217adfa77 /bar/components/SimpleResource.qml
parentdb6f779b1a8781b659838e5fcf929f5d3215cb4f (diff)
chore: reorganize component
rm: circularprogress as its unused
Diffstat (limited to 'bar/components/SimpleResource.qml')
-rw-r--r--bar/components/SimpleResource.qml63
1 files changed, 63 insertions, 0 deletions
diff --git a/bar/components/SimpleResource.qml b/bar/components/SimpleResource.qml
new file mode 100644
index 0000000..818327d
--- /dev/null
+++ b/bar/components/SimpleResource.qml
@@ -0,0 +1,63 @@
+import QtQuick
+import Quickshell
+import QtQuick.Layouts
+import qs.config
+import qs.components
+
+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 isAlt: false
+
+ implicitWidth: layout.implicitWidth
+ implicitHeight: layout.implicitHeight
+
+ RowLayout {
+ id: layout
+
+ spacing: Bar.resourceIconTextSpacing
+
+ Item {
+ Layout.fillWidth: true
+ }
+
+ Icon {
+ text: !root.isAlt ? 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
+ }
+ IText {
+ animate: true
+ renderType: Text.CurveRendering // it's not static and is rapidly updated
+ text: !root.isAlt ? root.text : root.altText
+ color: root.value < root.thresholdL1 ? Colors.foreground1 : 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
+ onPressed: {
+ root.isAlt = !root.isAlt;
+ }
+ }
+}