// SPDX-License-Identifier: MIT import QtQuick import QtQuick.Layouts import org.kde.plasma.core as PlasmaCore import org.kde.plasma.plasmoid import org.kde.kirigami as Kirigami import se.ajpanton.panelactions 1.0 PlasmoidItem { id: root readonly property bool vertical: Plasmoid.formFactor === PlasmaCore.Types.Vertical readonly property bool editing: Plasmoid.containment.corona?.editMode ?? false readonly property int minimumLength: Math.max(editing ? 48 : 1, settings.values.spacerLength) readonly property Item panelLayout: { let item = root.parent; while (item) { if (item instanceof GridLayout) return item; item = item.parent; } return null; } // Give other widgets their preferred space first; share the remainder // with any other flexible spacers, instead of competing with task buttons. readonly property real availableLength: { if (!panelLayout) return minimumLength; let used = 0; let spacers = 0; let count = 0; for (const child of panelLayout.children) { if (!child.visible) continue; ++count; const plugin = child.applet?.plasmoid?.pluginName; if (plugin === "se.ajpanton.panelactions" || (plugin === "org.kde.plasma.panelspacer" && child.applet.plasmoid.configuration.expanding)) { ++spacers; } else { const minimum = vertical ? child.Layout.minimumHeight : child.Layout.minimumWidth; const preferred = vertical ? child.Layout.preferredHeight : child.Layout.preferredWidth; const maximum = vertical ? child.Layout.maximumHeight : child.Layout.maximumWidth; used += Math.min(maximum, Math.max(minimum, preferred)); } } used += Math.max(0, count - 1) * (vertical ? panelLayout.rowSpacing : panelLayout.columnSpacing); return Math.max(minimumLength, ((vertical ? panelLayout.height : panelLayout.width) - used) / Math.max(1, spacers)); } Plasmoid.backgroundHints: PlasmaCore.Types.NoBackground Layout.minimumWidth: vertical ? 1 : minimumLength Layout.minimumHeight: vertical ? minimumLength : 1 Layout.preferredWidth: vertical ? 0 : availableLength Layout.preferredHeight: vertical ? availableLength : 0 Layout.fillWidth: !vertical Layout.fillHeight: vertical preferredRepresentation: fullRepresentation PanelSettings { id: settings } // Direct content, like Plasma's own spacer: never a compact icon or popup. Rectangle { anchors.fill: parent visible: root.editing color: Kirigami.Theme.highlightColor opacity: 0.4 radius: 4 } PlasmaCore.Action { id: configureAction text: i18n("Configure Panel Actions…") icon.name: "configure" onTriggered: settings.open() } Component.onCompleted: Plasmoid.setInternalAction("configure", configureAction) }