shift-shell/containments/taskpanel/package/contents/ui/TaskSwitcher.qml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

316 lines
10 KiB
QML
Raw Normal View History

2015-06-18 23:31:26 +00:00
/*
2021-03-01 20:03:25 +00:00
* SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com>
2015-06-18 23:31:26 +00:00
*
2021-03-01 20:03:25 +00:00
* SPDX-License-Identifier: LGPL-2.0-or-later
2015-06-18 23:31:26 +00:00
*/
2020-07-17 12:13:35 +00:00
import QtQuick 2.12
2015-06-18 23:31:26 +00:00
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
import org.kde.taskmanager 0.1 as TaskManager
2015-06-24 20:47:07 +00:00
import org.kde.plasma.core 2.1 as PlasmaCore
2019-10-11 10:06:12 +00:00
import org.kde.plasma.components 3.0 as PlasmaComponents
2019-09-18 13:31:04 +00:00
import org.kde.plasma.private.nanoshell 2.0 as NanoShell
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
2015-06-18 23:31:26 +00:00
2019-09-18 14:49:44 +00:00
NanoShell.FullScreenOverlay {
2015-06-18 23:31:26 +00:00
id: window
visible: false
width: Screen.width
height: Screen.height
property int offset: 0
property int overShoot: units.gridUnit * 2
2020-07-17 12:13:35 +00:00
property int tasksCount: window.model.count
property int currentTaskIndex: -1
2020-07-17 12:13:35 +00:00
property TaskManager.TasksModel model
2015-06-18 23:31:26 +00:00
Component.onCompleted: plasmoid.nativeInterface.panel = window;
2020-07-17 12:13:35 +00:00
enum MovementDirection {
None = 0,
Up,
Down
}
onTasksCountChanged: {
if (tasksCount == 0) {
hide();
}
}
2020-07-31 10:06:46 +00:00
color: "transparent"
// More controllable than the color property
Rectangle {
anchors.fill: parent
color: Qt.rgba(0, 0, 0, 0.6)
opacity: Math.min(
(Math.min(tasksView.contentY, tasksView.height) / tasksView.height),
((tasksView.contentHeight - tasksView.contentY - window.height) / tasksView.height))
}
2015-06-18 23:31:26 +00:00
function show() {
2020-07-17 12:13:35 +00:00
if (window.model.count == 0) {
return;
}
2020-07-17 12:13:35 +00:00
2015-06-18 23:31:26 +00:00
visible = true;
2015-06-22 05:34:43 +00:00
scrollAnim.from = tasksView.contentY;
2020-07-17 12:13:35 +00:00
scrollAnim.to = window.height;
scrollAnim.restart();
2015-06-18 23:31:26 +00:00
}
function hide() {
2020-07-17 09:19:56 +00:00
if (!window.visible) {
return;
}
2015-06-22 05:34:43 +00:00
scrollAnim.from = tasksView.contentY;
2020-07-31 14:31:17 +00:00
if (tasksView.contentY + window.height <= tasksView.contentHeight - tasksView.contentY) {
2020-07-17 12:13:35 +00:00
scrollAnim.to = 0;
2015-06-22 05:34:43 +00:00
} else {
2020-07-17 12:13:35 +00:00
scrollAnim.to = tasksView.contentHeight - window.height;
2015-06-22 05:34:43 +00:00
}
2020-07-17 12:13:35 +00:00
scrollAnim.restart();
2015-06-18 23:31:26 +00:00
}
2020-07-30 15:53:55 +00:00
function setSingleActiveWindow(id, delegate) {
if (id < 0) {
return;
}
for (var i = 0 ; i < tasksModel.count; i++) {
var idx = window.model.index(i, 0)
if (i == id) {
window.model.requestActivate(idx);
} else if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsMinimized)) {
tasksModel.requestToggleMinimized(idx);
}
}
2020-07-30 15:53:55 +00:00
activateAnim.delegate = delegate;
activateAnim.restart();
}
2020-07-17 16:12:07 +00:00
onOffsetChanged: tasksView.contentY = offset + grid.y
2020-07-17 12:13:35 +00:00
onVisibleChanged: {
if (!visible) {
tasksView.contentY = 0;
moveTransition.enabled = false;
scrollAnim.running = false;
activateAnim.running = false;
window.contentItem.opacity = 1;
if (activateAnim.delegate) {
activateAnim.delegate.z = 0;
activateAnim.delegate.scale = 1;
}
2020-07-17 12:13:35 +00:00
}
MobileShell.HomeScreenControls.taskSwitcherVisible = visible;
2020-07-17 12:13:35 +00:00
}
2015-06-18 23:31:26 +00:00
SequentialAnimation {
id: scrollAnim
property alias to: internalAnim.to
2015-06-22 05:34:43 +00:00
property alias from: internalAnim.from
2015-06-18 23:31:26 +00:00
ScriptAction {
script: window.showFullScreen();
2015-06-18 23:31:26 +00:00
}
NumberAnimation {
id: internalAnim
target: tasksView
properties: "contentY"
duration: units.longDuration
easing.type: Easing.InOutQuad
}
ScriptAction {
script: {
2020-07-30 15:56:34 +00:00
if (tasksView.contentY <= 0 || tasksView.contentY >= tasksView.contentHeight - window.height) {
window.visible = false;
setSingleActiveWindow(currentTaskIndex);
} else {
moveTransition.enabled = true;
2020-07-30 15:56:34 +00:00
}
2020-07-30 15:53:55 +00:00
}
}
}
SequentialAnimation {
id: activateAnim
property Item delegate
ScriptAction {
script: {
activateAnim.delegate.z = 2;
2020-07-31 10:06:46 +00:00
let pos = tasksView.mapFromItem(activateAnim.delegate, 0, 0);
if (pos.x < tasksView.width / 2 && pos.y < tasksView.height / 2) {
activateAnim.delegate.transformOrigin = Item.TopLeft;
} else if (pos.x < tasksView.width / 2 && pos.y >= tasksView.height / 2) {
activateAnim.delegate.transformOrigin = Item.BottomLeft;
} else if (pos.x >= tasksView.width / 2 && pos.y < tasksView.height / 2) {
activateAnim.delegate.transformOrigin = Item.TopRight;
} else {
activateAnim.delegate.transformOrigin = Item.BottomRight;
}
2020-07-30 15:53:55 +00:00
}
}
ParallelAnimation {
OpacityAnimator {
target: window.contentItem
from: 1
to: 0
duration: units.longDuration
easing.type: Easing.InOutQuad
}
ScaleAnimator {
target: activateAnim.delegate
from: 1
to: 2
// To try tosync up with kwin animation
duration: units.longDuration * 0.85
2020-07-30 15:53:55 +00:00
easing.type: Easing.InOutQuad
}
}
ScriptAction {
script: {
window.visible = false;
2015-06-18 23:31:26 +00:00
}
}
}
2020-07-17 12:13:35 +00:00
Flickable {
2015-06-18 23:31:26 +00:00
id: tasksView
width: window.width
height: window.height
2020-07-17 12:13:35 +00:00
contentWidth: width
contentHeight: mainArea.implicitHeight
2020-07-31 10:44:44 +00:00
// topMargin: flickingVertically ? -height : 0
// bottomMargin: flickingVertically ? -height : 0
2020-07-17 12:13:35 +00:00
property int flickState: TaskSwitcher.MovementDirection.None
readonly property int movementDirection: {
if (flickState != TaskSwitcher.MovementDirection.None) {
return flickState;
} else if (verticalVelocity < 0) {
return TaskSwitcher.MovementDirection.Up;
} else if (verticalVelocity > 0) {
return TaskSwitcher.MovementDirection.Down;
} else {
return TaskSwitcher.MovementDirection.None;
}
}
onFlickingVerticallyChanged: {
if (flickingVertically) {
flickState = verticalVelocity < 0 ? TaskSwitcher.MovementDirection.Up : TaskSwitcher.MovementDirection.Down;
} else if (/*!draggingVertically &&*/ !flickingVertically) {
flickState = TaskSwitcher.MovementDirection.None
2015-06-18 23:31:26 +00:00
}
2020-07-31 10:44:44 +00:00
Qt.callLater(function() {
tasksView.topMargin = flickingVertically && !scrollAnim.running ? -tasksView.height : 0;
tasksView.bottomMargin = tasksView.topMargin;
});
2015-06-18 23:31:26 +00:00
}
2015-06-22 05:34:43 +00:00
2015-06-18 23:31:26 +00:00
onDraggingVerticallyChanged: {
if (draggingVertically) {
return;
}
2020-07-17 12:13:35 +00:00
let beforeBeginning = contentY < window.height;
let afterEnd = contentY > contentHeight - window.height * 2;
let topCloseCondition = contentY < window.height / 10 * 9;
let bottomClosecondition = contentY > contentHeight - window.height * 2 - window.height / 10;
switch (movementDirection) {
case TaskSwitcher.MovementDirection.Up: {
if (topCloseCondition) {
hide();
} else if (beforeBeginning) {
show();
} else if (afterEnd) {
scrollAnim.from = tasksView.contentY;
scrollAnim.to = tasksView.contentHeight - window.height * 2;
scrollAnim.restart();
}
break;
2015-06-18 23:31:26 +00:00
}
2020-07-17 12:13:35 +00:00
case TaskSwitcher.MovementDirection.Down: {
if (bottomClosecondition) {
hide();
} else if (beforeBeginning) {
show();
} else if (afterEnd) {
scrollAnim.from = tasksView.contentY;
scrollAnim.to = tasksView.contentHeight - window.height * 2;
scrollAnim.restart();
}
2020-07-17 12:13:35 +00:00
break;
}
2020-07-17 12:13:35 +00:00
case TaskSwitcher.MovementDirection.None:
default:
if (beforeBeginning) {
show();
} else if (afterEnd) {
scrollAnim.from = tasksView.contentY;
scrollAnim.to = tasksView.contentHeight - window.height * 2;
scrollAnim.restart();
}
break;
2015-06-21 19:26:14 +00:00
}
}
2020-07-17 12:13:35 +00:00
2020-02-04 19:10:01 +00:00
MouseArea {
2020-07-17 12:13:35 +00:00
id: mainArea
2020-02-04 19:10:01 +00:00
parent: tasksView.contentItem
2020-07-17 12:13:35 +00:00
width: tasksView.width
implicitHeight: window.height * 2 + Math.max(window.height, grid.implicitHeight)
2020-02-04 19:10:01 +00:00
onClicked: window.hide()
2020-07-17 12:13:35 +00:00
Grid {
id: grid
anchors {
left: parent.left
right: parent.right
}
columns: 2
2020-07-31 14:31:17 +00:00
y: parent.height - height - window.height
2020-07-17 12:13:35 +00:00
2020-07-31 14:31:17 +00:00
Behavior on y {
NumberAnimation {
duration: units.longDuration
easing.type: Easing.InOutQuad
}
}
2020-07-17 12:13:35 +00:00
Repeater {
model: window.model
delegate: Task {}
}
move: Transition {
id: moveTransition
enabled: false
2020-07-17 12:13:35 +00:00
NumberAnimation {
properties: "x,y"
duration: units.longDuration
easing.type: Easing.InOutQuad
}
}
}
2020-02-04 19:10:01 +00:00
}
2020-07-17 12:13:35 +00:00
2015-06-18 23:31:26 +00:00
}
2019-10-11 10:06:12 +00:00
PlasmaComponents.RoundButton {
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
}
2019-10-11 10:06:12 +00:00
icon.name: "start-here-kde"
2020-07-17 09:27:38 +00:00
icon.width: units.iconSizes.medium
icon.height: units.iconSizes.medium
onClicked: {
currentTaskIndex = -1;
window.hide();
//plasmoid.nativeInterface.showDesktop = true;
root.minimizeAll();
}
}
2015-06-18 23:31:26 +00:00
}