|
| 1 | +import QtQuick |
| 2 | +import QtQuick.Layouts |
| 3 | +import Quickshell |
| 4 | +import qs.Commons |
| 5 | +import qs.Services.UI |
| 6 | +import qs.Widgets |
| 7 | + |
| 8 | +Item { |
| 9 | + id: root |
| 10 | + |
| 11 | + property var pluginApi: null |
| 12 | + property ShellScreen screen |
| 13 | + property string widgetId: "" |
| 14 | + property string section: "" |
| 15 | + property int sectionWidgetIndex: -1 |
| 16 | + property int sectionWidgetsCount: 0 |
| 17 | + |
| 18 | + property var cfg: pluginApi?.pluginSettings || ({}) |
| 19 | + property var defaults: pluginApi?.manifest?.metadata?.defaultSettings || ({}) |
| 20 | + |
| 21 | + readonly property string iconColorKey: cfg.iconColor ?? defaults.iconColor |
| 22 | + readonly property bool showErrorBadge: cfg.showErrorBadge ?? defaults.showErrorBadge ?? true |
| 23 | + readonly property var main: pluginApi?.mainInstance ?? null |
| 24 | + |
| 25 | + readonly property string barPosition: Settings.getBarPositionForScreen(screen?.name) |
| 26 | + readonly property bool isVertical: barPosition === "left" || barPosition === "right" |
| 27 | + readonly property real capsuleHeight: Style.getCapsuleHeightForScreen(screen?.name) |
| 28 | + |
| 29 | + implicitWidth: isVertical ? capsuleHeight : contentRow.implicitWidth + Style.marginM * 2 |
| 30 | + implicitHeight: isVertical ? contentRow.implicitHeight + Style.marginM * 2 : capsuleHeight |
| 31 | + |
| 32 | + NPopupContextMenu { |
| 33 | + id: contextMenu |
| 34 | + model: [ |
| 35 | + { "label": pluginApi?.tr("menu.settings"), "action": "settings", "icon": "settings" } |
| 36 | + ] |
| 37 | + onTriggered: function(action) { |
| 38 | + contextMenu.close(); |
| 39 | + PanelService.closeContextMenu(screen); |
| 40 | + if (action === "settings") { |
| 41 | + BarService.openPluginSettings(root.screen, pluginApi.manifest); |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + MouseArea { |
| 47 | + anchors.fill: parent |
| 48 | + hoverEnabled: true |
| 49 | + cursorShape: Qt.PointingHandCursor |
| 50 | + acceptedButtons: Qt.LeftButton | Qt.RightButton |
| 51 | + onClicked: mouse => { |
| 52 | + if (mouse.button === Qt.RightButton) { |
| 53 | + PanelService.showContextMenu(contextMenu, root, screen); |
| 54 | + } else { |
| 55 | + if (pluginApi) pluginApi.openPanel(root.screen, root); |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + RowLayout { |
| 61 | + id: contentRow |
| 62 | + anchors.centerIn: parent |
| 63 | + spacing: Style.marginS |
| 64 | + |
| 65 | + NIcon { |
| 66 | + icon: "topology-star-3" |
| 67 | + pointSize: Style.fontSizeL |
| 68 | + color: { |
| 69 | + if (root.showErrorBadge && root.main?.hasCriticalPod) return Color.mError; |
| 70 | + return Color.resolveColorKey(root.iconColorKey); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + NText { |
| 75 | + visible: !root.isVertical && root.main?.activeContext !== undefined && root.main?.activeContext !== "" |
| 76 | + text: { |
| 77 | + var ctx = root.main?.activeContext ?? ""; |
| 78 | + var ns = root.main?.activeNamespace ?? ""; |
| 79 | + if (ctx === "") return ""; |
| 80 | + if (ns === "") return ctx; |
| 81 | + return ctx + " / " + ns; |
| 82 | + } |
| 83 | + pointSize: Style.fontSizeS |
| 84 | + color: Color.mOnSurface |
| 85 | + elide: Text.ElideRight |
| 86 | + Layout.maximumWidth: capsuleHeight * 3 |
| 87 | + } |
| 88 | + |
| 89 | + // Error badge dot |
| 90 | + Rectangle { |
| 91 | + visible: root.showErrorBadge && (root.main?.hasCriticalPod ?? false) |
| 92 | + width: Math.round(Style.fontSizeS * 0.6) |
| 93 | + height: width |
| 94 | + radius: width / 2 |
| 95 | + color: Color.mError |
| 96 | + Layout.alignment: Qt.AlignVCenter |
| 97 | + } |
| 98 | + } |
| 99 | +} |
0 commit comments