5.8 KiB · text History db86591
import QtQuick
import QtQuick.Layouts
import org.kde.plasma.plasmoid
import org.kde.plasma.core as PlasmaCore
import org.kde.plasma.components as PlasmaComponents3
import org.kde.kirigami as Kirigami

// The GitGud logo followed by one circle per watched repo (or grouped
// namespace). The logo opens every run; a circle opens just its own.
// Used both as the panel representation and as a filter bar at the top
// of the popup.
Item {
    id: strip

    required property var store
    property bool inPanel: true

    readonly property bool vertical: inPanel && Plasmoid.formFactor === PlasmaCore.Types.Vertical
    // Panel thickness drives circle size; in the popup use a fixed size.
    readonly property real cell: inPanel
        ? Math.max(Kirigami.Units.iconSizes.small,
                   Math.min(vertical ? width : height, Kirigami.Units.iconSizes.medium))
        : Kirigami.Units.iconSizes.smallMedium + Kirigami.Units.smallSpacing
    readonly property int count: (store.hasValidConfig && store.hasWatched ? circles.count : 0) + 1

    Layout.minimumWidth: inPanel && !vertical ? count * cell + (count - 1) * flow.spacing : -1
    Layout.preferredWidth: Layout.minimumWidth
    Layout.minimumHeight: inPanel && vertical ? count * cell + (count - 1) * flow.spacing : flow.implicitHeight
    Layout.preferredHeight: Layout.minimumHeight
    implicitHeight: flow.implicitHeight

    Flow {
        id: flow
        anchors.fill: strip.inPanel ? parent : undefined
        width: strip.inPanel ? undefined : strip.width
        flow: strip.vertical ? Flow.TopToBottom : Flow.LeftToRight
        spacing: strip.inPanel ? 0 : Kirigami.Units.smallSpacing

        // ── logo: every run ─────────────────────────────────────────────
        Item {
            width: strip.cell
            height: strip.cell

            Rectangle {
                anchors.fill: parent
                radius: Kirigami.Units.cornerRadius
                color: Kirigami.Theme.highlightColor
                opacity: logoMouse.containsMouse ? 0.2
                         : (!strip.inPanel && strip.store.focusKey === "") ? 0.3 : 0
            }

            Kirigami.Icon {
                anchors.fill: parent
                anchors.margins: parent.width * 0.08
                source: strip.store.logoSource
                // Brand colour once connected; greyed out until then.
                isMask: !strip.store.hasValidConfig
                color: Kirigami.Theme.disabledTextColor
            }

            PlasmaCore.ToolTipArea {
                anchors.fill: parent
                mainText: i18n("GitGud CI")
                subText: !strip.store.hasValidConfig ? i18n("Click to configure the connection")
                       : !strip.store.hasWatched ? i18n("Click to choose repositories")
                       : strip.store.lastError !== "" ? strip.store.lastError
                       : strip.store.anyActive ? i18n("Runs in progress — click to see all runs")
                       : i18n("Click to see all runs")
            }

            MouseArea {
                id: logoMouse
                anchors.fill: parent
                hoverEnabled: true
                onClicked: {
                    if (!strip.store.hasValidConfig || !strip.store.hasWatched) {
                        Plasmoid.internalAction("configure").trigger()
                    } else if (strip.inPanel) {
                        strip.store.openAll()
                    } else {
                        strip.store.focusKey = ""
                    }
                }
            }
        }

        // ── one circle per watched repo / grouped namespace ─────────────
        Repeater {
            id: circles
            model: strip.store.hasValidConfig && strip.store.hasWatched ? strip.store.circlesModelRef : null

            delegate: Item {
                id: circleItem

                required property string key
                required property string label
                required property string status
                required property string tooltip

                readonly property bool selected: strip.store.focusKey === key && (!strip.inPanel || strip.store.expanded)

                width: strip.cell
                height: strip.cell

                StatusCircle {
                    anchors.fill: parent
                    anchors.margins: strip.inPanel ? strip.cell * 0.15 : 0
                    status: circleItem.status
                    highlighted: mouse.containsMouse || circleItem.selected
                }

                // Grouped namespaces get a small outer ring so they read
                // as "several repos" rather than one.
                Rectangle {
                    visible: circleItem.key.indexOf("ns:") === 0
                    anchors.fill: parent
                    anchors.margins: strip.inPanel ? strip.cell * 0.05 : -2
                    radius: width / 2
                    color: "transparent"
                    border.color: Kirigami.Theme.textColor
                    border.width: 1
                    opacity: 0.4
                }

                PlasmaCore.ToolTipArea {
                    anchors.fill: parent
                    mainText: circleItem.label
                    subText: circleItem.tooltip
                    textFormat: Text.RichText
                }

                MouseArea {
                    id: mouse
                    anchors.fill: parent
                    hoverEnabled: true
                    onClicked: {
                        if (strip.inPanel) strip.store.openCircle(circleItem.key)
                        else strip.store.focusKey = strip.store.focusKey === circleItem.key ? "" : circleItem.key
                    }
                }
            }
        }
    }
}