mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-28 22:53:09 +00:00
get rid of ListView and hackTimer
This commit is contained in:
parent
fa8bec3fd8
commit
3f515a3c16
1 changed files with 109 additions and 159 deletions
|
|
@ -29,91 +29,126 @@ import org.kde.kquickcontrolsaddons 2.0
|
||||||
import org.kde.activities 0.1 as Activities
|
import org.kde.activities 0.1 as Activities
|
||||||
import "../components"
|
import "../components"
|
||||||
|
|
||||||
MouseArea {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
width: 1080
|
width: 0
|
||||||
height: 1920
|
height: 0
|
||||||
|
|
||||||
property Item containment;
|
property Item containment;
|
||||||
property Item containmentNextActivityPreview;
|
property Item containmentNextActivityPreview;
|
||||||
property Item wallpaper;
|
property Item wallpaper;
|
||||||
property int notificationId: 0;
|
property int notificationId: 0;
|
||||||
property int buttonHeight: width/4
|
property int buttonHeight: width/4
|
||||||
property bool containmentsEnterFromRight: true
|
property bool loadCompleted: false
|
||||||
drag.filterChildren: false
|
|
||||||
|
|
||||||
//HACK FIXME this timer hack is to wait activitiesView finished all its setup
|
SmoothedAnimation {
|
||||||
//which we can't know for sure and suggests that we can't really use it
|
id: switchAnim
|
||||||
Timer {
|
target: activitiesView
|
||||||
id: hackTimer
|
properties: "contentX"
|
||||||
interval: 1000
|
to: 0
|
||||||
running: true
|
//it's a long travel, we want a consistent velocity rather than duration
|
||||||
|
velocity: width
|
||||||
|
easing.type: Easing.InOutQuad
|
||||||
}
|
}
|
||||||
ListView {
|
Flickable {
|
||||||
id: activitiesView
|
id: activitiesView
|
||||||
z: 998
|
z: 99
|
||||||
visible: root.containment
|
visible: root.containment
|
||||||
interactive: true
|
interactive: true
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
orientation: ListView.Horizontal
|
contentWidth: activitiesLayout.width
|
||||||
snapMode: ListView.SnapOneItem
|
contentHeight: height
|
||||||
boundsBehavior: Flickable.StopAtBounds
|
boundsBehavior: Flickable.StopAtBounds
|
||||||
highlightMoveDuration: 0
|
maximumFlickVelocity: width/5
|
||||||
highlightRangeMode: ListView.StrictlyEnforceRange
|
property int currentIndex: -1
|
||||||
cacheBuffer: width * count * 2
|
|
||||||
model: Activities.ActivityModel {
|
onCurrentIndexChanged: {
|
||||||
id: activityModel
|
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 {
|
Row {
|
||||||
radius: 100
|
id: activitiesLayout
|
||||||
id: mainDelegate
|
|
||||||
width: activitiesView.width
|
|
||||||
height: activitiesView.height
|
height: activitiesView.height
|
||||||
property Item containment
|
spacing: 0
|
||||||
readonly property bool inViewport: !hackTimer.running && root.containment &&
|
//don't try to do anything until we are well setted up
|
||||||
((x >= activitiesView.contentX &&
|
property bool loadCompleted: root.loadCompleted && width == activitiesView.width * (activitiesLayout.children.length - 1) && activitiesLayout.children.length == activityRepeater.count + 1
|
||||||
x < activitiesView.contentX + activitiesView.width) ||
|
onLoadCompletedChanged: activitiesView.currentIndexChanged();
|
||||||
(x + width > activitiesView.contentX &&
|
|
||||||
x + width < activitiesView.contentX + activitiesView.width))
|
Repeater {
|
||||||
readonly property bool currentActivity: root.containment && model.current
|
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 {
|
Connections {
|
||||||
target: activitiesView
|
target: activitiesView
|
||||||
onMovementEnded: {
|
onMovementEnded: {
|
||||||
if (activitiesView.currentIndex == index) {
|
if (activitiesView.currentIndex == index) {
|
||||||
activityModel.setCurrentActivity(model.id, function(){
|
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.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 {
|
PageIndicator {
|
||||||
z: 999
|
z: 100
|
||||||
anchors {
|
anchors {
|
||||||
bottom: parent.bottom
|
bottom: parent.bottom
|
||||||
horizontalCenter: parent.horizontalCenter
|
horizontalCenter: parent.horizontalCenter
|
||||||
|
|
@ -121,27 +156,7 @@ MouseArea {
|
||||||
count: activitiesView.count
|
count: activitiesView.count
|
||||||
currentIndex: activitiesView.currentIndex
|
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) {
|
function toggleWidgetExplorer(containment) {
|
||||||
console.log("Widget Explorer toggled");
|
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 {
|
Binding {
|
||||||
target: containment
|
target: containment
|
||||||
property: "width"
|
property: "width"
|
||||||
|
|
@ -212,51 +196,7 @@ MouseArea {
|
||||||
property Item oldContainment: null;
|
property Item oldContainment: null;
|
||||||
property Item newContainment: 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
|
//pass the focus to the containment, so it can react to homescreen activate/inactivate
|
||||||
Connections {
|
Connections {
|
||||||
target: desktop
|
target: desktop
|
||||||
|
|
@ -276,11 +216,21 @@ MouseArea {
|
||||||
source: Qt.resolvedUrl("Pin.qml")
|
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
|
//configure the view behavior
|
||||||
if (desktop) {
|
if (desktop && root.width > 0) {
|
||||||
desktop.width = width;
|
desktop.width = width;
|
||||||
desktop.height = height;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue