From f0f7c69be68809b9de5f8ba625d5051503d3eb1a Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 8 Feb 2018 19:54:32 +0100 Subject: [PATCH 1/9] very early prototype of gesture activity switching idea is to slide activities with an horizontal swipe --- shell/contents/loader.qml | 2 +- shell/contents/views/ActivityHandle.qml | 1 + shell/contents/views/Desktop.qml | 65 +++++++++++++++++-------- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/shell/contents/loader.qml b/shell/contents/loader.qml index 9d8fac80..79e34f63 100644 --- a/shell/contents/loader.qml +++ b/shell/contents/loader.qml @@ -25,7 +25,7 @@ Item { property string shell : "org.kde.plasma.phone" property bool willing : true - property int priority : currentSession == "plasma-mobile" ? 0 : 10 + property int priority : 10 // This is not needed, but allows the // handler to know whether its shell is loaded diff --git a/shell/contents/views/ActivityHandle.qml b/shell/contents/views/ActivityHandle.qml index 6c29daca..b32fd8c3 100644 --- a/shell/contents/views/ActivityHandle.qml +++ b/shell/contents/views/ActivityHandle.qml @@ -33,6 +33,7 @@ MouseArea { right: handle.mirrored ? parent.right : undefined left: handle.mirrored ? undefined : parent.left } + property Item frame: nextActivityLabel width: units.gridUnit drag.target: nextActivityLabel drag.axis: Drag.XAxis diff --git a/shell/contents/views/Desktop.qml b/shell/contents/views/Desktop.qml index bd77d72a..a2bed670 100644 --- a/shell/contents/views/Desktop.qml +++ b/shell/contents/views/Desktop.qml @@ -20,6 +20,7 @@ import QtQuick 2.6 import QtGraphicalEffects 1.0 +import QtQuick.Controls 2.3 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.shell 2.0 as Shell import org.kde.plasma.components 2.0 as PlasmaComponents @@ -28,18 +29,20 @@ import org.kde.kquickcontrolsaddons 2.0 import org.kde.activities 0.1 as Activities import "../components" -Item { +MouseArea { id: root width: 1080 height: 1920 property Item containment; + property Item containmentNextActivityPreview; property Item wallpaper; property int notificationId: 0; property int buttonHeight: width/4 property bool containmentsEnterFromRight: true + drag.filterChildren: true - //NOTE: this + //HACK: needs better api from kactivities qml PathView { id: activitiesRepresentation model: Activities.ActivityModel { @@ -59,7 +62,36 @@ Item { } } } - + PageIndicator { + z: 999 + anchors { + bottom: parent.bottom + horizontalCenter: parent.horizontalCenter + } + count: activitiesRepresentation.count + currentIndex: activitiesRepresentation.currentIndex + } + property int startX + onPressed: { + startX = mouse.x - containment.x + } + onPositionChanged: { + containment.x = mouse.x - startX + if (containment.x < 0) { + var cont = desktop.containmentItemForActivity("395250d4-d44b-4735-8494-4db49beb29dd"); + if (cont != containmentNextActivityPreview) { + print(cont+" "+root.containment); + containmentNextActivityPreview = cont; + cont.width = root.width; + cont.height = root.height; + cont.parent = root; + } + containmentNextActivityPreview.x = containment.x + containment.width; + } + } + onReleased: { + activityModel.setCurrentActivity("395250d4-d44b-4735-8494-4db49beb29dd", function(){}); + } ActivityHandle { mirrored: true } @@ -113,9 +145,9 @@ Item { if (internal.oldContainment != null && internal.oldContainment != containment) { switchAnim.running = true; } else { - containment.anchors.left = root.left; + //containment.anchors.left = root.left; containment.anchors.top = root.top; - containment.anchors.right = root.right; + //containment.anchors.right = root.right; containment.anchors.bottom = root.bottom; if (internal.oldContainment) { internal.oldContainment.visible = false; @@ -124,6 +156,11 @@ Item { } } + Binding { + target: containment + property: "width" + value: root.width + } //some properties that shouldn't be accessible from elsewhere QtObject { id: internal; @@ -137,20 +174,12 @@ Item { ScriptAction { script: { if (containment) { - containment.anchors.left = undefined; - containment.anchors.top = undefined; - containment.anchors.right = undefined; - containment.anchors.bottom = undefined; - containment.z = 1; - containment.x = root.containmentsEnterFromRight ? root.width : -root.width; + //containment.z = 1; + //containment.x = root.containmentsEnterFromRight ? root.width : -root.width; } if (internal.oldContainment) { - internal.oldContainment.anchors.left = undefined; - internal.oldContainment.anchors.top = undefined; - internal.oldContainment.anchors.right = undefined; - internal.oldContainment.anchors.bottom = undefined; - internal.oldContainment.z = 0; - internal.oldContainment.x = 0; + //internal.oldContainment.z = 0; + //internal.oldContainment.x = 0; } } } @@ -176,9 +205,7 @@ Item { internal.oldContainment.visible = false; } if (containment) { - containment.anchors.left = root.left; containment.anchors.top = root.top; - containment.anchors.right = root.right; containment.anchors.bottom = root.bottom; internal.oldContainment = containment; } From 5e1e5e9009dc093d99227e1c28f282d55f2a6bae Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 9 Feb 2018 13:04:48 +0100 Subject: [PATCH 2/9] prototype with a ListView still doesn't change activities correctly, seems to be too eager to load all containments at start --- shell/contents/views/Desktop.qml | 62 +++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/shell/contents/views/Desktop.qml b/shell/contents/views/Desktop.qml index a2bed670..df215155 100644 --- a/shell/contents/views/Desktop.qml +++ b/shell/contents/views/Desktop.qml @@ -40,7 +40,7 @@ MouseArea { property int notificationId: 0; property int buttonHeight: width/4 property bool containmentsEnterFromRight: true - drag.filterChildren: true + drag.filterChildren: false //HACK: needs better api from kactivities qml PathView { @@ -62,16 +62,60 @@ MouseArea { } } } + ListView { + id: mainView + z: 998 + visible: root.containment + interactive: true + anchors.fill: parent + orientation: ListView.Horizontal + snapMode: ListView.SnapOneItem + boundsBehavior: Flickable.StopAtBounds + cacheBuffer: width * count * 2 + model: Activities.ActivityModel { + id: activityModel2 + } + + delegate: Rectangle { + radius: 100 + id: mainDelegate + width: mainView.width + height: mainView.height + property bool inViewport: root.containment && mainView.contentX <= x && mainView.contentX+mainView.width <= x + width + property bool current: containment == root.containment + property Item containment + onCurrentChanged: { + if (current) { + mainView.currentIndex = index + } + } + onInViewportChanged: { + if (inViewport && !mainDelegate.containment) { + mainDelegate.containment = desktop.containmentItemForActivity(model.id); + print(mainDelegate.containment+" "+root.containment); + containmentNextActivityPreview = containment; + mainDelegate.containment.parent = mainDelegate; + mainDelegate.containment.anchors.fill = mainDelegate; + } + } + + Text { + x: -100 + z: 100 + text: mainDelegate.inViewport + " " + mainView.contentX +" "+ mainDelegate.x +" "+ (mainView.contentX + mainView.width) + " " + (mainDelegate.x + mainDelegate.width) + } + } + } PageIndicator { z: 999 anchors { bottom: parent.bottom horizontalCenter: parent.horizontalCenter } - count: activitiesRepresentation.count - currentIndex: activitiesRepresentation.currentIndex + count: mainView.count + currentIndex: mainView.currentIndex } - property int startX + /* property int startX onPressed: { startX = mouse.x - containment.x } @@ -91,7 +135,7 @@ MouseArea { } onReleased: { activityModel.setCurrentActivity("395250d4-d44b-4735-8494-4db49beb29dd", function(){}); - } + }*/ ActivityHandle { mirrored: true } @@ -124,7 +168,7 @@ MouseArea { } } } - +/* onContainmentChanged: { if (containment == null) { return; @@ -155,7 +199,7 @@ MouseArea { internal.oldContainment = containment; } } - +*/ Binding { target: containment property: "width" @@ -168,7 +212,7 @@ MouseArea { property Item oldContainment: null; property Item newContainment: null; } - +/* SequentialAnimation { id: switchAnim ScriptAction { @@ -212,7 +256,7 @@ MouseArea { } } } - +*/ //pass the focus to the containment, so it can react to homescreen activate/inactivate Connections { target: desktop From 89fef3ed7ba2dba59fa0f314f904c1c6bfd47c28 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 9 Feb 2018 18:20:43 +0100 Subject: [PATCH 3/9] almost functional even if hacky swipe activity switcher --- shell/contents/views/Desktop.qml | 70 +++++++++++++++++--------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/shell/contents/views/Desktop.qml b/shell/contents/views/Desktop.qml index df215155..9c0664b3 100644 --- a/shell/contents/views/Desktop.qml +++ b/shell/contents/views/Desktop.qml @@ -42,28 +42,15 @@ MouseArea { property bool containmentsEnterFromRight: true drag.filterChildren: false - //HACK: needs better api from kactivities qml - PathView { - id: activitiesRepresentation - model: Activities.ActivityModel { - id: activityModel - } - width: 10 - height: 10 - cacheItemCount: 999//count - delegate: Item { - Connections { - target: activitiesRepresentation - onCurrentIndexChanged: { - if (index == activitiesRepresentation.currentIndex) { - activityModel.setCurrentActivity(model.id, function(){}); - } - } - } - } + //HACK FIXME this timer hack is to wait activitiesView finished all its setup + //which we can't know for sure and suggests that we can't really use it + Timer { + id: hackTimer + interval: 1000 + running: true } ListView { - id: mainView + id: activitiesView z: 998 visible: root.containment interactive: true @@ -71,23 +58,37 @@ MouseArea { orientation: ListView.Horizontal snapMode: ListView.SnapOneItem boundsBehavior: Flickable.StopAtBounds + highlightMoveDuration: 0 + highlightRangeMode: ListView.StrictlyEnforceRange cacheBuffer: width * count * 2 model: Activities.ActivityModel { - id: activityModel2 + id: activityModel } delegate: Rectangle { radius: 100 id: mainDelegate - width: mainView.width - height: mainView.height - property bool inViewport: root.containment && mainView.contentX <= x && mainView.contentX+mainView.width <= x + width - property bool current: containment == root.containment + width: activitiesView.width + height: activitiesView.height property Item containment - onCurrentChanged: { - if (current) { - mainView.currentIndex = index + readonly property bool inViewport: !hackTimer.running && root.containment && + ((x >= activitiesView.contentX && + x < activitiesView.contentX + activitiesView.width) || + (x + width > activitiesView.contentX && + x + width < activitiesView.contentX + activitiesView.width)) + readonly property bool currentActivity: root.containment && model.current + + + Connections { + target: activitiesView + onMovementEnded: {return; + if (activitiesView.currentIndex == index) { + activityModel.setCurrentActivity(model.id, function(){ + mainDelegate.containment.parent = mainDelegate; + }); + } } + onFlickEnded: onMovementEnded() } onInViewportChanged: { if (inViewport && !mainDelegate.containment) { @@ -98,11 +99,16 @@ MouseArea { mainDelegate.containment.anchors.fill = mainDelegate; } } + onCurrentActivityChanged: { + if (currentActivity) { + activitiesView.positionViewAtIndex(index, ListView.Beginning); + activitiesView.currentIndex = index; + } + } Text { - x: -100 z: 100 - text: mainDelegate.inViewport + " " + mainView.contentX +" "+ mainDelegate.x +" "+ (mainView.contentX + mainView.width) + " " + (mainDelegate.x + mainDelegate.width) + text: mainDelegate.inViewport + " " + activitiesView.contentX +" "+ mainDelegate.x +" "+ (activitiesView.contentX + activitiesView.width) + " " + (mainDelegate.x + mainDelegate.width) } } } @@ -112,8 +118,8 @@ MouseArea { bottom: parent.bottom horizontalCenter: parent.horizontalCenter } - count: mainView.count - currentIndex: mainView.currentIndex + count: activitiesView.count + currentIndex: activitiesView.currentIndex } /* property int startX onPressed: { From fa8bec3fd8f89ee4e8b6dc8620c516927ef3c34a Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 9 Feb 2018 18:26:57 +0100 Subject: [PATCH 4/9] actually fix activity switching --- shell/contents/views/Desktop.qml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/shell/contents/views/Desktop.qml b/shell/contents/views/Desktop.qml index 9c0664b3..f8ebb025 100644 --- a/shell/contents/views/Desktop.qml +++ b/shell/contents/views/Desktop.qml @@ -81,14 +81,14 @@ MouseArea { Connections { target: activitiesView - onMovementEnded: {return; + onMovementEnded: { if (activitiesView.currentIndex == index) { activityModel.setCurrentActivity(model.id, function(){ mainDelegate.containment.parent = mainDelegate; }); } } - onFlickEnded: onMovementEnded() + onFlickEnded: activitiesView.movementEnded() } onInViewportChanged: { if (inViewport && !mainDelegate.containment) { @@ -142,12 +142,6 @@ MouseArea { onReleased: { activityModel.setCurrentActivity("395250d4-d44b-4735-8494-4db49beb29dd", function(){}); }*/ - ActivityHandle { - mirrored: true - } - ActivityHandle { - mirrored: false - } function toggleWidgetExplorer(containment) { console.log("Widget Explorer toggled"); From 3f515a3c162edf41ef04612ebfdb7d48ddaadc99 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 13 Feb 2018 14:16:48 +0100 Subject: [PATCH 5/9] get rid of ListView and hackTimer --- shell/contents/views/Desktop.qml | 268 +++++++++++++------------------ 1 file changed, 109 insertions(+), 159 deletions(-) diff --git a/shell/contents/views/Desktop.qml b/shell/contents/views/Desktop.qml index f8ebb025..03407a90 100644 --- a/shell/contents/views/Desktop.qml +++ b/shell/contents/views/Desktop.qml @@ -29,91 +29,126 @@ import org.kde.kquickcontrolsaddons 2.0 import org.kde.activities 0.1 as Activities import "../components" -MouseArea { +Item { id: root - width: 1080 - height: 1920 + width: 0 + height: 0 property Item containment; property Item containmentNextActivityPreview; property Item wallpaper; property int notificationId: 0; property int buttonHeight: width/4 - property bool containmentsEnterFromRight: true - drag.filterChildren: false + property bool loadCompleted: false - //HACK FIXME this timer hack is to wait activitiesView finished all its setup - //which we can't know for sure and suggests that we can't really use it - Timer { - id: hackTimer - interval: 1000 - running: true + SmoothedAnimation { + id: switchAnim + target: activitiesView + properties: "contentX" + to: 0 + //it's a long travel, we want a consistent velocity rather than duration + velocity: width + easing.type: Easing.InOutQuad } - ListView { + Flickable { id: activitiesView - z: 998 + z: 99 visible: root.containment interactive: true anchors.fill: parent - orientation: ListView.Horizontal - snapMode: ListView.SnapOneItem + contentWidth: activitiesLayout.width + contentHeight: height boundsBehavior: Flickable.StopAtBounds - highlightMoveDuration: 0 - highlightRangeMode: ListView.StrictlyEnforceRange - cacheBuffer: width * count * 2 - model: Activities.ActivityModel { - id: activityModel + maximumFlickVelocity: width/5 + property int currentIndex: -1 + + onCurrentIndexChanged: { + if (!activitiesLayout.loadCompleted) { + contentX = currentIndex * width; + return; + } + switchAnim.from = contentX; + switchAnim.to = currentIndex * width; + switchAnim.running = true; } + onFlickEnded: movementEnded(); + onMovementEnded: { + currentIndex = Math.round(contentX / width); + //be sure the animation will work + currentIndexChanged(); + } + //don't animate + onWidthChanged: contentX = currentIndex * width; - delegate: Rectangle { - radius: 100 - id: mainDelegate - width: activitiesView.width + Row { + id: activitiesLayout height: activitiesView.height - property Item containment - readonly property bool inViewport: !hackTimer.running && root.containment && - ((x >= activitiesView.contentX && - x < activitiesView.contentX + activitiesView.width) || - (x + width > activitiesView.contentX && - x + width < activitiesView.contentX + activitiesView.width)) - readonly property bool currentActivity: root.containment && model.current + spacing: 0 + //don't try to do anything until we are well setted up + property bool loadCompleted: root.loadCompleted && width == activitiesView.width * (activitiesLayout.children.length - 1) && activitiesLayout.children.length == activityRepeater.count + 1 + onLoadCompletedChanged: activitiesView.currentIndexChanged(); - - Connections { - target: activitiesView - onMovementEnded: { - if (activitiesView.currentIndex == index) { - activityModel.setCurrentActivity(model.id, function(){ + Repeater { + id: activityRepeater + model: Activities.ActivityModel { + id: activityModel + } + + delegate: Rectangle { + radius: 100 + id: mainDelegate + width: activitiesView.width + height: activitiesView.height + property Item containment + readonly property bool inViewport: activitiesLayout.loadCompleted && root.containment && + ((x >= activitiesView.contentX && + x < activitiesView.contentX + activitiesView.width) || + (x + width > activitiesView.contentX && + x + width < activitiesView.contentX + activitiesView.width)) + readonly property bool currentActivity: root.containment && model.current + + + Connections { + target: activitiesView + onMovementEnded: { + if (activitiesView.currentIndex == index) { + activityModel.setCurrentActivity(model.id, function(){ + mainDelegate.containment.parent = mainDelegate; + }); + } + } + onFlickEnded: activitiesView.movementEnded() + } + onInViewportChanged: { + if (inViewport && !mainDelegate.containment) { + mainDelegate.containment = desktop.containmentItemForActivity(model.id); + containmentNextActivityPreview = containment; mainDelegate.containment.parent = mainDelegate; - }); + mainDelegate.containment.anchors.fill = mainDelegate; + } + } + onCurrentActivityChanged: { + if (currentActivity) { + activitiesView.currentIndex = index; + } + } + + Text { + z: 100 + text: "inViewport: " + mainDelegate.inViewport + + "\n activitiesView.contentX: " + activitiesView.contentX + + "\n mainDelegate.x: "+ mainDelegate.x + + "\n (activitiesView.contentX + activitiesView.width):"+ (activitiesView.contentX + activitiesView.width) + + "\n (mainDelegate.x + mainDelegate.width):" + (mainDelegate.x + mainDelegate.width) } } - onFlickEnded: activitiesView.movementEnded() - } - onInViewportChanged: { - if (inViewport && !mainDelegate.containment) { - mainDelegate.containment = desktop.containmentItemForActivity(model.id); - print(mainDelegate.containment+" "+root.containment); - containmentNextActivityPreview = containment; - mainDelegate.containment.parent = mainDelegate; - mainDelegate.containment.anchors.fill = mainDelegate; - } - } - onCurrentActivityChanged: { - if (currentActivity) { - activitiesView.positionViewAtIndex(index, ListView.Beginning); - activitiesView.currentIndex = index; - } - } - - Text { - z: 100 - text: mainDelegate.inViewport + " " + activitiesView.contentX +" "+ mainDelegate.x +" "+ (activitiesView.contentX + activitiesView.width) + " " + (mainDelegate.x + mainDelegate.width) } } } + + //TODO: adjust its Y to current containment availablescreenrect PageIndicator { - z: 999 + z: 100 anchors { bottom: parent.bottom horizontalCenter: parent.horizontalCenter @@ -121,27 +156,7 @@ MouseArea { count: activitiesView.count currentIndex: activitiesView.currentIndex } - /* property int startX - onPressed: { - startX = mouse.x - containment.x - } - onPositionChanged: { - containment.x = mouse.x - startX - if (containment.x < 0) { - var cont = desktop.containmentItemForActivity("395250d4-d44b-4735-8494-4db49beb29dd"); - if (cont != containmentNextActivityPreview) { - print(cont+" "+root.containment); - containmentNextActivityPreview = cont; - cont.width = root.width; - cont.height = root.height; - cont.parent = root; - } - containmentNextActivityPreview.x = containment.x + containment.width; - } - } - onReleased: { - activityModel.setCurrentActivity("395250d4-d44b-4735-8494-4db49beb29dd", function(){}); - }*/ + function toggleWidgetExplorer(containment) { console.log("Widget Explorer toggled"); @@ -168,38 +183,7 @@ MouseArea { } } } -/* - onContainmentChanged: { - if (containment == null) { - return; - } - if (switchAnim.running) { - //If the animation was still running, stop it and reset - //everything so that a consistent state can be kept - switchAnim.running = false; - internal.newContainment.visible = false; - internal.oldContainment.visible = false; - internal.oldContainment = null; - } - - internal.newContainment = containment; - containment.visible = true; - - if (internal.oldContainment != null && internal.oldContainment != containment) { - switchAnim.running = true; - } else { - //containment.anchors.left = root.left; - containment.anchors.top = root.top; - //containment.anchors.right = root.right; - containment.anchors.bottom = root.bottom; - if (internal.oldContainment) { - internal.oldContainment.visible = false; - } - internal.oldContainment = containment; - } - } -*/ Binding { target: containment property: "width" @@ -212,51 +196,7 @@ MouseArea { property Item oldContainment: null; property Item newContainment: null; } -/* - SequentialAnimation { - id: switchAnim - ScriptAction { - script: { - if (containment) { - //containment.z = 1; - //containment.x = root.containmentsEnterFromRight ? root.width : -root.width; - } - if (internal.oldContainment) { - //internal.oldContainment.z = 0; - //internal.oldContainment.x = 0; - } - } - } - ParallelAnimation { - NumberAnimation { - target: internal.oldContainment - properties: "x" - to: internal.newContainment != null ? (root.containmentsEnterFromRight ? -root.width : root.width) : 0 - duration: 400 - easing.type: Easing.InOutQuad - } - NumberAnimation { - target: internal.newContainment - properties: "x" - to: 0 - duration: units.longDuration - easing.type: Easing.InOutQuad - } - } - ScriptAction { - script: { - if (internal.oldContainment) { - internal.oldContainment.visible = false; - } - if (containment) { - containment.anchors.top = root.top; - containment.anchors.bottom = root.bottom; - internal.oldContainment = containment; - } - } - } - } -*/ + //pass the focus to the containment, so it can react to homescreen activate/inactivate Connections { target: desktop @@ -276,11 +216,21 @@ MouseArea { source: Qt.resolvedUrl("Pin.qml") } - Component.onCompleted: { + onWidthChanged: { + //There will be a resize at the very start which we can't avoid, don't do anything until then //configure the view behavior - if (desktop) { + if (desktop && root.width > 0) { desktop.width = width; desktop.height = height; + root.loadCompleted = true; + } + } + Component.onCompleted: { + //configure the view behavior + if (desktop && root.width > 0) { + desktop.width = width; + desktop.height = height; + root.loadCompleted = true; } } } From 4ab220ed062b5eedefba0fd37958c29d2beebe7f Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 22 Feb 2018 19:26:53 +0100 Subject: [PATCH 6/9] try to replace the flickable with a custom implementation --- shell/contents/views/Desktop.qml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/shell/contents/views/Desktop.qml b/shell/contents/views/Desktop.qml index 03407a90..5a9b0b23 100644 --- a/shell/contents/views/Desktop.qml +++ b/shell/contents/views/Desktop.qml @@ -18,7 +18,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import QtQuick 2.6 +import QtQuick 2.7 import QtGraphicalEffects 1.0 import QtQuick.Controls 2.3 import org.kde.plasma.core 2.0 as PlasmaCore @@ -50,16 +50,16 @@ Item { velocity: width easing.type: Easing.InOutQuad } - Flickable { + MouseArea { id: activitiesView z: 99 visible: root.containment - interactive: true anchors.fill: parent - contentWidth: activitiesLayout.width - contentHeight: height - boundsBehavior: Flickable.StopAtBounds - maximumFlickVelocity: width/5 + drag.filterChildren: true + drag.target: activitiesLayout + drag.axis: Drag.XAxis + drag.minimumX: -activitiesLayout.width + width + drag.maximumX: 0 property int currentIndex: -1 onCurrentIndexChanged: { @@ -71,12 +71,12 @@ Item { switchAnim.to = currentIndex * width; switchAnim.running = true; } - onFlickEnded: movementEnded(); + /* onFlickEnded: movementEnded(); onMovementEnded: { currentIndex = Math.round(contentX / width); //be sure the animation will work currentIndexChanged(); - } + }*/ //don't animate onWidthChanged: contentX = currentIndex * width; @@ -101,10 +101,10 @@ Item { height: activitiesView.height property Item containment readonly property bool inViewport: activitiesLayout.loadCompleted && root.containment && - ((x >= activitiesView.contentX && - x < activitiesView.contentX + activitiesView.width) || - (x + width > activitiesView.contentX && - x + width < activitiesView.contentX + activitiesView.width)) + ((x >= -activitiesLayout.x && + x < -activitiesLayout.x + activitiesView.width) || + (x + width > -activitiesLayout.x && + x + width < -activitiesLayout.x + activitiesView.width)) readonly property bool currentActivity: root.containment && model.current @@ -136,9 +136,9 @@ Item { Text { z: 100 text: "inViewport: " + mainDelegate.inViewport + - "\n activitiesView.contentX: " + activitiesView.contentX + + "\n -activitiesLayout.x: " + -activitiesLayout.x + "\n mainDelegate.x: "+ mainDelegate.x + - "\n (activitiesView.contentX + activitiesView.width):"+ (activitiesView.contentX + activitiesView.width) + + "\n (-activitiesLayout.x + activitiesView.width):"+ (-activitiesLayout.x + activitiesView.width) + "\n (mainDelegate.x + mainDelegate.width):" + (mainDelegate.x + mainDelegate.width) } } From 896608092436b2ceb5c61d9bbef33ece82bbe821 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 23 Feb 2018 13:27:50 +0100 Subject: [PATCH 7/9] finish the port to Animators clean up the code --- shell/contents/views/Desktop.qml | 69 +++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/shell/contents/views/Desktop.qml b/shell/contents/views/Desktop.qml index 5a9b0b23..491215cf 100644 --- a/shell/contents/views/Desktop.qml +++ b/shell/contents/views/Desktop.qml @@ -41,13 +41,10 @@ Item { property int buttonHeight: width/4 property bool loadCompleted: false - SmoothedAnimation { + XAnimator { id: switchAnim - target: activitiesView - properties: "contentX" - to: 0 - //it's a long travel, we want a consistent velocity rather than duration - velocity: width + target: activitiesLayout + duration: units.longDuration easing.type: Easing.InOutQuad } MouseArea { @@ -61,25 +58,31 @@ Item { drag.minimumX: -activitiesLayout.width + width drag.maximumX: 0 property int currentIndex: -1 + property Item nextContainment: root.containment - onCurrentIndexChanged: { + function adjustPosition() { if (!activitiesLayout.loadCompleted) { - contentX = currentIndex * width; + activitiesLayout.x = - currentIndex * width; return; } - switchAnim.from = contentX; - switchAnim.to = currentIndex * width; + switchAnim.from = activitiesLayout.x; + switchAnim.to = - currentIndex * width; switchAnim.running = true; } - /* onFlickEnded: movementEnded(); - onMovementEnded: { - currentIndex = Math.round(contentX / width); - //be sure the animation will work - currentIndexChanged(); - }*/ + onCurrentIndexChanged: adjustPosition(); + //don't animate onWidthChanged: contentX = currentIndex * width; + onPositionChanged: { + var tempIndex = Math.round(-activitiesLayout.x / width); + nextContainment = activitiesLayout.children[tempIndex].containment; + } + onReleased: { + currentIndex = Math.round(-activitiesLayout.x / width); + //unconditionally run the slide anim + adjustPosition(); + } Row { id: activitiesLayout height: activitiesView.height @@ -94,23 +97,23 @@ Item { id: activityModel } - delegate: Rectangle { - radius: 100 + delegate: Item { id: mainDelegate width: activitiesView.width height: activitiesView.height property Item containment + //inViewport should be only the current, and the other adjacent two readonly property bool inViewport: activitiesLayout.loadCompleted && root.containment && ((x >= -activitiesLayout.x && - x < -activitiesLayout.x + activitiesView.width) || - (x + width > -activitiesLayout.x && + x <= -activitiesLayout.x + activitiesView.width) || + (x + width >= -activitiesLayout.x && x + width < -activitiesLayout.x + activitiesView.width)) readonly property bool currentActivity: root.containment && model.current Connections { target: activitiesView - onMovementEnded: { + onCurrentIndexChanged: { if (activitiesView.currentIndex == index) { activityModel.setCurrentActivity(model.id, function(){ mainDelegate.containment.parent = mainDelegate; @@ -132,7 +135,7 @@ Item { activitiesView.currentIndex = index; } } - + /*DEBUG TODO remove Text { z: 100 text: "inViewport: " + mainDelegate.inViewport + @@ -140,7 +143,7 @@ Item { "\n mainDelegate.x: "+ mainDelegate.x + "\n (-activitiesLayout.x + activitiesView.width):"+ (-activitiesLayout.x + activitiesView.width) + "\n (mainDelegate.x + mainDelegate.width):" + (mainDelegate.x + mainDelegate.width) - } + }*/ } } } @@ -151,12 +154,30 @@ Item { z: 100 anchors { bottom: parent.bottom + bottomMargin: root.containment.availableScreenRect.y + root.containment.availableScreenRect.height horizontalCenter: parent.horizontalCenter } count: activitiesView.count currentIndex: activitiesView.currentIndex } - + PlasmaCore.FrameSvgItem { + z: 100 + opacity: activitiesView.drag.active ? 1 : 0 + anchors.centerIn: parent + imagePath: "widgets/background" + width: childrenRect.width + units.gridUnit*2 + height: childrenRect.height + units.gridUnit*2 + PlasmaComponents.Label { + anchors.centerIn: parent + text: activitiesView.nextContainment.activityName + } + Behavior on opacity { + OpacityAnimator { + duration: units.longDuration + easing.type: Easing.InOutQuad + } + } + } function toggleWidgetExplorer(containment) { console.log("Widget Explorer toggled"); From 727c0fd7c957127532748b11d1b9200845ea884a Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 19 Apr 2018 17:37:16 +0200 Subject: [PATCH 8/9] use candidatecontainments --- shell/contents/views/Desktop.qml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/shell/contents/views/Desktop.qml b/shell/contents/views/Desktop.qml index 491215cf..fa3f310a 100644 --- a/shell/contents/views/Desktop.qml +++ b/shell/contents/views/Desktop.qml @@ -40,7 +40,17 @@ Item { property int notificationId: 0; property int buttonHeight: width/4 property bool loadCompleted: false + property var candidateContainments: Object + Connections { + target: desktop + onCandidateContainmentsChanged: { + for (var i = 0; i < desktop.candidateContainments.length; ++i) { + var cont = desktop.candidateContainments[i]; + root.candidateContainments[cont.activity] = cont; + } + } + } XAnimator { id: switchAnim target: activitiesLayout @@ -124,7 +134,8 @@ Item { } onInViewportChanged: { if (inViewport && !mainDelegate.containment) { - mainDelegate.containment = desktop.containmentItemForActivity(model.id); + mainDelegate.containment = root.candidateContainments[model.id]; + //desktop.containmentItemForActivity(model.id); containmentNextActivityPreview = containment; mainDelegate.containment.parent = mainDelegate; mainDelegate.containment.anchors.fill = mainDelegate; @@ -135,15 +146,6 @@ Item { activitiesView.currentIndex = index; } } - /*DEBUG TODO remove - Text { - z: 100 - text: "inViewport: " + mainDelegate.inViewport + - "\n -activitiesLayout.x: " + -activitiesLayout.x + - "\n mainDelegate.x: "+ mainDelegate.x + - "\n (-activitiesLayout.x + activitiesView.width):"+ (-activitiesLayout.x + activitiesView.width) + - "\n (mainDelegate.x + mainDelegate.width):" + (mainDelegate.x + mainDelegate.width) - }*/ } } } From 3a9592419c4e53c2f28b7fe92e2a4b54d5742add Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Sun, 22 Apr 2018 17:09:49 +0200 Subject: [PATCH 9/9] imake it work with latest revision --- shell/contents/views/Desktop.qml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/shell/contents/views/Desktop.qml b/shell/contents/views/Desktop.qml index fa3f310a..1bc89286 100644 --- a/shell/contents/views/Desktop.qml +++ b/shell/contents/views/Desktop.qml @@ -40,17 +40,7 @@ Item { property int notificationId: 0; property int buttonHeight: width/4 property bool loadCompleted: false - property var candidateContainments: Object - Connections { - target: desktop - onCandidateContainmentsChanged: { - for (var i = 0; i < desktop.candidateContainments.length; ++i) { - var cont = desktop.candidateContainments[i]; - root.candidateContainments[cont.activity] = cont; - } - } - } XAnimator { id: switchAnim target: activitiesLayout @@ -134,7 +124,7 @@ Item { } onInViewportChanged: { if (inViewport && !mainDelegate.containment) { - mainDelegate.containment = root.candidateContainments[model.id]; + mainDelegate.containment = desktop.candidateContainments[model.id]; //desktop.containmentItemForActivity(model.id); containmentNextActivityPreview = containment; mainDelegate.containment.parent = mainDelegate; @@ -145,6 +135,7 @@ Item { if (currentActivity) { activitiesView.currentIndex = index; } + mainDelegate.containment.visible = true; } } }