finish the port to Animators

clean up the code
This commit is contained in:
Marco Martin 2018-02-23 13:27:50 +01:00
parent 4ab220ed06
commit 8966080924

View file

@ -41,13 +41,10 @@ Item {
property int buttonHeight: width/4 property int buttonHeight: width/4
property bool loadCompleted: false property bool loadCompleted: false
SmoothedAnimation { XAnimator {
id: switchAnim id: switchAnim
target: activitiesView target: activitiesLayout
properties: "contentX" duration: units.longDuration
to: 0
//it's a long travel, we want a consistent velocity rather than duration
velocity: width
easing.type: Easing.InOutQuad easing.type: Easing.InOutQuad
} }
MouseArea { MouseArea {
@ -61,25 +58,31 @@ Item {
drag.minimumX: -activitiesLayout.width + width drag.minimumX: -activitiesLayout.width + width
drag.maximumX: 0 drag.maximumX: 0
property int currentIndex: -1 property int currentIndex: -1
property Item nextContainment: root.containment
onCurrentIndexChanged: { function adjustPosition() {
if (!activitiesLayout.loadCompleted) { if (!activitiesLayout.loadCompleted) {
contentX = currentIndex * width; activitiesLayout.x = - currentIndex * width;
return; return;
} }
switchAnim.from = contentX; switchAnim.from = activitiesLayout.x;
switchAnim.to = currentIndex * width; switchAnim.to = - currentIndex * width;
switchAnim.running = true; switchAnim.running = true;
} }
/* onFlickEnded: movementEnded(); onCurrentIndexChanged: adjustPosition();
onMovementEnded: {
currentIndex = Math.round(contentX / width);
//be sure the animation will work
currentIndexChanged();
}*/
//don't animate //don't animate
onWidthChanged: contentX = currentIndex * width; 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 { Row {
id: activitiesLayout id: activitiesLayout
height: activitiesView.height height: activitiesView.height
@ -94,23 +97,23 @@ Item {
id: activityModel id: activityModel
} }
delegate: Rectangle { delegate: Item {
radius: 100
id: mainDelegate id: mainDelegate
width: activitiesView.width width: activitiesView.width
height: activitiesView.height height: activitiesView.height
property Item containment property Item containment
//inViewport should be only the current, and the other adjacent two
readonly property bool inViewport: activitiesLayout.loadCompleted && root.containment && readonly property bool inViewport: activitiesLayout.loadCompleted && root.containment &&
((x >= -activitiesLayout.x && ((x >= -activitiesLayout.x &&
x < -activitiesLayout.x + activitiesView.width) || x <= -activitiesLayout.x + activitiesView.width) ||
(x + width > -activitiesLayout.x && (x + width >= -activitiesLayout.x &&
x + width < -activitiesLayout.x + activitiesView.width)) x + width < -activitiesLayout.x + activitiesView.width))
readonly property bool currentActivity: root.containment && model.current readonly property bool currentActivity: root.containment && model.current
Connections { Connections {
target: activitiesView target: activitiesView
onMovementEnded: { onCurrentIndexChanged: {
if (activitiesView.currentIndex == index) { if (activitiesView.currentIndex == index) {
activityModel.setCurrentActivity(model.id, function(){ activityModel.setCurrentActivity(model.id, function(){
mainDelegate.containment.parent = mainDelegate; mainDelegate.containment.parent = mainDelegate;
@ -132,7 +135,7 @@ Item {
activitiesView.currentIndex = index; activitiesView.currentIndex = index;
} }
} }
/*DEBUG TODO remove
Text { Text {
z: 100 z: 100
text: "inViewport: " + mainDelegate.inViewport + text: "inViewport: " + mainDelegate.inViewport +
@ -140,7 +143,7 @@ Item {
"\n mainDelegate.x: "+ mainDelegate.x + "\n mainDelegate.x: "+ mainDelegate.x +
"\n (-activitiesLayout.x + activitiesView.width):"+ (-activitiesLayout.x + activitiesView.width) + "\n (-activitiesLayout.x + activitiesView.width):"+ (-activitiesLayout.x + activitiesView.width) +
"\n (mainDelegate.x + mainDelegate.width):" + (mainDelegate.x + mainDelegate.width) "\n (mainDelegate.x + mainDelegate.width):" + (mainDelegate.x + mainDelegate.width)
} }*/
} }
} }
} }
@ -151,12 +154,30 @@ Item {
z: 100 z: 100
anchors { anchors {
bottom: parent.bottom bottom: parent.bottom
bottomMargin: root.containment.availableScreenRect.y + root.containment.availableScreenRect.height
horizontalCenter: parent.horizontalCenter horizontalCenter: parent.horizontalCenter
} }
count: activitiesView.count count: activitiesView.count
currentIndex: activitiesView.currentIndex 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) { function toggleWidgetExplorer(containment) {
console.log("Widget Explorer toggled"); console.log("Widget Explorer toggled");