pragma ComponentBehavior: Bound import QtQuick import QtQuick.Layouts import ".." import "../../core" import "../../services" import "../../theme" // A plugin's Control Center widget (Noctalia `controlCenterWidget` entry point) // in a grid tile. The plugin draws and handles its own button; the tile scales // it to fit and, when wide enough, adds the plugin's name and tooltip text. CCModule { id: root readonly property string pluginId: moduleId.startsWith("plugin:") ? moduleId.slice("plugin:".length) : "" readonly property string source: pluginId ? PluginService.entryUrl(pluginId, "control-center-widget") : "" readonly property Item widget: loader.item as Item // Plugin items are untyped. readonly property var widgetObject: loader.item readonly property string hint: widgetObject && typeof widgetObject.tooltipText === "string" ? widgetObject.tooltipText : "" // Room for the widget: the circle at 1×1, else the first cell. readonly property real room: compact ? background.width * 0.6 : Math.min(baseHeight, width) - 24 objectName: "pluginTile-" + pluginId round: true hovered: area.containsMouse onSourceChanged: load() Component.onCompleted: load() function load() { if (!source) { loader.source = ""; return; } // Noctalia widgets get their pluginApi at creation, as in Noctalia. loader.setSource(source, { pluginApi: PluginService.noctaliaApi(pluginId), screen: ShellState.activeScreen() }); } MouseArea { id: area anchors.fill: parent hoverEnabled: true acceptedButtons: Qt.NoButton } Item { id: holder readonly property real size: Math.min(root.room, 56) x: root.wide && !root.tall ? (root.baseHeight - size) / 2 : root.wide ? 14 : (root.width - size) / 2 y: root.wide && root.tall ? 14 : !root.wide && root.tall ? 12 : (root.baseHeight - size) / 2 width: size height: size Loader { id: loader anchors.centerIn: parent scale: root.widget && root.widget.implicitWidth > 0 ? Math.min(2.2, holder.size / Math.max(root.widget.implicitWidth, root.widget.implicitHeight)) : 1 } } ColumnLayout { visible: !root.compact x: root.wide ? (root.tall ? 14 : holder.x + holder.width + 10) : 8 y: root.wide ? (root.tall ? root.baseHeight - height - 14 : (root.baseHeight - height) / 2) : holder.y + holder.height + 8 width: root.width - x - (root.wide ? 14 : 8) spacing: 1 Text { text: root.pluginId ? PluginService.title(root.pluginId) : "" color: Theme.text font.pixelSize: 12 font.weight: Font.DemiBold elide: Text.ElideRight horizontalAlignment: root.wide ? Text.AlignLeft : Text.AlignHCenter Layout.fillWidth: true } Text { visible: text !== "" text: root.hint color: Theme.textSecondary font.pixelSize: 11 elide: Text.ElideRight wrapMode: root.tall ? Text.Wrap : Text.NoWrap maximumLineCount: Math.max(1, root.rows - 1) horizontalAlignment: root.wide ? Text.AlignLeft : Text.AlignHCenter Layout.fillWidth: true } } Text { visible: !root.source anchors.centerIn: parent text: "Plugin unavailable" color: Theme.textSecondary font.pixelSize: 10 } }