shift-shell/kwin/mobiletaskswitcher/qml/Task.qml

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

238 lines
7.2 KiB
QML
Raw Normal View History

2023-03-06 06:38:43 +00:00
// SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com>
// SPDX-FileCopyrightText: 2021-2023 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
2015-06-21 19:18:02 +00:00
import QtQuick
import QtQuick.Layouts
2023-03-06 06:38:43 +00:00
import Qt5Compat.GraphicalEffects
import org.kde.plasma.core as PlasmaCore
2020-07-17 09:12:06 +00:00
import org.kde.plasma.components 3.0 as PlasmaComponents
2023-03-06 06:38:43 +00:00
import org.kde.kwin 3.0 as KWinComponents
2015-06-21 19:18:02 +00:00
Item {
id: delegate
required property var taskSwitcher
2023-03-06 06:38:43 +00:00
required property QtObject window
required property int index
required property var model
2021-10-18 03:50:59 +00:00
required property real previewHeight
required property real previewWidth
2023-03-06 06:38:43 +00:00
readonly property real dragOffset: -control.y
2023-03-06 06:38:43 +00:00
property bool showHeader: true
property real darken: 0
2023-03-06 06:38:43 +00:00
opacity: 1 - dragOffset / taskSwitcher.height
2023-03-06 06:38:43 +00:00
//BEGIN functions
function closeApp() {
2023-03-06 06:38:43 +00:00
delegate.window.closeWindow();
}
2023-03-06 06:38:43 +00:00
function activateApp() {
taskSwitcherState.wasInActiveTask = false;
2023-03-06 06:38:43 +00:00
taskSwitcher.activateWindow(model.index, delegate.window);
delegate.window.setMaximize(true, true);
}
2023-03-06 06:38:43 +00:00
function minimizeApp() {
delegate.window.minimized = true;
}
2023-03-06 06:38:43 +00:00
//END functions
MouseArea {
2021-10-18 03:50:59 +00:00
id: control
width: parent.width
height: parent.height
enabled: !taskSwitcher.taskSwitcherState.currentlyBeingOpened
2023-03-06 06:38:43 +00:00
// set cursor shape here, since taphandler seems to not be able to do it
cursorShape: Qt.PointingHandCursor
2023-03-06 06:38:43 +00:00
property bool movingUp: false
property real oldY: y
onYChanged: {
movingUp = y < oldY;
oldY = y;
}
2023-03-06 06:38:43 +00:00
onClicked: {
if (!taskSwitcher.taskSwitcherState.currentlyBeingOpened && !passedDragThreshold) {
delegate.activateApp();
}
}
// pixels before we start treating it as drag event
readonly property real dragThreshold: 5
2023-03-06 06:38:43 +00:00
property real startPosition: 0
property bool hasStartPosition: false
property bool passedDragThreshold: false
2023-03-06 06:38:43 +00:00
onPositionChanged: (mouse) => {
// map it to the root area, so that it doesn't jitter (since this item is moving)
const yPos = control.mapToItem(delegate, mouse.x, mouse.y).y
2023-03-06 06:38:43 +00:00
// reset start position
if (!hasStartPosition) {
startPosition = yPos;
hasStartPosition = true;
}
// set threshold
if (!passedDragThreshold && Math.abs(y) > dragThreshold) {
passedDragThreshold = true;
// TODO: request that FlickContainer be not interactive (so we don't change position in list while swiping up)
}
// update position
// y < 0 - dragging up (dismissing the app)
y = Math.min(0, yPos - startPosition);
}
onPressedChanged: {
yAnimator.stop();
// reset values
if (pressed) {
hasStartPosition = false;
passedDragThreshold = false;
}
2023-03-06 06:38:43 +00:00
// run animation when finger lets go
if (!pressed) {
if (control.movingUp && control.y < -PlasmaCore.Units.gridUnit * 2) {
yAnimator.to = -root.height;
2021-10-18 03:50:59 +00:00
} else {
yAnimator.to = 0;
}
yAnimator.start();
2015-06-21 19:26:14 +00:00
}
2021-10-18 03:50:59 +00:00
}
2023-03-06 06:38:43 +00:00
// if the app doesn't close within a certain time, drag it back
Timer {
id: uncloseTimer
interval: 3000
onTriggered: {
yAnimator.to = 0;
yAnimator.restart();
}
}
2023-03-06 06:38:43 +00:00
2021-10-18 03:50:59 +00:00
NumberAnimation on y {
id: yAnimator
running: !control.pressed
2021-10-18 03:50:59 +00:00
duration: PlasmaCore.Units.longDuration
easing.type: Easing.InOutQuad
to: 0
onFinished: {
if (to != 0) { // close app
delegate.closeApp();
uncloseTimer.start();
2015-06-21 19:26:14 +00:00
}
}
2015-06-21 19:18:02 +00:00
}
2020-08-20 14:55:14 +00:00
2021-10-18 03:50:59 +00:00
// application
ColumnLayout {
2021-10-31 19:21:02 +00:00
id: column
anchors.fill: parent
2021-10-31 19:21:02 +00:00
spacing: 0
2023-03-06 06:38:43 +00:00
2021-10-31 19:21:02 +00:00
// header
2021-10-18 03:50:59 +00:00
RowLayout {
id: appHeader
Layout.fillWidth: true
2021-10-31 19:21:02 +00:00
Layout.fillHeight: true
Layout.minimumHeight: column.height - appView.height
spacing: PlasmaCore.Units.smallSpacing * 2
opacity: delegate.showHeader ? 1 : 0
2023-03-06 06:38:43 +00:00
Behavior on opacity {
NumberAnimation { duration: PlasmaCore.Units.shortDuration }
}
2023-03-06 06:38:43 +00:00
2021-10-18 03:50:59 +00:00
PlasmaCore.IconItem {
Layout.preferredHeight: PlasmaCore.Units.iconSizes.smallMedium
Layout.preferredWidth: PlasmaCore.Units.iconSizes.smallMedium
Layout.alignment: Qt.AlignVCenter
usesPlasmaTheme: false
2023-03-06 06:38:43 +00:00
source: delegate.window.icon
2015-06-21 19:18:02 +00:00
}
2023-03-06 06:38:43 +00:00
2021-10-18 03:50:59 +00:00
PlasmaComponents.Label {
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
elide: Text.ElideRight
2023-03-06 06:38:43 +00:00
text: delegate.window.caption
2021-10-18 03:50:59 +00:00
color: "white"
2015-06-21 19:18:02 +00:00
}
2023-03-06 06:38:43 +00:00
2021-10-18 03:50:59 +00:00
PlasmaComponents.ToolButton {
2021-10-31 19:21:02 +00:00
Layout.alignment: Qt.AlignVCenter
2021-10-18 03:50:59 +00:00
z: 99
icon.name: "window-close"
icon.width: PlasmaCore.Units.iconSizes.smallMedium
icon.height: PlasmaCore.Units.iconSizes.smallMedium
onClicked: delegate.closeApp()
}
}
2023-03-06 06:38:43 +00:00
2021-10-31 19:21:02 +00:00
// app preview
Rectangle {
2021-10-18 03:50:59 +00:00
id: appView
Layout.preferredWidth: delegate.previewWidth
2021-10-31 19:21:02 +00:00
Layout.preferredHeight: delegate.previewHeight
Layout.maximumWidth: delegate.previewWidth
Layout.maximumHeight: delegate.previewHeight
2023-03-06 06:38:43 +00:00
color: "transparent"
clip: true
2023-03-06 06:38:43 +00:00
// scale animation on press
property real zoomScale: control.pressed ? 0.9 : 1
2022-04-07 00:33:23 +00:00
Behavior on zoomScale {
NumberAnimation {
duration: 200
easing.type: Easing.OutExpo
}
}
2023-03-06 06:38:43 +00:00
transform: Scale {
origin.x: appView.width / 2;
origin.y: appView.height / 2;
2022-04-07 00:33:23 +00:00
xScale: appView.zoomScale
yScale: appView.zoomScale
}
2023-03-06 06:38:43 +00:00
Item {
2021-10-18 03:50:59 +00:00
id: item
anchors.fill: parent
2023-03-06 06:38:43 +00:00
KWinComponents.WindowThumbnail {
id: thumbSource
wId: delegate.window.internalId
anchors.fill: parent
2023-03-06 06:38:43 +00:00
layer {
enabled: true
effect: ColorOverlay {
color: Qt.rgba(0, 0, 0, delegate.darken)
}
}
}
2020-08-20 14:55:14 +00:00
}
2015-06-21 19:18:02 +00:00
}
}
}
}
2023-03-06 06:38:43 +00:00