/* * Copyright 2011 Marco Martin * * 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 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. */ .pragma library var positions = new Array(); var cellSize = new Object(); cellSize.width = 24; cellSize.height = 24; var defaultAppletSize = new Object(); defaultAppletSize.width = cellSize.width * 6; defaultAppletSize.height = cellSize.height * 6; var resultsFlow var plasmoid; var itemsConfig //bookkeeping for the item groups var itemGroups = new Object() function restore() { var appletsMap = new Object(); var applet; for (var i = 0; i < plasmoid.applets.length; ++i) { applet = plasmoid.applets[i]; appletsMap["Applet-"+applet.id] = applet; } itemsConfig = new Object(); var configString = String(plasmoid.configuration.ItemsGeometries) //print("Config read from configfile: " + configString); //array, a cell for encoded item geometry var itemsStrings = configString.split(";") for (var i=0; i= Math.max(item.minimumWidth, cellSize.width) && forwardAvail.height >= Math.max(item.minimumHeight, cellSize.height)) { x = forwardX y = forwardY avail = forwardAvail break } forwardX += cellSize.width //new line if (forwardX+item.width > resultsFlow.width) { forwardX = 0 forwardY += cellSize.height //forward positions exausted //scrolling now /*if (forwardY > resultsFlow.height) { break; }*/ } //backwards positions exausted if (backY < 0) { continue } //look backwards var backAvail = availableSpace(backX, backY, Math.max(item.minimumWidth, item.width), Math.max(item.minimumHeight, item.height)) //print("checking backwards "+backX/cellSize.width+" "+backY/cellSize.height+" "+backAvail.width/cellSize.width+" "+backAvail.height/cellSize.height) if (backAvail.width >= Math.max(item.minimumWidth, cellSize.width) && backAvail.height >= Math.max(item.minimumHeight, cellSize.height)) { x = backX y = backY avail = backAvail break } backX -= cellSize.width if (backX < 0) { backX = resultsFlow.width - item.width backY -= cellSize.height } } var width = Math.max(cellSize.width*Math.max(1, Math.ceil(item.minimumWidth/cellSize.width)), Math.round(Math.min(avail.width, item.width)/cellSize.width)*cellSize.width) var height = Math.max(cellSize.height*Math.max(1, Math.ceil(item.minimumHeight/cellSize.height)), Math.round(Math.min(avail.height, item.height)/cellSize.height)*cellSize.height) setSpaceAvailable(x, y, width, height, false) //resultsFlow.height = Math.max(resultsFlow.height, y+cellSize.height) item.x = x item.y = y item.width = width item.height = height saveItem(item); } function removeApplet(applet) { // Keeps config in sync, deletion of items in the scene // are handled in AppletAppearance and main.qml delete itemsConfig["Applet-"+applet.id]; delete itemGroups["Applet-"+applet.id]; } function saveItem(item) { var rect = new Object() rect.x = item.x rect.y = item.y rect.width = item.width rect.height = item.height rect.rotation = item.rotation //print("-- Saving rotation : " + rect.rotation); //save only things that actually have a category (exclude the placeholder) if (item.category) { //print("-- Saving rotation : " + rect.rotation); itemsConfig[item.category] = rect } }