/** Copyright 2011 Sebastian KΓΌgler <sebas@kde.org>* Copyright 2011 Marco Martin <mart@kde.org>** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU Library General Public License as* published by the Free Software Foundation; either version 2 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 Library General Public License for more details** You should have received a copy of the GNU Library 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.0import org.kde.plasma.core 2.0 as PlasmaCoreimport org.kde.plasma.components 2.0 as PlasmaComponentsimport org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddonsimport org.kde.plasma.extras 2.0 as PlasmaExtrasimport org.kde.plasma.plasmoid 2.0Item {id: mainz: 999anchors.fill: parentItem {id: mainAreax: plasmoid.availableScreenRect.xy: plasmoid.availableScreenRect.ywidth: plasmoid.availableScreenRect.widthheight: plasmoid.availableScreenRect.heightonXChanged: placeToolBoxTimer.restart();onYChanged: placeToolBoxTimer.restart();onWidthChanged: placeToolBoxTimer.restart();onHeightChanged: placeToolBoxTimer.restart();}signal minimumWidthChangedsignal minimumHeightChangedsignal maximumWidthChangedsignal maximumHeightChangedsignal preferredWidthChangedsignal preferredHeightChangedproperty int iconSize: units.iconSizes.smallproperty int iconWidth: units.iconSizes.smallMediumproperty int iconHeight: iconWidthonWidthChanged: placeToolBoxTimer.restart();onHeightChanged: placeToolBoxTimer.restart();LayoutMirroring.enabled: (Qt.application.layoutDirection === Qt.RightToLeft)LayoutMirroring.childrenInherit: trueConnections {target: plasmoidonFocusChanged: {if (!plasmoid.focus) {toolBoxItem.showing = false;}}}MouseArea {id: toolBoxDismisseranchors.fill: parentvisible: toolBoxItem.showingonPressed: toolBoxItem.showing = false}ToolBoxButton {id: toolBoxButtonvisible: falseComponent.onCompleted: {placeToolBox(plasmoid.configuration.ToolBoxButtonState);toolBoxButton.visible = true}}Timer {id: placeToolBoxTimerinterval: 100repeat: falserunning: falseonTriggered: {placeToolBox(plasmoid.configuration.ToolBoxButtonState);}}PlasmaExtras.ConditionalLoader {id: toolBoxItemproperty alias showing: toolBoxItem.whenstate: item ? item.state : "collapsed"property int margin: 22width: item ? item.width : 0height: item ? item.height : 0x: {var maxX = main.width - toolBoxItem.width - marginif (toolBoxButton.x > maxX) {return maxX;} else {return Math.max(toolBoxButton.x, margin);}}y: {var maxY = main.height - (item ? item.childrenRect.height : 0) - marginif (toolBoxButton.y > maxY) {return maxY;} else {return Math.max(toolBoxButton.y, margin);}}anchors.margins: 16source: Component {ToolBoxItem {showing: toolBoxItem.showing}}}function placeToolBox(ts) {var tx = Plasmoid.configuration.ToolBoxButtonXvar ty = Plasmoid.configuration.ToolBoxButtonYswitch (ts) {case "top":ty = mainArea.y;break;case "left":tx = mainArea.x;break;case "right":tx = mainArea.width + mainArea.x - toolBoxButton.width;break;case "bottom":ty = mainArea.height + mainArea.y - toolBoxButton.height;break;case "topleft":tx = mainArea.x;ty = mainArea.y;break;case "topright":tx = mainArea.width + mainArea.x - toolBoxButton.height;ty = mainArea.y;break;case "bottomleft":tx = mainArea.x;ty = mainArea.height + mainArea.y - toolBoxButton.height;break;case "bottomright":default:tx = mainArea.width + mainArea.x - toolBoxButton.height;ty = mainArea.height + mainArea.y - toolBoxButton.height;break;}//print("XXXY Setting toolbox to: " + ts + " " + tx + "x" + ty + " screen: " + main.width+ "x" + main.height+"");toolBoxButton.x = tx;toolBoxButton.y = ty;}}