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

245 lines
7.7 KiB
QML
Raw Normal View History

2015-06-18 23:31:26 +00:00
/*
* Copyright 2015 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program 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 Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
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
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-17 12:13:35 +00:00
color: Qt.rgba(0, 0, 0, 0.6 * 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-17 12:13:35 +00:00
if (tasksView.contentY + window.height < tasksView.contentHeight/2) {
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
}
function setSingleActiveWindow(id) {
if (id >= 0) {
2020-07-17 12:13:35 +00:00
window.model.requestActivate(window.model.index(id, 0));
}
}
onOffsetChanged: tasksView.contentY = offset
2020-07-17 12:13:35 +00:00
onVisibleChanged: {
if (!visible) {
tasksView.contentY = 0;
}
}
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-17 12:13:35 +00:00
if (tasksView.contentY <= 0 || tasksView.contentY >= tasksView.contentHeight - window.height) {
2015-06-18 23:31:26 +00:00
window.visible = false;
setSingleActiveWindow(currentTaskIndex);
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
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) {
draggingVerticallyChanged();
flickState = TaskSwitcher.MovementDirection.None
2015-06-18 23:31:26 +00:00
}
2020-07-17 12:13:35 +00:00
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
bottom: parent.bottom
bottomMargin: window.height
}
columns: 2
Repeater {
model: window.model
delegate: Task {}
}
move: Transition {
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;
}
}
2015-06-18 23:31:26 +00:00
}