diff --git a/containment/package/contents/ui/ParabolicManager.qml b/containment/package/contents/ui/ParabolicManager.qml index 280fddaa..fcd5f375 100644 --- a/containment/package/contents/ui/ParabolicManager.qml +++ b/containment/package/contents/ui/ParabolicManager.qml @@ -1,407 +1,407 @@ /* * Copyright 2016 Smith AR * Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock 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. * * Latte-Dock 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, see . */ import QtQuick 2.0 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore // holds all the logic around parabolic effect signals into one place. // ParabolicManager is responsible for triggering all the messages to applets // that are neighbour to the hovered applet. This will help a lot to catch cases // such as separator applets, hidden applets and proper clearing zoom. Item { id: parManager property var hidden: [] property var separators: [] //!this is used in order to update the index when the signal is for the internal latte plasmoid //!this is used in order to update the index when the signal is for the internal latte plasmoid function updateIdSendScale(appIndex, index, zScale, zStep){ // console.log(appIndex + " _ "+index+ " _ "+zScale + " _ "+ zStep); if(root.latteApplet && root.latteApplet.parabolicManager.firstRealTaskIndex !== -1 && ((appIndex=root.latteAppletPos) || (appIndex>root.latteAppletPos && index<=root.latteAppletPos)) ){ var appStep = Math.abs(root.latteAppletPos-appIndex); var signalStep = Math.abs(index - appIndex); var taskIndex = -1; var internSepStep = 0; if(appIndexroot.latteAppletPos){ if (root.latteApplet.parabolicManager.taskIsSeparator(root.tasksCount-1) - || (!root.showWindowsWithNoLaunchers && root.latteApplet.parabolicManager.taskIsHiddenBecauseNoLauncherExists(root.tasksCount-1)) ) + || (!root.showWindowsWithNoLaunchers && root.latteApplet.parabolicManager.taskIsForcedHidden(root.tasksCount-1)) ) internSepStep = Math.abs(root.tasksCount-1 - root.latteApplet.parabolicManager.availableLowerIndex(root.tasksCount-1)); taskIndex = root.tasksCount-1 - (signalStep-appStep) - internSepStep; if (root.latteApplet.parabolicManager.taskIsSeparator(taskIndex)) taskIndex = root.latteApplet.parabolicManager.availableLowerIndex(taskIndex - 1); //console.log("reverse:" + taskIndex + " step:"+internSepStep + " zoom:"+zScale); } root.latteApplet.updateScale(taskIndex, zScale,zStep); return taskIndex; } else { // console.log("ch 2..."); root.updateScale(index, zScale, zStep); return -1; } } function applyParabolicEffect(index, currentMousePosition, center) { var rDistance = Math.abs(currentMousePosition - center); //check if the mouse goes right or down according to the center var positiveDirection = ((currentMousePosition - center) >= 0 ); if (Qt.application.layoutDirection === Qt.RightToLeft && !root.isVertical) { positiveDirection = !positiveDirection; } //finding the zoom center e.g. for zoom:1.7, calculates 0.35 var zoomCenter = (root.zoomFactor - 1) / 2 //computes the in the scale e.g. 0...0.35 according to the mouse distance //0.35 on the edge and 0 in the center var firstComputation = (rDistance / center) * zoomCenter; //calculates the scaling for the neighbour tasks var bigNeighbourZoom = Math.min(1 + zoomCenter + firstComputation, root.zoomFactor); var smallNeighbourZoom = Math.max(1 + zoomCenter - firstComputation, 1); //bigNeighbourZoom = Number(bigNeighbourZoom.toFixed(4)); //smallNeighbourZoom = Number(smallNeighbourZoom.toFixed(4)); var leftScale; var rightScale; if(positiveDirection === true){ rightScale = bigNeighbourZoom; leftScale = smallNeighbourZoom; } else { rightScale = smallNeighbourZoom; leftScale = bigNeighbourZoom; } var gAppletIndex = -1; var lAppletIndex = -1; var gTaskIndex = -1; var lTaskIndex = -1; var tLIndex = -1; var tHIndex = -1; var gAppN = availableHigherId(index+1); var lAppN = availableLowerId(index-1); var latteNeighbour = root.latteApplet && ((gAppN === root.latteAppletPos) || (lAppN === root.latteAppletPos )); if(!root.latteApplet || !latteNeighbour || !root.hasInternalSeparator || (root.latteApplet && root.latteApplet.parabolicManager.firstRealTaskIndex===-1) || (root.latteApplet && root.hasInternalSeparator && ((!root.latteApplet.parabolicManager.taskIsSeparator(0) && !root.latteApplet.parabolicManager.taskIsSeparator(root.tasksCount-1)) || (root.latteApplet.parabolicManager.taskIsSeparator(0) && index>root.latteAppletPos) || (root.latteApplet.parabolicManager.taskIsSeparator(root.tasksCount-1) && index -1) latteApplet.parabolicManager.clearTasksGreaterThan(gTaskIndex); if (lTaskIndex > -1) latteApplet.parabolicManager.clearTasksLowerThan(lTaskIndex); } } clearAppletsGreaterThan(gAppletIndex+1, 1, 0); clearAppletsLowerThan(lAppletIndex-1, 1, 0); return {leftScale:leftScale, rightScale:rightScale}; } function clearAppletsGreaterThan(index) { var startLastIndex = layoutsContainer.startLayout.beginIndex+layoutsContainer.startLayout.count-1; if (indexlayoutsContainer.mainLayout.beginIndex ? index+1 : layoutsContainer.mainLayout.beginIndex; for (var j=mainClearStart; j<=mainLastIndex; ++j) root.updateScale(j, 1, 0); } var endLastIndex = layoutsContainer.endLayout.beginIndex+layoutsContainer.endLayout.count-1; if (indexlayoutsContainer.endLayout.beginIndex ? index+1 : layoutsContainer.endLayout.beginIndex; for (var k=endClearStart; k<=endLastIndex; ++k) root.updateScale(k, 1, 0); } } function clearAppletsLowerThan(index) { var startBeginIndex = layoutsContainer.startLayout.beginIndex; var startLastIndex = layoutsContainer.startLayout.beginIndex+layoutsContainer.startLayout.count-1; if (index>startBeginIndex) { var startClearStart = index<=startLastIndex ? index-1 : startLastIndex; for (var i=startClearStart; i>=startBeginIndex; --i) root.updateScale(i, 1, 0); } var mainBeginIndex = layoutsContainer.mainLayout.beginIndex; var mainLastIndex = layoutsContainer.mainLayout.beginIndex+layoutsContainer.mainLayout.count-1; if (index>mainBeginIndex) { var mainClearStart = index<=mainLastIndex ? index-1 : mainLastIndex; for (var j=mainClearStart; j>=mainBeginIndex; --j) root.updateScale(j, 1, 0); } var endBeginIndex = layoutsContainer.endLayout.beginIndex; var endLastIndex = layoutsContainer.endLayout.beginIndex+layoutsContainer.endLayout.count-1; if (index>endBeginIndex) { var endClearStart = index<=endLastIndex ? index-1 : endLastIndex; for (var k=endClearStart; k>=endBeginIndex; --k) root.updateScale(k, 1, 0); } } // update the registered separators // -1, no = add separator // no, -1 = remove separator // no, no = update separator position function setSeparator(previousId, nextId) { if (previousId === nextId && separators.indexOf(nextId)>-1) return; //if (plasmoid.location === PlasmaCore.Types.BottomEdge) // console.log("message: "+previousId + " - " + nextId); var update=false; //should update if (previousId>-1 && nextId>-1) update=true; //remove if ((previousId>-1 && nextId===-1) || update) { var ind = separators.indexOf(previousId); if (ind>-1) separators.splice(ind,1); } //add if ((previousId===-1 && nextId>-1) || update) { separators.push(nextId); } //if (plasmoid.location === PlasmaCore.Types.BottomEdge) // console.log("separators : "+separators); root.separatorsUpdated(); } // update the registered hidden applets // -1, no = add hidden // no, -1 = remove hidden // no, no = update hidden position function setHidden(previousId, nextId) { if (previousId === nextId && hidden.indexOf(nextId)>-1) return; var update=false; //should update if (previousId>-1 && nextId>-1) update=true; //remove if ((previousId>-1 && nextId===-1) || update) { var ind = hidden.indexOf(previousId); if (ind>-1) hidden.splice(ind,1); } //add if ((previousId===-1 && nextId>-1) || update) { hidden.push(nextId); } // console.log("hidden : "+hidden); } function availableLowerId(from) { var next = from; while (separators.indexOf(next) !== -1 || hidden.indexOf(next) !== -1 || (root.latteApplet && root.latteAppletPos===next && root.latteApplet.parabolicManager.firstRealTaskIndex === -1 )) next = next - 1; return next; } function availableHigherId(from) { var next = from; while (separators.indexOf(next) !== -1 || hidden.indexOf(next) !== -1 || (root.latteApplet && root.latteAppletPos===next && root.latteApplet.parabolicManager.firstRealTaskIndex === -1 )) next = next + 1; return next; } function isSeparator(index){ return (separators.indexOf(index) !== -1) } function isHidden(index) { return (hidden.indexOf(index) !== -1) } //! the pseudo index applet after we take into account the separators before it, hidden applets, //! spacers etc. for example the third applet if there is a separator before it is 1, it isnt 2 function pseudoAppletIndex(realIndex) { var counter = 0; var originalAppletFound = false; for (var i=0; iroot.latteApplet.tasksNumbersBase && index<=lastTaskIndex); } return false; } } diff --git a/plasmoid/package/contents/ui/ParabolicManager.qml b/plasmoid/package/contents/ui/ParabolicManager.qml index 5ca8d757..51dac957 100644 --- a/plasmoid/package/contents/ui/ParabolicManager.qml +++ b/plasmoid/package/contents/ui/ParabolicManager.qml @@ -1,658 +1,652 @@ /* * Copyright 2016 Smith AR * Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock 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. * * Latte-Dock 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, see . */ import QtQuick 2.0 import org.kde.plasma.plasmoid 2.0 import org.kde.latte 0.1 as Latte // holds all the logic around parabolic effect signals into one place. // ParabolicManager is responsible for triggering all the messages to tasks // that are neighbour to the hovered task. This will help a lot to catch cases // such as separators and proper clearing zoom. Item { id: parManager property bool hasInternalSeparator: false property int firstRealTaskIndex: -1 property int lastRealTaskIndex: -1 property int countRealTasks: -1 //tasks that change state (launcher,startup,window) and //at the next state must look the same //(id, mScale) property variant frozenTasks: [] //the internal separators in the form //(launcherUrl, index) property variant separators: [] //new launchers in order to be moved in correct place //(launcher, pos) property variant launchersToBeMoved: [] Connections{ target: root onTasksCountChanged:parManager.updateTasksEdgesIndexes(); onDragSourceChanged: { if (!root.dragSource && parManager.hasInternalSeparator) { //! Send the internal separators to other docks var tasks = icList.contentItem.children; var size = icList.contentItem.children.length; var tempSeparatorsArray = []; var tempSeparatorsIndexes = []; for(var i=0; i=icList.contentItem.children.length) { break; } if (tasks[i] && tasks[i].isSeparator) { tempSeparatorsArray.push(tasks[i].launcherUrl); tempSeparatorsIndexes.push(tasks[i].itemIndex); } } if (tempSeparatorsArray.length > 0) { if (latteDock && latteDock.launchersGroup >= Latte.Dock.LayoutLaunchers) { //reorder to lowest for(var i=0; i=0 && index<=root.tasksCount-1) || (!root.latteDock)){ root.updateScale(index, zScale, zStep); return -1; } else{ var appletId = latteDock.latteAppletPos; if (index<0) appletId = latteDock.parabolicManager.availableLowerId(latteDock.latteAppletPos + index); else if (index>root.tasksCount-1){ var step=index-root.tasksCount+1; appletId = latteDock.parabolicManager.availableHigherId(latteDock.latteAppletPos + step); } latteDock.updateScale(appletId, zScale, zStep); return appletId; } } function applyParabolicEffect(index, currentMousePosition, center) { var rDistance = Math.abs(currentMousePosition - center); //check if the mouse goes right or down according to the center var positiveDirection = ((currentMousePosition - center) >= 0 ); if (Qt.application.layoutDirection === Qt.RightToLeft && !root.vertical) { positiveDirection = !positiveDirection; } var minimumZoom = 1; //finding the zoom center e.g. for zoom:1.7, calculates 0.35 var zoomCenter = ((root.zoomFactor + minimumZoom)/2) - 1; //computes the in the scale e.g. 0...0.35 according to the mouse distance //0.35 on the edge and 0 in the center var firstComputation = (rDistance / center) * (zoomCenter-minimumZoom+1); //calculates the scaling for the neighbour tasks var bigNeighbourZoom = Math.min(1 + zoomCenter + firstComputation, root.zoomFactor); var smallNeighbourZoom = Math.max(1 + zoomCenter - firstComputation, minimumZoom); //bigNeighbourZoom = Number(bigNeighbourZoom.toFixed(4)); //smallNeighbourZoom = Number(smallNeighbourZoom.toFixed(4)); var leftScale; var rightScale; if(positiveDirection === true){ rightScale = bigNeighbourZoom; leftScale = smallNeighbourZoom; } else { rightScale = smallNeighbourZoom; leftScale = bigNeighbourZoom; } // console.debug(leftScale + " " + rightScale + " " + index); //first applets accessed var gPAppletId = -1; var lPAppletId = -1; //secondary applets accessed to restore zoom var gAppletId = -1; var lAppletId = -1; var gStep = 1; var lStep = 1; //console.log("--- task style 2..."); var aGId1 = availableHigherIndex(index+1); var aLId1 = availableLowerIndex(index-1); gPAppletId = updateIdSendScale(aGId1, rightScale, 0); lPAppletId = updateIdSendScale(aLId1, leftScale, 0); // console.log("index:"+index + " lattePos:"+latteDock.latteAppletPos); // console.log("gApp:"+gPAppletId+" lApp:"+lPAppletId+ " aG1:"+aGId1+" aLId1:"+aLId1); gStep = aGId1 - index; lStep = index - aLId1; if (latteDock) { if (gPAppletId > -1) gStep = Math.abs(gPAppletId - latteDock.latteAppletPos + (root.tasksCount-1-index)); if (lPAppletId > -1) lStep = Math.abs(lPAppletId - latteDock.latteAppletPos - index); } //console.log("gs:"+gStep+" ls:"+lStep); gAppletId = updateIdSendScale(index+gStep+1, 1, 0); lAppletId = updateIdSendScale(index-lStep-1, 1, 0); //console.log(" cgApp:"+gAppletId+" clApp:"+lAppletId); clearTasksGreaterThan(aGId1+1); clearTasksLowerThan(aLId1-1); if (latteDock){ if (gAppletId > -1) latteDock.parabolicManager.clearAppletsGreaterThan(gAppletId); else latteDock.parabolicManager.clearAppletsGreaterThan(latteDock.latteAppletPos); if (lAppletId > -1) latteDock.parabolicManager.clearAppletsLowerThan(lAppletId); else latteDock.parabolicManager.clearAppletsLowerThan(latteDock.latteAppletPos-1); } return {leftScale:leftScale, rightScale:rightScale}; } function clearTasksGreaterThan(index) { if (index0 && root.tasksCount>2) { for(var i=0; i-1 && (hovered === index || hovered === availableLowerIndex(index-1) || hovered === availableHigherIndex(index+1) )) { return true; } return false; } //! Frozen Tasks functions function getFrozenTask(identifier) { for(var i=0; i -1) { frozenTasks.splice(taskIndex, 1); } } function setFrozenTask(identifier, scale) { var frozenTaskExists = false; console.log("SET FROZEN :: "+identifier+" - "+scale); var frozenTask = getFrozenTask(identifier); if (frozenTask) { frozenTask.mScale = scale; } else { frozenTasks.push({id: identifier, mScale: scale}); } } //! SEPARATORS functions // update the registered separators // launcherUrl, no = add/update separator // launcherUrl, -1 = remove separator function setSeparator(launcher, taskIndex) { var currentPos = separatorArrayPos(launcher); var updated = false; if (currentPos === -1 && taskIndex >=0){ //add that separator //console.log("add separator:"+launcher+" at:"+taskIndex); separators.push({launcherUrl: launcher, index: taskIndex}); updated = true; } else if (currentPos>-1 && taskIndex === -1) { //remove that separator //console.log("remove separator:"+launcher); separators.splice(currentPos,1); updated = true; } else if (currentPos>-1 && taskIndex>-1 && separators[currentPos].index !== taskIndex) { //update that separator //console.log("update separator:"+launcher+" from:"+separators[currentPos].index+" -> "+taskIndex); separators[currentPos].index = taskIndex; updated = true; } //if (separators.length > 0) // console.log(separators[0].launcherUrl+ " _________ " + separators[0].index); if (updated) { //console.log("message sent..."); hasInternalSeparator = separators.length > 0; updateTasksEdgesIndexes(); root.separatorsUpdated(); } } function separatorArrayPos(launcher) { var res = -1; var sLength = separators.length; for (var i=0; i=separators.length) return false; if (separators[i].launcherUrl === launcher) return i; } return res; } function availableLowerIndex(from) { var next = from; while (next>=0 - && (taskIsSeparator(next) || (root.showWindowsOnlyFromLaunchers && taskIsHiddenBecauseNoLauncherExists(next))) ) + && (taskIsSeparator(next) || (root.showWindowsOnlyFromLaunchers && taskIsForcedHidden(next))) ) next = next - 1; return next; } function availableHigherIndex(from) { var next = from; while (next<=root.tasksCount-1 - && (taskIsSeparator(next) || (root.showWindowsOnlyFromLaunchers && taskIsHiddenBecauseNoLauncherExists(next))) ) { + && (taskIsSeparator(next) || (root.showWindowsOnlyFromLaunchers && taskIsForcedHidden(next))) ) { next = next + 1; } return next; } function isSeparator(launcher){ return (launcher.indexOf("latte-separator")!==-1 && launcher.indexOf(".desktop")!==1); } function taskIsSeparator(taskIndex){ var sLength = separators.length; for (var i=0; i=separators.length) return false; if (separators[i].index === taskIndex) return true; } return false; } - function taskIsHiddenBecauseNoLauncherExists(taskIndex) { + function taskIsForcedHidden(taskIndex) { var task = icList.childAtIndex(taskIndex); - if (task && root.showWindowsOnlyFromLaunchers) { - var launcherExists = !(((tasksModel.launcherPosition(task.launcherUrl) == -1) - && (tasksModel.launcherPosition(task.launcherUrlWithIcon) == -1) ) - || !task.launcherIsPresent(task.launcherUrl)); - - //console.log(task.launcherUrl + " ::: " +!launcherExists + " _ " + task.isWindow); - - return (!launcherExists && task.isWindow); - } - - return false; + //!tasks that become hidden there is a chance to have index===-1 and to not be + //!able to be tracked down + return ((!task && (taskIndex>=0 && taskIndex=0); } //! the real index task after we take into account the separators before it //! for example the first task if there is a separator before it is 1, it isnt 0 function realTaskIndex(pseudoIndex) { if (hasInternalSeparator) { var steps = pseudoIndex + 1; var pos = 0; while (steps > 0) { if (!taskIsSeparator(pos)) { steps = steps - 1; } if (steps > 0) pos = pos + 1; } return pos; } else { return pseudoIndex; } } //! the pseudo index task after we take into account the separators before it //! for example the third task if there is a separator before it is 1, it isnt 2 function pseudoTaskIndex(realIndex) { var pseudoIndex = realIndex; if (hasInternalSeparator) { for (var i=0; i