From a9df1d6745d044c8aea4a09e65ef1c863458de63 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Tue, 23 May 2017 19:19:02 +0300 Subject: [PATCH] add ParabolicManager in the plasmoid --move all the logic around parabolic effect signals into one place, ParabolicManager. The 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. --- .../package/contents/ui/ParabolicManager.qml | 114 ++++++++++++++++++ plasmoid/package/contents/ui/main.qml | 15 ++- .../package/contents/ui/task/TaskDelegate.qml | 10 +- .../package/contents/ui/task/TaskIconItem.qml | 3 +- .../package/contents/ui/task/TaskWrapper.qml | 87 +------------ 5 files changed, 134 insertions(+), 95 deletions(-) create mode 100644 plasmoid/package/contents/ui/ParabolicManager.qml diff --git a/plasmoid/package/contents/ui/ParabolicManager.qml b/plasmoid/package/contents/ui/ParabolicManager.qml new file mode 100644 index 000000000..7f1ee48bd --- /dev/null +++ b/plasmoid/package/contents/ui/ParabolicManager.qml @@ -0,0 +1,114 @@ +/* +* 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 + +// 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: internalSeparatorPos > -1 + + property int internalSeparatorPos: -1 + + //!this is used in order to update the index when the signal is for applets + //!outside the latte plasmoid + function updateIdSendScale(index, zScale, zStep){ + if ((index>=0 && index<=root.tasksCount-1) || (!root.latteDock)){ + root.updateScale(index, zScale, zStep); + } else{ + var appletId = latteDock.latteAppletPos; + if (index<0) + appletId = latteDock.latteAppletPos + index; + else if (index>root.tasksCount-1){ + var step=index-root.tasksCount+1; + appletId = latteDock.latteAppletPos + step; + } + + latteDock.updateScale(appletId, zScale, zStep); + } + } + + 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 ); + + 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); + + if(!hasInternalSeparator || Math.abs(index-internalSeparatorPos)>=2){ + //activate messages to update the the neighbour scales + updateIdSendScale(index+1, rightScale, 0); + updateIdSendScale(index-1, leftScale, 0); + + updateIdSendScale(index+2, 1, 0); + updateIdSendScale(index-2, 1, 0); + } else if(root.internalSeparatorPos>=0) { + if(internalSeparatorPos === index+1){ + updateIdSendScale(index+2, rightScale, 0); + updateIdSendScale(index-1, leftScale, 0); + + + updateIdSendScale(index+3, 1, 0); + updateIdSendScale(index-2, 1, 0); + } else if(internalSeparatorPos === index-1) { + updateIdSendScale(index-2, leftScale, 0); + updateIdSendScale(index+1, rightScale, 0); + + updateIdSendScale(index+2, 1, 0); + updateIdSendScale(index-3, 1, 0); + } + } + + return {leftScale:leftScale, rightScale:rightScale}; + } +} diff --git a/plasmoid/package/contents/ui/main.qml b/plasmoid/package/contents/ui/main.qml index 718614de2..1d897dc84 100644 --- a/plasmoid/package/contents/ui/main.qml +++ b/plasmoid/package/contents/ui/main.qml @@ -60,7 +60,7 @@ Item { property bool editMode: latteDock ? latteDock.editMode : plasmoid.userConfiguring property bool disableRestoreZoom: false //blocks restore animation in rightClick property bool dropNewLauncher: false - property bool hasInternalSeparator: false + readonly property bool hasInternalSeparator: parabolicManager.hasInternalSeparator property bool initializationStep: false //true property bool initializatedBuffers: true // noInitCreatedBuffers >= tasksStarting ? true : false property bool isHovered: false @@ -74,7 +74,7 @@ Item { property int clearWidth property int clearHeight - property int internalSeparatorPos: -1 + readonly property int internalSeparatorPos: parabolicManager.internalSeparatorPos property int newLocationDebugUse: PlasmaCore.Types.BottomPositioned property int newDroppedPosition: -1 property int noInitCreatedBuffers: 0 @@ -497,10 +497,9 @@ Item { break; } } - root.hasInternalSeparator = hasSep; if (!hasSep) - root.internalSeparatorPos = -1; + parabolicManager.internalSeparatorPos = -1; } onGroupingAppIdBlacklistChanged: { @@ -653,6 +652,10 @@ Item { active: root.indicateAudioStreams } + ParabolicManager{ + id: parabolicManager + } + /* IconsModel{ id: iconsmdl }*/ @@ -1163,7 +1166,7 @@ Item { var tasks = icList.contentItem.children; //! this is used to bypass the internal separator if it exists - var confirmedIndex = root.hasInternalSeparator && (index>=root.internalSeparatorPos) ? index+1 : index; + var confirmedIndex = parabolicManager.hasInternalSeparator && (index>=parabolicManager.internalSeparatorPos) ? index+1 : index; for(var i=0; i=root.internalSeparatorPos) ? index+1 : index; + var confirmedIndex = parabolicManager.hasInternalSeparator && (index>=parabolicManager.internalSeparatorPos) ? index+1 : index; for(var i=0; i=0){ isSeparator = true; - root.internalSeparatorPos = index; + parabolicManager.internalSeparatorPos = index; } else { isSeparator = false; } @@ -271,7 +271,8 @@ MouseArea{ visible: (index === 0) || (separatorSpace > 0) //in case there is a neighbour separator - property int separatorSpace: (root.hasInternalSeparator && root.internalSeparatorPos === index-1) ? + property int separatorSpace: (parabolicManager.hasInternalSeparator + && parabolicManager.internalSeparatorPos === index-1) ? (2+root.iconMargin/2) : 0 property real nHiddenSize: (nScale > 0) ? (mainItemContainer.spacersMaxSize * nScale) + separatorSpace : separatorSpace @@ -310,7 +311,8 @@ MouseArea{ visible: (index === icList.count - 1) || (separatorSpace > 0) //in case there is a neighbour separator - property int separatorSpace: (root.hasInternalSeparator && root.internalSeparatorPos === index+1) ? + property int separatorSpace: (parabolicManager.hasInternalSeparator + && parabolicManager.internalSeparatorPos === index+1) ? (2+root.iconMargin/2) : 0 property real nHiddenSize: (nScale > 0) ? (mainItemContainer.spacersMaxSize * nScale) + separatorSpace : separatorSpace @@ -394,7 +396,7 @@ MouseArea{ lastValidTimer.start(); if (isSeparator){ - root.internalSeparatorPos = itemIndex; + parabolicManager.internalSeparatorPos = itemIndex; } } diff --git a/plasmoid/package/contents/ui/task/TaskIconItem.qml b/plasmoid/package/contents/ui/task/TaskIconItem.qml index 532d78008..250adc3b4 100644 --- a/plasmoid/package/contents/ui/task/TaskIconItem.qml +++ b/plasmoid/package/contents/ui/task/TaskIconItem.qml @@ -666,8 +666,7 @@ Item{ if(!running){ var halfZoom = 1 + ((root.zoomFactor - 1) / 2); - wrapper.updateIdSendScale(index-1, halfZoom, 0); - wrapper.updateIdSendScale(index+1, halfZoom, 0); + wrapper.calculateScales((root.iconSize+root.iconMargin)/2); mainItemContainer.animationEnded(); // root.animations--; diff --git a/plasmoid/package/contents/ui/task/TaskWrapper.qml b/plasmoid/package/contents/ui/task/TaskWrapper.qml index 3e893a31d..02c91f11d 100644 --- a/plasmoid/package/contents/ui/task/TaskWrapper.qml +++ b/plasmoid/package/contents/ui/task/TaskWrapper.qml @@ -140,23 +140,6 @@ Item{ }//Flow - //!this is used in order to update the index when the signal is for applets - //!outside the latte plasmoid - function updateIdSendScale(indx, zScale, zStep){ - if ((indx>=0 && indx<=root.tasksCount-1) || (!root.latteDock)){ - root.updateScale(indx, zScale, zStep); - } else{ - var appletId = latteDock.latteAppletPos; - if (indx<0) - appletId = latteDock.latteAppletPos + indx; - else if (indx>root.tasksCount-1){ - var step=indx-root.tasksCount+1; - appletId = latteDock.latteAppletPos + step; - } - - latteDock.updateScale(appletId, zScale, zStep); - } - } function calculateScales( currentMousePosition ){ if (root.editMode || root.zoomFactor===1 || root.durationTime===0) { @@ -171,79 +154,17 @@ Item{ (currentMousePosition > 0)&& (root.dragSource == null) ){ - var rDistance = Math.abs(currentMousePosition - center); - - //check if the mouse goes right or down according to the center - var positiveDirection = ((currentMousePosition - center) >= 0 ); - - var minimumZoom = 1; - - if(mainItemContainer.isSeparator){ - //minimumZoom for separator item - var tempZoomDifference = (root.missingSeparatorLength / (root.maxSeparatorLength+root.missingSeparatorLength)) * root.zoomFactor; - minimumZoom = Math.max(tempZoomDifference, 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); - - if(!root.hasInternalSeparator || Math.abs(index-root.internalSeparatorPos)>=2 - || mainItemContainer.isSeparator){ - //activate messages to update the the neighbour scales - updateIdSendScale(index+1, rightScale, 0); - updateIdSendScale(index-1, leftScale, 0); - - updateIdSendScale(index+2, 1, 0); - updateIdSendScale(index-2, 1, 0); - } else if(root.internalSeparatorPos>=0) { - if(root.internalSeparatorPos === index+1){ - updateIdSendScale(index+2, rightScale, 0); - updateIdSendScale(index-1, leftScale, 0); - - - updateIdSendScale(index+3, 1, 0); - updateIdSendScale(index-2, 1, 0); - } else if(root.internalSeparatorPos === index-1) { - updateIdSendScale(index-2, leftScale, 0); - updateIdSendScale(index+1, rightScale, 0); - - updateIdSendScale(index+2, 1, 0); - updateIdSendScale(index-3, 1, 0); - } - } + //use the new parabolicManager in order to handle all parabolic effect messages + var scales = parabolicManager.applyParabolicEffect(index, currentMousePosition, center); //Left hiddenSpacer if(((index === 0 )&&(icList.count > 1)) && !root.disableLeftSpacer){ - hiddenSpacerLeft.nScale = leftScale - 1; + hiddenSpacerLeft.nScale = scales.leftScale - 1; } //Right hiddenSpacer if(((index === icList.count - 1 )&&(icList.count>1)) && (!root.disableRightSpacer)){ - hiddenSpacerRight.nScale = rightScale - 1; + hiddenSpacerRight.nScale = scales.rightScale - 1; } mScale = root.zoomFactor;