/*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.ksvg 1.0 as KSvgimport org.kde.plasma.components 3.0 as PlasmaComponents3import org.kde.plasma.plasmoid 2.0import org.kde.kirigami 2.20 as Kirigamiimport org.kde.kcmutils as KCMItem {id: toolBoxContentproperty alias enterAnimation: enterAnimationproperty alias exitAnimation: exitAnimationvisible: falseopacity: 0transform: Translate {id: translator}transformOrigin: Item.CenterBehavior on rotation {NumberAnimation {duration: Kirigami.Units.shortDuration;easing.type: Easing.InOutExpo;}enabled: visible}Behavior on x {NumberAnimation {duration: Kirigami.Units.shortDuration;easing.type: Easing.InOutExpo;}enabled: visible}Behavior on y {NumberAnimation {duration: Kirigami.Units.shortDuration;easing.type: Easing.InOutExpo;}enabled: visible}width: buttonRow.widthheight: buttonRow.height + (touchMode ? backgroundFrame.margins.top + backgroundFrame.margins.bottom : 0)state: "topcenter"property QtObject container: mainproperty int pressedXproperty int pressedYproperty int snapStartXproperty bool snapX: false;property bool dragging: falsereadonly property bool touchMode: Kirigami.Settings.hasTransientTouchInput || Kirigami.Settings.tabletModeonXChanged: 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)) < Kirigami.Units.gridUnit) {toolBoxContent.state = "topcenter";} else {toolBoxContent.state = "top";}//bottom} else {if (Math.abs(container.width/2 - (x + height/2)) < Kirigami.Units.gridUnit) {toolBoxContent.state = "bottomcenter";} else {toolBoxContent.state = "bottom";}}if (!mouseArea.pressed) {main.placeToolBox(toolBoxContent.state);}stateTimer.running = false;}function destroyToolBox() {main.toolBoxContent = null;toolBoxContent.destroy();}SequentialAnimation {id: enterAnimationPropertyAction {target: toolBoxContentproperty: "visible"value: true}ParallelAnimation {NumberAnimation {target: toolBoxContentproperty: "opacity"duration: Kirigami.Units.longDurationeasing.type: Easing.OutCubicto: 1}NumberAnimation {target: translatorproperty: "y"duration: Kirigami.Units.longDurationeasing.type: Easing.OutCubicfrom: state == "top" || state == "topcenter" ? -height: state == "bottom" || state == "bottomcenter" ? height: 0to: 0}}}SequentialAnimation {id: exitAnimationParallelAnimation {NumberAnimation {target: toolBoxContentproperty: "opacity"duration: Kirigami.Units.longDurationeasing.type: Easing.InCubicto: 0}NumberAnimation {target: translatorproperty: "y"duration: Kirigami.Units.longDurationeasing.type: Easing.InCubicto: state == "top" || state == "topcenter" ? -toolBoxContent.height: state == "bottom" || state == "bottomcenter" ? toolBoxContent.height: 0}}ScriptAction {script: toolBoxContent.destroyToolBox()}}MouseArea {id: mouseAreaanchors {fill: parentleftMargin: -backgroundFrame.margins.lefttopMargin: touchMode ? 0 : -backgroundFrame.margins.toprightMargin: -backgroundFrame.margins.rightbottomMargin: touchMode ? 0 : -backgroundFrame.margins.bottom}drag {filterChildren: truetarget: main.Plasmoid.immutable ? undefined : toolBoxContentminimumX: 0maximumX: container.width - toolBoxContent.widthminimumY: 0maximumY: container.height}hoverEnabled: trueonPressed: {pressedX = toolBoxContent.xpressedY = toolBoxContent.y}onPositionChanged: mouse => {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) > Kirigami.Units.gridUnit) {toolBoxContent.anchors.horizontalCenter = undefined;snapX = false;} else if (!snapX && Math.abs(main.width/2 - (toolBoxContent.x + toolBoxContent.width/2)) < Kirigami.Units.gridUnit) {toolBoxContent.anchors.horizontalCenter = main.horizontalCenter;snapStartX = mouse.x;snapX = true;}}onReleased: mouse => {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;KSvg.FrameSvgItem {id: backgroundFrameanchors.fill: parentimagePath: "widgets/background"width: Math.round(buttonLayout.width + margins.horizontal)height: Math.round(buttonLayout.height + margins.vertical)}Row {id: buttonRowanchors.centerIn: parentspacing: buttonLayout.columnSpacingGrid {id: buttonLayoutrowSpacing: Kirigami.Units.smallSpacingcolumnSpacing: rowSpacing// Show buttons in two lines if screen space is limitedreadonly property real buttonWidth: addWidgetButton.implicitWidth+ addPanelButton.implicitWidth+ configureButton.implicitWidth+ themeButton.implicitWidth+ displaySettingsButton.implicitWidth+ manageContainmentsButton.implicitWidth+ (touchMode ? menuButton.implicitWidth : 0)+ closeButton.implicitWidthrows: Math.ceil(buttonWidth / (Screen.width * 0.8))PlasmaComponents3.ToolButton {id: addWidgetButtonproperty QtObject qAction: Plasmoid.internalAction("add widgets")text: qAction.texticon.name: "list-add"onClicked: qAction.trigger()}PlasmaComponents3.ToolButton {id: addPanelButtonheight: addWidgetButton.heightproperty QtObject qAction: Plasmoid.corona.action("add panel")text: qAction.texticon.name: "list-add"Accessible.role: Accessible.ButtonMenuonClicked: Plasmoid.corona.showAddPanelContextMenu(mapToGlobal(0, height))}PlasmaComponents3.ToolButton {id: configureButtonproperty QtObject qAction: Plasmoid.internalAction("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: KCM.KCMLauncher.openSystemSettings("kcm_lookandfeel")}PlasmaComponents3.ToolButton {id: displaySettingsButtontext: i18nd("plasma_toolbox_org.kde.desktoptoolbox", "Configure Display Settingsβ¦")icon.name: "preferences-desktop-display"onClicked: KCM.KCMLauncher.openSystemSettings("kcm_kscreen")}PlasmaComponents3.ToolButton {id: manageContainmentsButtonproperty QtObject qAction: Plasmoid.corona.action("manage-containments")text: qAction.textvisible: qAction.visibleicon.name: "preferences-system-windows-effect-fadedesktop"onClicked: qAction.trigger()}PlasmaComponents3.ToolButton {id: menuButtonheight: addWidgetButton.heightvisible: touchModeicon.name: "overflow-menu"text: i18ndc("plasma_toolbox_org.kde.desktoptoolbox", "@action:button", "More")onClicked: {container.parent.openContextMenu(mapToGlobal(0, height));}}}PlasmaComponents3.ToolButton {id: closeButtonanchors.verticalCenter: buttonLayout.verticalCenterheight: addWidgetButton.heightdisplay: PlasmaComponents3.AbstractButton.IconOnlyicon.name: "window-close"text: i18nd("plasma_toolbox_org.kde.desktoptoolbox", "Exit Edit Mode")onClicked: Plasmoid.containment.corona.editMode = falsePlasmaComponents3.ToolTip {text: closeButton.text}}}}}