/**************************************************************************** Copyright 2012,2015 by Sebastian KΓΌgler <sebas@kde.org> ** Copyright 2015 by Kai Uwe Broulik <kde@privat.broulik.de> ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the ** Free Software Foundation, Inc., ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . ****************************************************************************/import QtQuick 2.4import QtQuick.Layouts 1.4import 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: toolBoxButtontransform: Translate {y: plasmoid.editMode ? 0: state == "top" || state == "topcenter" ? -height: state == "bottom" || state == "bottomcenter" ? height: 0Behavior on y {NumberAnimation {duration: units.longDurationeasing.type: Easing.InOutQuad}}}transformOrigin: Item.Centeropacity: plasmoid.editModevisible: plasmoid.editModeBehavior on opacity {OpacityAnimator {duration: units.longDurationeasing.type: Easing.InOutQuad}enabled: visible}Behavior on rotation {NumberAnimation {duration: units.shortDuration * 3;easing.type: Easing.InOutExpo;}enabled: visible}Behavior on x {NumberAnimation {duration: units.shortDuration * 3;easing.type: Easing.InOutExpo;}enabled: visible}Behavior on y {NumberAnimation {duration: units.shortDuration * 3;easing.type: Easing.InOutExpo;}enabled: visible}width: buttonLayout.widthheight: buttonLayout.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: " + toolBoxButton.width);var x = toolBoxButton.x - main.x;var y = toolBoxButton.y - main.y;var cornerSnap = iconWidth//topif (y + height / 2 < container.height / 2) {if (Math.abs(container.width/2 - (x + width/2)) < units.gridUnit) {toolBoxButton.state = "topcenter";} else {toolBoxButton.state = "top";}//bottom} else {if (Math.abs(container.width/2 - (x + height/2)) < units.gridUnit) {toolBoxButton.state = "bottomcenter";} else {toolBoxButton.state = "bottom";}}if (!buttonMouse.pressed) {main.placeToolBox(toolBoxButton.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 : toolBoxButtonminimumX: 0maximumX: container.width - toolBoxButton.widthminimumY: 0maximumY: container.height}hoverEnabled: trueonPressed: {pressedX = toolBoxButton.xpressedY = toolBoxButton.y}onPositionChanged: {if (pressed && (Math.abs(toolBoxButton.x - pressedX) > iconSize ||Math.abs(toolBoxButton.y - pressedY) > iconSize)) {dragging = true;}// Center snapping Xif (snapX && Math.abs(snapStartX - mouse.x) > units.gridUnit) {toolBoxButton.anchors.horizontalCenter = undefined;snapX = false;} else if (!snapX && Math.abs(main.width/2 - (toolBoxButton.x + toolBoxButton.width/2)) < units.gridUnit) {toolBoxButton.anchors.horizontalCenter = main.horizontalCenter;snapStartX = mouse.x;snapX = true;}}onReleased: {toolBoxButton.anchors.horizontalCenter = undefined;toolBoxButton.anchors.verticalCenter = undefined;snapX = false;main.Plasmoid.configuration.ToolBoxButtonState = toolBoxButton.state;main.Plasmoid.configuration.ToolBoxButtonX = toolBoxButton.x;main.Plasmoid.configuration.ToolBoxButtonY = toolBoxButton.y;//print("Saved coordinates for ToolBox in config: " + toolBoxButton.x + ", " +toolBoxButton.x);if (dragging) {main.placeToolBox();}dragging = false;stateTimer.stop();updateState();}onCanceled: dragging = false;RowLayout {id: buttonLayoutanchors.centerIn: parentspacing: units.smallSpacingPlasmaComponents3.ToolButton {property QtObject qAction: plasmoid.action("add widgets")text: qAction.texticon.name: "list-add"icon.height: units.iconSizes.smallMediumonClicked: qAction.trigger()}PlasmaComponents3.ToolButton {property QtObject qAction: plasmoid.globalAction("manage activities")text: qAction.texticon.name: "activities"icon.height: units.iconSizes.smallMediumonClicked: qAction.trigger()}PlasmaComponents3.ToolButton {property QtObject qAction: plasmoid.action("configure")text: qAction.texticon.name: "preferences-desktop-wallpaper"icon.height: units.iconSizes.smallMediumonClicked: qAction.trigger()}PlasmaComponents3.ToolButton {icon.name: "window-close"icon.height: units.iconSizes.smallMediumLayout.preferredWidth: heightonClicked: plasmoid.editMode = falsePlasmaComponents3.ToolTip {text: i18n("Finish Customizing Layout")}}}}}