diff --git a/plasmoid/package/contents/ui/MouseHandler.qml b/plasmoid/package/contents/ui/MouseHandler.qml index d5110a22..294d441d 100644 --- a/plasmoid/package/contents/ui/MouseHandler.qml +++ b/plasmoid/package/contents/ui/MouseHandler.qml @@ -1,251 +1,253 @@ /* * 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.draganddrop 2.0 import org.kde.taskmanager 0.1 as TaskManager import org.kde.latte 0.1 as Latte import "../code/tools.js" as TaskTools Item { // signal urlDropped(url url) signal urlsDropped(var urls) property Item target property Item ignoredItem property bool moved: false property alias hoveredItem: dropHandler.hoveredItem property alias onlyLaunchers: dropHandler.onlyLaunchers Timer { id: ignoreItemTimer repeat: false interval: 200 onTriggered: { ignoredItem = null; } } Connections { target: root onDragSourceChanged: { if (!dragSource) { ignoredItem = null; ignoreItemTimer.stop(); } } } DropArea { id: dropHandler anchors.fill: parent preventStealing: true; property int droppedPosition: -1; property bool onlyLaunchers: false; property bool droppingSeparator: false; property Item hoveredItem function isDroppingSeparator(event) { return ((event.mimeData.formats.indexOf("text/x-plasmoidservicename") === 0) && (String(event.mimeData.getDataAsByteArray("text/x-plasmoidservicename")) === "audoban.applet.separator")); } onDragEnter:{ if(root.dragSource == null){ onlyLaunchers = false; droppingSeparator = false; root.dropNewLauncher = false; var createLaunchers = false; if (event.mimeData.hasUrls || (event.mimeData.formats.indexOf("text/x-plasmoidservicename") !== 0)) { root.dropNewLauncher = true; if (event.mimeData.hasUrls){ createLaunchers = event.mimeData.urls.every(function (item) { return backend.isApplication(item) }); } } else if (isDroppingSeparator(event)) { droppingSeparator = true; root.dropNewLauncher = true; return; } else { event.ignore(); } if (createLaunchers) { onlyLaunchers = true; } } } onDragMove: { /* if(root.dragSource == null){ root.dropNewLauncher = true; } */ if (target.animating) { return; } var above = target.childAtPos(event.x, event.y); // If we're mixing launcher tasks with other tasks and are moving // a (small) launcher task across a non-launcher task, don't allow // the latter to be the move target twice in a row for a while, as // it will naturally be moved underneath the cursor as result of the // initial move, due to being far larger than the launcher delegate. // TODO: This restriction (minus the timer, which improves things) // has been proven out in the EITM fork, but could be improved later // by tracking the cursor movement vector and allowing the drag if // the movement direction has reversed, etablishing user intent to // move back. if (root.dragSource == null && ignoredItem == above) return; if (root.dragSource != null && root.dragSource.m.IsLauncher === true && above != null && above.m != null && above.m.IsLauncher !== true && above == ignoredItem) { return; } else { //ignoredItem = null; } //at some point it was needed the following && above != ignoredItem //but know not... strange... && above != ignoredItem //I use the ignoredItem in order to reduce the move calls as much //as possible if (tasksModel.sortMode == TaskManager.TasksModel.SortManual && root.dragSource && ignoredItem == null) { var insertAt = TaskTools.insertIndexAt(above, event.x, event.y); if (root.dragSource != above && root.dragSource.itemIndex != insertAt) { // console.log(root.dragSource.itemIndex + " - "+insertAt); root.dragSource.z = 100; ignoredItem = above; var pos = root.dragSource.itemIndex; tasksModel.move(pos, insertAt); if (latteDock && latteDock.launchersGroup >= Latte.Dock.LayoutLaunchers) { latteDock.universalLayoutManager.launchersSignals.moveTask(root.managedLayoutName, plasmoid.id, latteDock.launchersGroup, pos, insertAt); } - + root.separatorsUpdated(); ignoreItemTimer.restart(); } } else if (!root.dragSource && above && hoveredItem != above) { hoveredItem = above; //root.dropNewLauncher = true; activationTimer.restart(); } else if (!above) { //root.dropNewLauncher = true; hoveredItem = null; activationTimer.stop(); } if (hoveredItem && windowsPreviewDlg.visible && toolTipDelegate.parentIndex !== hoveredItem.itemIndex ) { windowsPreviewDlg.hide(6); } } onDragLeave: { hoveredItem = null; root.dropNewLauncher = false; onlyLaunchers = false; + root.separatorsUpdated(); activationTimer.stop(); } onDrop: { // Reject internal drops. root.dropNewLauncher = false; onlyLaunchers = false; + root.separatorsUpdated(); if (event.mimeData.formats.indexOf("application/x-orgkdeplasmataskmanager_taskbuttonitem") >= 0) { return; } if (droppingSeparator) { droppingSeparator = false; if (hoveredItem && hoveredItem.itemIndex >=0){ root.addInternalSeparatorAtPos(hoveredItem.itemIndex); } else { root.addInternalSeparatorAtPos(0); } return; } if (event.mimeData.hasUrls) { parent.urlsDropped(event.mimeData.urls); } } Timer { id: activationTimer interval: 250 repeat: false onTriggered: { if (dropHandler.onlyLaunchers || !root.dropNewLauncher || dropHandler.droppingSeparator) { return; } if (parent.hoveredItem.m.IsGroupParent === true) { root.showPreviewForTasks(parent.hoveredItem); // groupDialog.visualParent = parent.hoveredItem; // groupDialog.visible = true; } else if (parent.hoveredItem.m.IsLauncher !== true) { if(windowsPreviewDlg.visible && toolTipDelegate.currentItem !==parent.hoveredItem.itemIndex ) { windowsPreviewDlg.hide(5); toolTipDelegate.currentItem=-1; } tasksModel.requestActivate(parent.hoveredItem.modelIndex()); } } } } /* MouseArea { id: wheelHandler anchors.fill: parent property int wheelDelta: 0; enabled: plasmoid.configuration.wheelEnabled onWheel: wheelDelta = TaskTools.wheelActivateNextPrevTask(wheelDelta, wheel.angleDelta.y); } */ } diff --git a/plasmoid/package/contents/ui/ParabolicManager.qml b/plasmoid/package/contents/ui/ParabolicManager.qml index a86bc773..85b140cb 100644 --- a/plasmoid/package/contents/ui/ParabolicManager.qml +++ b/plasmoid/package/contents/ui/ParabolicManager.qml @@ -1,548 +1,545 @@ /* * 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: [] //new launchers in order to be moved in correct place //(launcher, pos) property variant launchersToBeMoved: [] Connections{ target: root onTasksCountChanged: parManager.updateTasksEdgesIndexes(); onHiddenTasksUpdated: parManager.updateTasksEdgesIndexes(); } Component.onCompleted: { updateHasInternalSeparator(); updateTasksEdgesIndexes(); root.separatorsUpdated.connect(updateHasInternalSeparator); } Component.onDestruction: { root.separatorsUpdated.disconnect(updateHasInternalSeparator); } function updateTasksEdgesIndexes() { var newFirstTask = firstRealTask(); var newLastTask = lastRealTask(); if (newFirstTask !== firstRealTaskIndex || newLastTask !== lastRealTaskIndex ){ firstRealTaskIndex = newFirstTask; lastRealTaskIndex = newLastTask; root.separatorsUpdated(); } countRealTasks = realTasks(); } function updateHasInternalSeparator() { var count = icList.contentItem.children.length; 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}); } } function availableLowerIndex(from) { var next = from; while (next>=0 && (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 && taskIsForcedHidden(next))) ) { next = next + 1; } return next; } function isSeparator(launcher){ return (launcher.indexOf("latte-separator")!==-1 && launcher.indexOf(".desktop")!==1); } function taskIsSeparator(taskIndex){ var task = icList.childAtIndex(taskIndex); return (task && !task.isForcedHidden && task.isSeparator); } function taskIsForcedHidden(taskIndex) { var task = icList.childAtIndex(taskIndex); //!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