1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-25 19:21:41 +03:00

appletItem:provide its own Parabolic Area

--move the parabolic effect code in its own item
and thus making it a lot cleaner to maintain and
debug
This commit is contained in:
Michail Vourlakos 2020-12-27 21:45:01 +02:00
parent 345d2823f6
commit 751a4f6713
10 changed files with 255 additions and 206 deletions

View File

@ -32,4 +32,6 @@ Ability.ParabolicEffectPrivate {
factor.maxZoom: Math.max(factor.zoom, animations.requirements.zoomFactor)
restoreZoomIsBlocked: (view && view.contextMenuIsShown)
|| (applets.parabolic.restoreZoomIsBlocked)
currentParabolicItem: view ? view.currentParabolicItem : null
}

View File

@ -89,6 +89,10 @@ AbilityHost.ParabolicEffect {
_privates.directRenderingEnabled = value;
}
function setCurrentParabolicItem(item) {
parabolic.view.currentParabolicItem = item;
}
function applyParabolicEffect(index, currentMousePosition, center) {
if (parabolic._privates.lastIndex === -1) {
setDirectRenderingEnabled(false);

View File

@ -48,10 +48,6 @@ Item {
signal mousePressed(int x, int y, int button);
signal mouseReleased(int x, int y, int button);
signal parabolicEntered(int mouseX, int mouseY);
signal parabolicMove(int mouseX, int mouseY);
signal parabolicExited();
property bool animationsEnabled: true
property bool parabolicEffectIsSupported: true
property bool canShowAppletNumberBadge: !isSeparator && !isHidden && !isLattePlasmoid
@ -297,17 +293,19 @@ Item {
readonly property alias communicator: _communicator
readonly property alias wrapper: _wrapper
readonly property alias restoreAnimation: _restoreAnimation
property Item animations: null
property Item debug: null
property Item indexer: null
property Item layouter: null
property Item layouts: null
property Item metrics: null
property Item parabolic: null
property Item shortcuts: null
property Item userRequests: null
property bool containsMouse: (latteView && latteView.currentParabolicItem === appletItem) || (isLattePlasmoid && latteApplet.containsMouse)
property bool containsMouse: parabolicArea.containsMouse || (isLattePlasmoid && latteApplet.containsMouse)
property bool pressed: viewSignalsConnector.pressed || clickedAnimation.running
@ -729,12 +727,6 @@ Item {
}
}
}
onCurrentParabolicItemChanged: {
if (latteView && latteView.currentParabolicItem !== appletItem) {
appletItem.parabolicExited();
}
}
}
Connections {
@ -941,6 +933,11 @@ Item {
height: width
}
ParabolicArea {
id: parabolicArea
anchors.fill: parent
}
Loader {
id: addingAreaLoader
width: root.isHorizontal ? parent.width : parent.width - appletItem.metrics.margin.screenEdge
@ -1027,95 +1024,6 @@ Item {
]
}
MouseArea {
id: parabolicMouseArea
anchors.fill: parent
enabled: visible
hoverEnabled: true
visible: parabolicEffectIsSupported && latteView && latteView.currentParabolicItem !== appletItem
onEntered: {
appletItem.parabolicEntered(mouseX, mouseY);
if (latteView) {
latteView.currentParabolicItem = appletItem;
}
}
}
onParabolicEntered: {
appletItem.parabolic.stopRestoreZoomTimer();
if (restoreAnimation.running) {
restoreAnimation.stop();
}
if (!(isSeparator || isSpacer)) {
root.showTooltipLabel(appletItem, applet.title);
}
if (originalAppletBehavior || communicator.requires.parabolicEffectLocked || !parabolicEffectIsSupported) {
return;
}
if (root.isHalfShown || (root.latteApplet
&& (root.latteApplet.noTasksInAnimation>0 || root.latteApplet.contextMenu))) {
return;
}
if (root.isHorizontal){
layoutsContainer.currentSpot = mouseX;
wrapper.calculateParabolicScales(mouseX);
}
else{
layoutsContainer.currentSpot = mouseY;
wrapper.calculateParabolicScales(mouseY);
}
}
onParabolicMove: {
if (root.isHalfShown || (root.latteApplet
&& (root.latteApplet.noTasksInAnimation>0 || root.latteApplet.contextMenu))) {
return;
}
var rapidMovement = appletItem.parabolic.lastIndex>=0 && Math.abs(appletItem.parabolic.lastIndex-index)>1;
if (rapidMovement) {
parabolic.setDirectRenderingEnabled(true);
}
if( ((wrapper.zoomScale == 1 || wrapper.zoomScale === appletItem.parabolic.factor.zoom) && !parabolic.directRenderingEnabled) || parabolic.directRenderingEnabled) {
if (root.isHorizontal){
var step = Math.abs(layoutsContainer.currentSpot-mouseX);
if (step >= appletItem.animations.hoverPixelSensitivity){
layoutsContainer.currentSpot = mouseX;
wrapper.calculateParabolicScales(mouseX);
}
}
else{
var step = Math.abs(layoutsContainer.currentSpot-mouseY);
if (step >= appletItem.animations.hoverPixelSensitivity){
layoutsContainer.currentSpot = mouseY;
wrapper.calculateParabolicScales(mouseY);
}
}
}
}
onParabolicExited: {
if (communicator.appletIconItemIsShown()) {
communicator.setAppletIconItemActive(false);
}
root.hideTooltipLabel();
/* if (appletItem.parabolic.factor.zoom>1){
appletItem.parabolic.startRestoreZoomTimer();
} */
}
//! Debug Elements
Loader{
anchors.bottom: parent.bottom
@ -1191,7 +1099,7 @@ Item {
//BEGIN animations
///////Restore Zoom Animation/////
ParallelAnimation{
id: restoreAnimation
id: _restoreAnimation
PropertyAnimation {
target: wrapper

View File

@ -109,10 +109,6 @@ Item{
property int layoutLength: 0
property int layoutThickness: 0
property real center:root.isHorizontal ?
(width + hiddenSpacerLeft.separatorSpace + hiddenSpacerRight.separatorSpace) / 2 :
(height + hiddenSpacerLeft.separatorSpace + hiddenSpacerRight.separatorSpace) / 2
property real zoomScale: 1
property int index: appletItem.index
@ -619,105 +615,4 @@ Item{
enabled: !animatedScaleBehavior.enabled
NumberAnimation { duration: 0 }
}
function calculateParabolicScales( currentMousePosition ){
if (parabolic.factor.zoom===1 || parabolic.restoreZoomIsBlocked) {
return;
}
//use the new parabolic effect manager in order to handle all parabolic effect messages
var scales = parabolic.applyParabolicEffect(index, currentMousePosition, center);
//Left hiddenSpacer
if(appletItem.firstAppletInContainer){
hiddenSpacerLeft.nScale = scales.leftScale - 1;
}
//Right hiddenSpacer ///there is one more item in the currentLayout ????
if(appletItem.lastAppletInContainer){
hiddenSpacerRight.nScale = scales.rightScale - 1;
}
zoomScale = parabolic.factor.zoom;
} //scale
function updateScale(nIndex, nScale, step){
if(appletItem && !appletItem.containsMouse && (appletItem.index === nIndex)){
if ( ((parabolicEffectIsSupported && !appletItem.originalAppletBehavior) || appletItem.latteApplet)
&& (applet && applet.status !== PlasmaCore.Types.HiddenStatus)
){
if(!appletItem.latteApplet){
if(nScale >= 0)
zoomScale = nScale + step;
else
zoomScale = zoomScale + step;
}
}
}
}
function sltUpdateLowerItemScale(delegateIndex, newScale, step) {
if (delegateIndex === appletItem.index) {
if (communicator.parabolicEffectIsSupported) {
communicator.bridge.parabolic.client.hostRequestUpdateLowerItemScale(newScale, step);
return;
}
if (!appletItem.isSeparator && !appletItem.isHidden) {
//! when accepted
updateScale(delegateIndex, newScale, step);
if (newScale > 1) { // clear lower items
parabolic.sglUpdateLowerItemScale(delegateIndex-1, 1, 0);
}
} else {
parabolic.sglUpdateLowerItemScale(delegateIndex-1, newScale, step);
}
} else if ((newScale === 1) && (appletItem.index < delegateIndex)) {
//! apply zoom clearing
if (communicator.parabolicEffectIsSupported) {
communicator.bridge.parabolic.client.hostRequestUpdateLowerItemScale(1, step);
} else {
updateScale(appletItem.index, 1, 0);
}
}
}
function sltUpdateHigherItemScale(delegateIndex, newScale, step) {
if (delegateIndex === appletItem.index) {
if (communicator.parabolicEffectIsSupported) {
communicator.bridge.parabolic.client.hostRequestUpdateHigherItemScale(newScale, step);
return;
}
if (!appletItem.isSeparator && !appletItem.isHidden) {
//! when accepted
updateScale(delegateIndex, newScale, step);
if (newScale > 1) { // clear higher items
parabolic.sglUpdateHigherItemScale(delegateIndex+1, 1, 0);
}
} else {
parabolic.sglUpdateHigherItemScale(delegateIndex+1, newScale, step);
}
} else if ((newScale === 1) && (appletItem.index > delegateIndex)) {
//! apply zoom clearing
if (communicator.parabolicEffectIsSupported) {
communicator.bridge.parabolic.client.hostRequestUpdateHigherItemScale(1, step);
} else {
updateScale(appletItem.index, 1, 0);
}
}
}
Component.onCompleted: {
parabolic.sglUpdateLowerItemScale.connect(sltUpdateLowerItemScale);
parabolic.sglUpdateHigherItemScale.connect(sltUpdateHigherItemScale);
}
Component.onDestruction: {
parabolic.sglUpdateLowerItemScale.disconnect(sltUpdateLowerItemScale);
parabolic.sglUpdateHigherItemScale.disconnect(sltUpdateHigherItemScale);
}
}// Main task area // id:wrapper

View File

@ -0,0 +1,227 @@
/*
* Copyright 2020 Michail Vourlakos <mvourlakos@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.7
import org.kde.plasma.core 2.0 as PlasmaCore
Item {
id: _parabolicArea
signal parabolicEntered(int mouseX, int mouseY);
signal parabolicMove(int mouseX, int mouseY);
signal parabolicExited();
readonly property bool containsMouse: appletItem.parabolic.currentParabolicItem === _parabolicArea
property real center:root.isHorizontal ?
(wrapper.width + hiddenSpacerLeft.separatorSpace + hiddenSpacerRight.separatorSpace) / 2 :
(wrapper.height + hiddenSpacerLeft.separatorSpace + hiddenSpacerRight.separatorSpace) / 2
MouseArea {
id: parabolicMouseArea
anchors.fill: parent
enabled: visible
hoverEnabled: true
visible: appletItem.parabolicEffectIsSupported && appletItem.parabolic.currentParabolicItem !== _parabolicArea
onEntered: {
_parabolicArea.parabolicEntered(mouseX, mouseY);
appletItem.parabolic.setCurrentParabolicItem(_parabolicArea);
}
}
Connections {
target: appletItem.parabolic
onCurrentParabolicItemChanged: {
if (appletItem.parabolic.currentParabolicItem !== _parabolicArea) {
_parabolicArea.parabolicExited();
}
}
}
onParabolicEntered: {
appletItem.parabolic.stopRestoreZoomTimer();
if (restoreAnimation.running) {
restoreAnimation.stop();
}
if (!(isSeparator || isSpacer)) {
root.showTooltipLabel(appletItem, applet.title);
}
if (appletItem.originalAppletBehavior || communicator.requires.parabolicEffectLocked || !parabolicEffectIsSupported) {
return;
}
if (root.isHalfShown || (root.latteApplet
&& (root.latteApplet.noTasksInAnimation>0 || root.latteApplet.contextMenu))) {
return;
}
if (root.isHorizontal){
appletItem.layouts.currentSpot = mouseX;
calculateParabolicScales(mouseX);
}
else{
appletItem.layouts.currentSpot = mouseY;
calculateParabolicScales(mouseY);
}
}
onParabolicMove: {
console.log(mouseX + " __ " + mouseY);
if (root.isHalfShown || (root.latteApplet
&& (root.latteApplet.noTasksInAnimation>0 || root.latteApplet.contextMenu))) {
return;
}
var rapidMovement = appletItem.parabolic.lastIndex>=0 && Math.abs(appletItem.parabolic.lastIndex-index)>1;
if (rapidMovement) {
parabolic.setDirectRenderingEnabled(true);
}
if( ((wrapper.zoomScale === 1 || wrapper.zoomScale === appletItem.parabolic.factor.zoom) && !parabolic.directRenderingEnabled) || parabolic.directRenderingEnabled) {
if (root.isHorizontal){
var step = Math.abs(appletItem.layouts.currentSpot-mouseX);
if (step >= appletItem.animations.hoverPixelSensitivity){
appletItem.layouts.currentSpot = mouseX;
calculateParabolicScales(mouseX);
}
}
else{
var step = Math.abs(appletItem.layouts.currentSpot-mouseY);
if (step >= appletItem.animations.hoverPixelSensitivity){
appletItem.layouts.currentSpot = mouseY;
calculateParabolicScales(mouseY);
}
}
}
}
onParabolicExited: {
if (communicator.appletIconItemIsShown()) {
communicator.setAppletIconItemActive(false);
}
root.hideTooltipLabel();
}
function calculateParabolicScales(currentMousePosition){
if (parabolic.factor.zoom===1 || parabolic.restoreZoomIsBlocked) {
return;
}
//use the new parabolic effect manager in order to handle all parabolic effect messages
var scales = parabolic.applyParabolicEffect(index, currentMousePosition, center);
//Left hiddenSpacer
if(appletItem.firstAppletInContainer){
hiddenSpacerLeft.nScale = scales.leftScale - 1;
}
//Right hiddenSpacer ///there is one more item in the currentLayout ????
if(appletItem.lastAppletInContainer){
hiddenSpacerRight.nScale = scales.rightScale - 1;
}
wrapper.zoomScale = parabolic.factor.zoom;
} //scale
function updateScale(nIndex, nScale, step){
if(appletItem && !appletItem.containsMouse && (appletItem.index === nIndex)){
if ( ((parabolicEffectIsSupported && !appletItem.originalAppletBehavior) || appletItem.latteApplet)
&& (applet && applet.status !== PlasmaCore.Types.HiddenStatus)){
if(!appletItem.latteApplet){
if(nScale >= 0) {
wrapper.zoomScale = nScale + step;
} else {
wrapper.zoomScale = wrapper.zoomScale + step;
}
}
}
}
}
function sltUpdateLowerItemScale(delegateIndex, newScale, step) {
if (delegateIndex === appletItem.index) {
if (communicator.parabolicEffectIsSupported) {
communicator.bridge.parabolic.client.hostRequestUpdateLowerItemScale(newScale, step);
return;
}
if (!appletItem.isSeparator && !appletItem.isHidden) {
//! when accepted
updateScale(delegateIndex, newScale, step);
if (newScale > 1) { // clear lower items
parabolic.sglUpdateLowerItemScale(delegateIndex-1, 1, 0);
}
} else {
parabolic.sglUpdateLowerItemScale(delegateIndex-1, newScale, step);
}
} else if ((newScale === 1) && (appletItem.index < delegateIndex)) {
//! apply zoom clearing
if (communicator.parabolicEffectIsSupported) {
communicator.bridge.parabolic.client.hostRequestUpdateLowerItemScale(1, step);
} else {
updateScale(appletItem.index, 1, 0);
}
}
}
function sltUpdateHigherItemScale(delegateIndex, newScale, step) {
if (delegateIndex === appletItem.index) {
if (communicator.parabolicEffectIsSupported) {
communicator.bridge.parabolic.client.hostRequestUpdateHigherItemScale(newScale, step);
return;
}
if (!appletItem.isSeparator && !appletItem.isHidden) {
//! when accepted
updateScale(delegateIndex, newScale, step);
if (newScale > 1) { // clear higher items
parabolic.sglUpdateHigherItemScale(delegateIndex+1, 1, 0);
}
} else {
parabolic.sglUpdateHigherItemScale(delegateIndex+1, newScale, step);
}
} else if ((newScale === 1) && (appletItem.index > delegateIndex)) {
//! apply zoom clearing
if (communicator.parabolicEffectIsSupported) {
communicator.bridge.parabolic.client.hostRequestUpdateHigherItemScale(1, step);
} else {
updateScale(appletItem.index, 1, 0);
}
}
}
Component.onCompleted: {
parabolic.sglUpdateLowerItemScale.connect(sltUpdateLowerItemScale);
parabolic.sglUpdateHigherItemScale.connect(sltUpdateHigherItemScale);
}
Component.onDestruction: {
parabolic.sglUpdateLowerItemScale.disconnect(sltUpdateLowerItemScale);
parabolic.sglUpdateHigherItemScale.disconnect(sltUpdateHigherItemScale);
}
}

View File

@ -1245,6 +1245,7 @@ Item {
debug: _debug
indexer: _indexer
layouter: _layouter
layouts: layoutsContainer
metrics: _metrics
parabolic: _parabolic
shortcuts: _shortcuts

View File

@ -29,6 +29,7 @@ AbilityDefinition.ParabolicEffect {
isEnabled: ref.parabolic.isEnabled
factor: ref.parabolic.factor
restoreZoomIsBlocked: bridge ? (bridge.parabolic.host.restoreZoomIsBlocked || local.restoreZoomIsBlocked) : local.restoreZoomIsBlocked
currentParabolicItem: ref.parabolic.currentParabolicItem
//! private properties can not go to definition because can not be made readonly in there
//! special care must be taken in order to be redefined in local properties

View File

@ -35,6 +35,8 @@ Item {
lastIndex: -1
}
property Item currentParabolicItem: null
signal sglClearZoom();
signal sglUpdateLowerItemScale(int delegateIndex, real newScale, real step);
signal sglUpdateHigherItemScale(int delegateIndex, real newScale, real step);

View File

@ -35,6 +35,7 @@ AbilityDefinition.ParabolicEffect {
readonly property alias factor: apis.factor
readonly property alias lastIndex: apis.lastIndex
readonly property alias restoreZoomIsBlocked: apis.restoreZoomIsBlocked
readonly property alias currentParabolicItem: apis.currentParabolicItem
signal sglClearZoom();

View File

@ -88,6 +88,14 @@ ClientAbility.ParabolicEffect {
}
}
function setCurrentParabolicItem(item) {
if (bridge) {
bridge.parabolic.host.setCurrentParabolicItem(item);
} else {
local._privates.currentParabolicItem = item;
}
}
function hostRequestUpdateLowerItemScale(newScale, step){
//! function called from host
sglUpdateLowerItemScale(itemsCount-1, newScale, step);