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 panel: the logo, then each pinned panel's current value, coloured
// by its thresholds. The logo opens the last dashboard; a value opens the
// dashboard it came from.
Item {
id: strip
required property var store
readonly property bool vertical: Plasmoid.formFactor === PlasmaCore.Types.Vertical
readonly property real cell: Math.max(Kirigami.Units.iconSizes.small,
Math.min(vertical ? width : height, Kirigami.Units.iconSizes.medium))
readonly property bool showPins: store.hasValidConfig && store.pinnedList.length > 0
Layout.minimumWidth: vertical ? -1 : row.implicitWidth
Layout.preferredWidth: Layout.minimumWidth
Layout.minimumHeight: vertical ? row.implicitHeight : -1
Layout.preferredHeight: Layout.minimumHeight
GridLayout {
id: row
anchors.fill: parent
flow: strip.vertical ? GridLayout.TopToBottom : GridLayout.LeftToRight
rows: strip.vertical ? -1 : 1
columns: strip.vertical ? 1 : -1
rowSpacing: 0
columnSpacing: Kirigami.Units.smallSpacing
// ── logo ────────────────────────────────────────────────────────
Item {
Layout.preferredWidth: strip.cell
Layout.preferredHeight: strip.cell
Layout.alignment: Qt.AlignCenter
Rectangle {
anchors.fill: parent
radius: Kirigami.Units.cornerRadius
color: Kirigami.Theme.highlightColor
opacity: logoMouse.containsMouse ? 0.2 : 0
}
Kirigami.Icon {
anchors.fill: parent
anchors.margins: parent.width * 0.1
source: strip.store.logoSource
isMask: !strip.store.hasValidConfig
color: Kirigami.Theme.disabledTextColor
}
PlasmaComponents3.BusyIndicator {
anchors.right: parent.right
anchors.bottom: parent.bottom
width: parent.width * 0.45
height: width
visible: strip.store.anyLoading && !strip.store.expanded
running: visible
}
PlasmaCore.ToolTipArea {
anchors.fill: parent
mainText: i18n("Grafana")
subText: !strip.store.hasValidConfig ? i18n("Click to configure the connection")
: !strip.store.hasDashboards ? i18n("Click to choose dashboards")
: strip.store.lastError !== "" ? strip.store.lastError
: i18n("Click to open %1", (strip.store.dashboards[strip.store.shownUid] || { dashboard: { title: strip.store.shownUid } }).dashboard.title)
}
MouseArea {
id: logoMouse
anchors.fill: parent
hoverEnabled: true
onClicked: {
if (!strip.store.hasValidConfig || !strip.store.hasDashboards) Plasmoid.internalAction("configure").trigger()
else strip.store.openAll()
}
}
}
// ── pinned values ───────────────────────────────────────────────
Repeater {
model: strip.showPins ? strip.store.pinnedList : []
delegate: Item {
id: pin
required property var modelData
readonly property var value: (strip.store.dataRev, strip.store.dashRev, strip.store.pinnedValue(modelData))
readonly property bool showLabel: strip.store.pinnedLabels && !strip.vertical
Layout.preferredWidth: strip.vertical ? strip.width : content.implicitWidth + Kirigami.Units.smallSpacing * 2
Layout.preferredHeight: strip.vertical ? content.implicitHeight + Kirigami.Units.smallSpacing : strip.height
Layout.alignment: Qt.AlignCenter
Rectangle {
anchors.fill: parent
radius: Kirigami.Units.cornerRadius
color: Kirigami.Theme.highlightColor
opacity: pinMouse.containsMouse ? 0.2 : 0
}
Column {
id: content
anchors.centerIn: parent
spacing: -2
PlasmaComponents3.Label {
visible: pin.showLabel
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: Math.max(8, strip.cell * 0.32)
opacity: 0.7
text: pin.modelData.label || pin.value.title || ""
elide: Text.ElideRight
width: Math.min(implicitWidth, Kirigami.Units.gridUnit * 8)
horizontalAlignment: Text.AlignHCenter
}
PlasmaComponents3.Label {
anchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: Math.max(9, strip.cell * (pin.showLabel ? 0.45 : 0.55))
font.bold: true
color: pin.value.color && pin.value.color !== "transparent" ? pin.value.color : Kirigami.Theme.textColor
text: pin.value.text
width: strip.vertical ? Math.min(implicitWidth, strip.width) : implicitWidth
fontSizeMode: strip.vertical ? Text.HorizontalFit : Text.FixedSize
minimumPixelSize: 6
horizontalAlignment: Text.AlignHCenter
}
}
PlasmaCore.ToolTipArea {
anchors.fill: parent
mainText: pin.value.title || pin.modelData.title || ""
textFormat: Text.RichText
subText: {
var lines = []
var v = pin.value
for (var i = 0; i < v.series.length && i < 10; i++) {
var c = v.series[i].color && v.series[i].color !== "transparent" ? v.series[i].color : Kirigami.Theme.textColor
lines.push((v.series.length > 1 ? v.series[i].name + ": " : "") + "<font color=\"" + c + "\"><b>" + v.series[i].text + "</b></font>")
}
if (v.series.length > 10) lines.push(i18n("…and %1 more", v.series.length - 10))
if (v.error) lines.push("<font color=\"" + Kirigami.Theme.negativeTextColor + "\">" + v.error + "</font>")
lines.push("<small>" + (pin.modelData.dashboardTitle || pin.modelData.uid) + "</small>")
return lines.join("<br/>")
}
}
MouseArea {
id: pinMouse
anchors.fill: parent
hoverEnabled: true
onClicked: strip.store.openDashboard(pin.modelData.uid)
}
}
}
}
}
neiam
/grafana-plasmoid
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
7.3 KiB · text
History
7a88816