/*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 vertical: (Plasmoid.formFactor === PlasmaCore.Types.Vertical)readonly property bool useCustomButtonImage: (Plasmoid.configuration.useCustomButtonImage&& Plasmoid.configuration.customButtonImage.length !== 0)readonly property Component dashWindowComponent: kicker.isDash ? Qt.createComponent(Qt.resolvedUrl("./DashboardRepresentation.qml"), root) : nullreadonly property Kicker.DashboardWindow dashWindow: dashWindowComponent && dashWindowComponent.status === Component.Ready? dashWindowComponent.createObject(root, { visualParent: root }) : nullonWidthChanged: updateSizeHints()onHeightChanged: updateSizeHints()function updateSizeHints(): void {if (useCustomButtonImage) {if (vertical) {const scaledHeight = Math.floor(parent.width * (buttonIcon.implicitHeight / buttonIcon.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 * (buttonIcon.implicitWidth / buttonIcon.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: parentreadonly property double aspectRatio: root.vertical? implicitHeight / implicitWidth: implicitWidth / implicitHeightactive: mouseArea.containsMouse && !justOpenedTimer.runningsource: root.useCustomButtonImage ? Plasmoid.configuration.customButtonImage : Plasmoid.configuration.icon// A custom icon could also be rectangular. However, if a square, custom, icon is given, assume it// to be an icon and round it to the nearest icon size again to avoid scaling artifacts.roundToIconSize: !root.useCustomButtonImage || aspectRatio === 1onSourceChanged: root.updateSizeHints()}MouseArea {id: mouseAreaanchors.fill: parentproperty bool wasExpanded: false;activeFocusOnTab: truehoverEnabled: !root.dashWindow || !root.dashWindow.visibleKeys.onPressed: event => {switch (event.key) {case Qt.Key_Space:case Qt.Key_Enter:case Qt.Key_Return:case Qt.Key_Select:Plasmoid.activated();break;}}Accessible.name: Plasmoid.titleAccessible.description: toolTipSubTextAccessible.role: Accessible.ButtononPressed: mouse => {if (!kicker.isDash) {wasExpanded = kicker.expanded}}onClicked: mouse => {if (kicker.isDash) {root.dashWindow.toggle();justOpenedTimer.start();} else {kicker.expanded = !wasExpanded;}}}Connections {target: Plasmoidenabled: kicker.isDash && root.dashWindow !== nullfunction onActivated(): void {root.dashWindow.toggle();justOpenedTimer.start();}}}