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

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

217 lines
6.4 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
2021-10-18 03:50:59 +00:00
import QtQuick 2.15
2015-06-21 19:18:02 +00:00
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
import QtQuick.Controls 2.2 as QQC2
2023-03-06 06:38:43 +00:00
import Qt5Compat.GraphicalEffects
2015-06-21 19:18:02 +00:00
import org.kde.plasma.core 2.0 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);
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
2021-10-18 03:50:59 +00:00
// drag up gesture
DragHandler {
id: dragHandler
target: parent
2023-03-06 06:38:43 +00:00
enabled: !taskSwitcher.taskSwitcherState.currentlyBeingOpened
2023-03-06 06:38:43 +00:00
2021-10-18 03:50:59 +00:00
yAxis.enabled: true
xAxis.enabled: false
yAxis.maximum: 0
2023-03-06 06:38:43 +00:00
// y > 0 - dragging down (opening the app)
// y < 0 - dragging up (dismissing the app)
2021-10-18 03:50:59 +00:00
onActiveChanged: {
yAnimator.stop();
2023-03-06 06:38:43 +00:00
if (control.movingUp && parent.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: !dragHandler.active
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
2023-03-06 06:38:43 +00:00
property real zoomScale: tapHandler.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)
}
}
}
2023-03-06 06:38:43 +00:00
2021-10-18 03:50:59 +00:00
TapHandler {
2022-04-07 00:33:23 +00:00
id: tapHandler
enabled: !taskSwitcher.taskSwitcherState.currentlyBeingOpened
onTapped: delegate.activateApp()
2021-10-18 03:50:59 +00:00
}
2020-08-20 14:55:14 +00:00
}
2015-06-21 19:18:02 +00:00
}
}
}
}
2023-03-06 06:38:43 +00:00