3.6 KiB · text History e43831b
import QtQuick
import QtQuick.Layouts
import org.kde.plasma.components as PlasmaComponents3
import org.kde.kirigami as Kirigami

import "Lambent.js" as L

// A running machine: its live preview, speed and brightness, and the same
// slower / faster / dimmer / brighter / persist / quit controls the web UI
// has. Reads live state from the store by name, so the row survives the
// 400ms publishes underneath it.
ColumnLayout {
    id: item

    required property var store
    required property string key

    readonly property var machine: (store.rev, store.machines[key] || null)
    readonly property var pixels: (store.rev, store.previews[key] || [])

    spacing: Kirigami.Units.smallSpacing / 2

    RowLayout {
        Layout.fillWidth: true
        spacing: Kirigami.Units.smallSpacing

        ColumnLayout {
            Layout.fillWidth: true
            spacing: 0

            PlasmaComponents3.Label {
                Layout.fillWidth: true
                elide: Text.ElideRight
                text: item.key
            }

            PlasmaComponents3.Label {
                Layout.fillWidth: true
                elide: Text.ElideRight
                font: Kirigami.Theme.smallFont
                opacity: 0.7
                text: !item.machine ? "" : [
                    item.machine.step || "",
                    L.speedLabel(item.machine.speed),
                    item.machine.bgt !== item.machine.bgtt
                        ? L.percent(item.machine.bgt) + "% → " + L.percent(item.machine.bgtt) + "%"
                        : L.percent(item.machine.bgt) + "%"
                ].filter(function(s) { return s !== "" }).join(" · ")
            }
        }

        PlasmaComponents3.ToolButton {
            icon.name: "media-seek-backward"
            onClicked: item.store.machineCommand("slower", item.key)
            PlasmaComponents3.ToolTip { text: i18n("Slower") }
        }
        PlasmaComponents3.ToolButton {
            icon.name: "media-seek-forward"
            onClicked: item.store.machineCommand("faster", item.key)
            PlasmaComponents3.ToolTip { text: i18n("Faster") }
        }
        PlasmaComponents3.ToolButton {
            icon.name: "brightness-low"
            onClicked: item.store.machineCommand("dimmer", item.key)
            PlasmaComponents3.ToolTip { text: i18n("Dimmer") }
        }
        PlasmaComponents3.ToolButton {
            icon.name: "brightness-high"
            onClicked: item.store.machineCommand("brighter", item.key)
            PlasmaComponents3.ToolTip { text: i18n("Brighter") }
        }
        PlasmaComponents3.ToolButton {
            icon.name: item.machine && item.machine.persist ? "window-pin" : "window-unpin"
            checkable: false
            checked: !!item.machine && !!item.machine.persist
            onClicked: item.store.machineCommand("persist", item.key)
            PlasmaComponents3.ToolTip {
                text: item.machine && item.machine.persist ? i18n("Kept across restarts — click to stop keeping it")
                                                           : i18n("Keep across restarts")
            }
        }
        PlasmaComponents3.ToolButton {
            icon.name: "process-stop"
            onClicked: item.store.machineCommand("quit", item.key)
            PlasmaComponents3.ToolTip { text: i18n("Stop this machine") }
        }
    }

    PreviewStrip {
        visible: item.pixels.length > 0
        Layout.fillWidth: true
        Layout.preferredHeight: cellHeight
        pixels: item.pixels
    }

    Kirigami.Separator {
        Layout.fillWidth: true
        Layout.topMargin: Kirigami.Units.smallSpacing / 2
        opacity: 0.5
    }
}