aboutsummaryrefslogtreecommitdiffstats
path: root/theme/components/PowerBar.qml
blob: 58b65bff2a6c4961438d6f0a0f17a857ca22cd67 (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
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// Shutdown, restart, sleep and hibernate. Each icon is the path udt-accent
// resolved from the selected icon theme, falling back to the bundled line art
// when the key is empty or the file fails to load. Each button is disabled when
// SDDM reports the action is unavailable.

import QtQuick
import QtQuick.Controls.Basic
import QtQuick.Effects

Row {
    id: bar
    spacing: 12

    readonly property var actions: [
        { icon: config.stringValue("powerIcon"), fallback: "../icons/power.svg",
          label: "Shut down", enabled: sddm.canPowerOff, run: function() { sddm.powerOff() } },
        { icon: config.stringValue("rebootIcon"), fallback: "../icons/reboot.svg",
          label: "Restart", enabled: sddm.canReboot, run: function() { sddm.reboot() } },
        { icon: config.stringValue("suspendIcon"), fallback: "../icons/suspend.svg",
          label: "Sleep", enabled: sddm.canSuspend, run: function() { sddm.suspend() } },
        { icon: config.stringValue("hibernateIcon"), fallback: "../icons/hibernate.svg",
          label: "Hibernate", enabled: sddm.canHibernate, run: function() { sddm.hibernate() } }
    ]

    Repeater {
        model: bar.actions
        delegate: Item {
            width: 56
            height: 56
            opacity: modelData.enabled ? 1 : 0.35

            // A resolved icon-theme path is drawn exactly as the theme ships
            // it. Only the bundled line art is tinted to the palette.
            readonly property bool themed:
                modelData.icon !== "" && String(icon.source) === modelData.icon

            Rectangle {
                anchors.fill: parent
                radius: 10
                color: config.stringValue("accent")
                opacity: mouse.containsMouse && modelData.enabled ? 0.3 : 0
                Behavior on opacity { NumberAnimation { duration: 120; easing.type: Easing.OutCubic } }
            }

            Item {
                id: iconBox
                anchors.centerIn: parent
                width: 34
                height: 34
                scale: mouse.containsMouse && modelData.enabled ? 1.25 : 1.0
                Behavior on scale { NumberAnimation { duration: 120; easing.type: Easing.OutCubic } }

                Image {
                    id: icon
                    anchors.fill: parent
                    sourceSize.width: width
                    sourceSize.height: height
                    source: modelData.icon !== "" ? modelData.icon : modelData.fallback
                    visible: false
                    onStatusChanged: {
                        if (status === Image.Error && String(source) !== modelData.fallback)
                            source = modelData.fallback
                    }
                }

                MultiEffect {
                    anchors.fill: parent
                    source: icon
                    colorization: themed ? 0.0 : 1.0
                    colorizationColor: mouse.containsMouse && modelData.enabled
                        ? config.stringValue("accent")
                        : config.stringValue("subtext0")
                }
            }

            MouseArea {
                id: mouse
                anchors.fill: parent
                hoverEnabled: true
                enabled: modelData.enabled
                onClicked: modelData.run()
            }

            ToolTip.visible: mouse.containsMouse && modelData.enabled
            ToolTip.text: modelData.label
            ToolTip.delay: 400
        }
    }
}