/*SPDX-FileCopyrightText: 2012, 2015 Sebastian KΓΌgler <sebas@kde.org>SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuick 2.4import QtQuick.Layouts 1.4import QtQuick.Window 2.15import org.kde.plasma.core 2.0 as PlasmaCoreimport org.kde.plasma.components 2.0 as PlasmaComponentsimport org.kde.plasma.components 3.0 as PlasmaComponents3import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddonsimport org.kde.plasma.plasmoid 2.0Item {id: toolBoxContenttransform: Translate {y: plasmoid.editMode ? 0: state == "top" || state == "topcenter" ? -height: state == "bottom" || state == "bottomcenter" ? height: 0Behavior on y {NumberAnimation {duration: PlasmaCore.Units.longDurationeasing.type: Easing.InOutQuad}}}transformOrigin: Item.Centeropacity: plasmoid.editModevisible: opacity > 0Behavior on opacity {OpacityAnimator {duration: PlasmaCore.Units.longDurationeasing.type: Easing.InOutQuad}enabled: visible}Behavior on rotation {NumberAnimation {duration: PlasmaCore.Units.shortDuration;easing.type: Easing.InOutExpo;}enabled: visible}Behavior on x {NumberAnimation {duration: PlasmaCore.Units.shortDuration;easing.type: Easing.InOutExpo;}enabled: visible}Behavior on y {NumberAnimation {duration: PlasmaCore.Units.shortDuration;easing.type: Easing.InOutExpo;}enabled: visible}width: buttonRow.widthheight: buttonRow.heightstate: "topcenter"onXChanged: stateTimer.restart()onYChanged: stateTimer.restart()Timer {id: stateTimerinterval: 0onTriggered: updateState()}function updateState() {var container = main;//print(" w: " + container.width +"x"+container.height+" : "+x+"/"+y+" tbw: " + toolBoxContent.width);var x = toolBoxContent.x - main.x;var y = toolBoxContent.y - main.y;var cornerSnap = iconWidth//topif (y + height / 2 < container.height / 2) {if (Math.abs(container.width/2 - (x + width/2)) < PlasmaCore.Units.gridUnit) {toolBoxContent.state = "topcenter";} else {toolBoxContent.state = "top";}//bottom} else {if (Math.abs(container.width/2 - (x + height/2)) < PlasmaCore.Units.gridUnit) {toolBoxContent.state = "bottomcenter";} else {toolBoxContent.state = "bottom";}}if (!buttonMouse.pressed) {main.placeToolBox(toolBoxContent.state);}stateTimer.running = false;}PlasmaCore.FrameSvgItem {id: backgroundFrameanchors {fill: parentleftMargin: -backgroundFrame.margins.lefttopMargin: -backgroundFrame.margins.toprightMargin: -backgroundFrame.margins.rightbottomMargin: -backgroundFrame.margins.bottom}imagePath: "widgets/background"width: Math.round(buttonLayout.width + margins.horizontal)height: Math.round(buttonLayout.height + margins.vertical)}MouseArea {id: buttonMouseproperty QtObject container: mainproperty int pressedXproperty int pressedYproperty int snapStartXproperty bool snapX: false;property bool dragging: falseanchors.fill: parentdrag {filterChildren: truetarget: main.Plasmoid.immutable ? undefined : toolBoxContentminimumX: 0maximumX: container.width - toolBoxContent.widthminimumY: 0maximumY: container.height}hoverEnabled: trueonPressed: {pressedX = toolBoxContent.xpressedY = toolBoxContent.y}onPositionChanged: {if (pressed && (Math.abs(toolBoxContent.x - pressedX) > iconSize ||Math.abs(toolBoxContent.y - pressedY) > iconSize)) {dragging = true;}// Center snapping Xif (snapX && Math.abs(snapStartX - mouse.x) > PlasmaCore.Units.gridUnit) {toolBoxContent.anchors.horizontalCenter = undefined;snapX = false;} else if (!snapX && Math.abs(main.width/2 - (toolBoxContent.x + toolBoxContent.width/2)) < PlasmaCore.Units.gridUnit) {toolBoxContent.anchors.horizontalCenter = main.horizontalCenter;snapStartX = mouse.x;snapX = true;}}onReleased: {toolBoxContent.anchors.horizontalCenter = undefined;toolBoxContent.anchors.verticalCenter = undefined;snapX = false;main.Plasmoid.configuration.ToolBoxButtonState = toolBoxContent.state;main.Plasmoid.configuration.ToolBoxButtonX = toolBoxContent.x;main.Plasmoid.configuration.ToolBoxButtonY = toolBoxContent.y;//print("Saved coordinates for ToolBox in config: " + toolBoxContent.x + ", " +toolBoxContent.x);if (dragging) {main.placeToolBox();}dragging = false;stateTimer.stop();updateState();}onCanceled: dragging = false;Row {id: buttonRowspacing: buttonLayout.columnSpacingGrid {id: buttonLayoutrowSpacing: PlasmaCore.Units.smallSpacingcolumnSpacing: rowSpacing// Show buttons in two lines if screen space is limitedreadonly property int buttonWidth: addWidgetButton.implicitWidth+ configureButton.implicitWidth+ themeButton.implicitWidth+ displaySettingsButton.implicitWidth+ manageContainmentsButton.implicitWidth+ closeButton.implicitWidthrows: Math.ceil(buttonWidth / (Screen.width * 0.8))PlasmaComponents3.ToolButton {id: addWidgetButtonproperty QtObject qAction: plasmoid.action("add widgets")text: qAction.texticon.name: "list-add"onClicked: qAction.trigger()}PlasmaComponents3.ToolButton {id: configureButtonproperty QtObject qAction: plasmoid.action("configure")text: qAction.texticon.name: "preferences-desktop-wallpaper"onClicked: qAction.trigger()}PlasmaComponents3.ToolButton {id: themeButtontext: i18nd("plasma_toolbox_org.kde.desktoptoolbox", "Choose Global Themeβ¦")icon.name: "preferences-desktop-theme-global"onClicked: KQuickControlsAddons.KCMShell.openSystemSettings("kcm_lookandfeel")}PlasmaComponents3.ToolButton {id: displaySettingsButtontext: i18nd("plasma_toolbox_org.kde.desktoptoolbox", "Configure Display Settingsβ¦")icon.name: "preferences-desktop-display"onClicked: KQuickControlsAddons.KCMShell.openSystemSettings("kcm_kscreen")}PlasmaComponents3.ToolButton {id: manageContainmentsButtonproperty QtObject qAction: plasmoid.globalAction("manage-containments")text: qAction.textvisible: qAction.visibleicon.name: "preferences-system-windows-effect-fadedesktop"onClicked: qAction.trigger()}}PlasmaComponents3.ToolButton {id: closeButtonanchors.verticalCenter: buttonLayout.verticalCenterheight: addWidgetButton.heighticon.name: "window-close"onClicked: plasmoid.editMode = falsePlasmaComponents3.ToolTip {text: i18nd("plasma_toolbox_org.kde.desktoptoolbox", "Exit Edit Mode")}}}}}