/*SPDX-FileCopyrightText: 2013-2014 Eike Hein <hein@kde.org>SPDX-License-Identifier: GPL-2.0-or-later*/pragma ComponentBehavior: Boundimport QtQuickimport QtQuick.Layoutsimport org.kde.kirigami as Kirigamiimport org.kde.plasma.core as PlasmaCoreimport org.kde.plasma.plasmoidimport org.kde.plasma.private.kicker as KickerItem {id: rootreadonly property bool isDash: Plasmoid.pluginName === "org.kde.plasma.kickerdash"readonly property bool vertical: (Plasmoid.formFactor === PlasmaCore.Types.Vertical)readonly property bool useCustomButtonImage: (Plasmoid.configuration.useCustomButtonImage&& Plasmoid.configuration.customButtonImage.length !== 0)property string toolTipSubText: ""property Component dashWindowComponentreadonly property Kicker.DashboardWindow dashWindow: isDash && dashWindowComponent && dashWindowComponent.status === Component.Ready? dashWindowComponent.createObject(root, { visualParent: root }) as Kicker.DashboardWindow : nullonWidthChanged: updateSizeHints()onHeightChanged: updateSizeHints()function updateSizeHints(): void {if (useCustomButtonImage && imageFallback.visible) {if (vertical) {const scaledHeight = Math.floor(parent?.width * (imageFallback.implicitHeight / imageFallback.implicitWidth));root.Layout.minimumWidth = -1;root.Layout.minimumHeight = scaledHeight;root.Layout.maximumWidth = Kirigami.Units.iconSizes.huge;root.Layout.maximumHeight = scaledHeight;} else {const scaledWidth = Math.floor(parent?.height * (imageFallback.implicitWidth / imageFallback.implicitHeight));root.Layout.minimumWidth = scaledWidth;root.Layout.minimumHeight = -1;root.Layout.maximumWidth = scaledWidth;root.Layout.maximumHeight = Kirigami.Units.iconSizes.huge;}} else {root.Layout.minimumWidth = -1;root.Layout.minimumHeight = -1;root.Layout.maximumWidth = Kirigami.Units.iconSizes.huge;root.Layout.maximumHeight = Kirigami.Units.iconSizes.huge;}}Kirigami.Icon {id: buttonIconanchors.fill: parentactive: mouseArea.containsMousesource: root.useCustomButtonImage ? Plasmoid.configuration.customButtonImage : Plasmoid.configuration.iconvisible: !imageFallback.visible// A custom icon could also be rectangular, but Kirigami.Icon only supports square ones.// If a square, custom, icon is given, we load it using Kirigami.Icon and round it to// the nearest icon size again to avoid scaling artifacts.roundToIconSize: trueonSourceChanged: root.updateSizeHints()onVisibleChanged: root.updateSizeHints()}Image {id: imageFallbackreadonly property double aspectRatio: root.vertical? implicitHeight / implicitWidth: implicitWidth / implicitHeightanchors.fill: parentvisible: root.useCustomButtonImage && status == Image.Ready && aspectRatio !== 1 && source !== ""mipmap: truesource: Plasmoid.icon.startsWith("/") ? "file:" + Plasmoid.icon.split("/").map(encodeURIComponent).join("/") : ""onSourceChanged: root.updateSizeHints()onVisibleChanged: root.updateSizeHints()fillMode: Image.PreserveAspectFit}MouseArea {id: mouseAreaanchors.fill: parentproperty bool wasExpanded: false;activeFocusOnTab: truehoverEnabled: !root.dashWindow || !root.dashWindow.visibleKeys.onReturnPressed: Plasmoid.activated()Keys.onEnterPressed: Plasmoid.activated()Keys.onSpacePressed: Plasmoid.activated()Keys.onSelectPressed: Plasmoid.activated()Accessible.name: Plasmoid.titleAccessible.description: root.toolTipSubTextAccessible.role: Accessible.ButtononPressed: mouse => {if (!root.isDash) {wasExpanded = kicker.expanded}}onClicked: mouse => {if (root.isDash) {root.dashWindow.toggle();} else {kicker.expanded = !wasExpanded;}}}Connections {target: Plasmoidenabled: root.isDash && root.dashWindow !== nullfunction onActivated(): void {root.dashWindow.toggle();}}}