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
|
|
|
|
2023-03-19 06:46:05 +00:00
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Layouts
|
2023-03-06 06:38:43 +00:00
|
|
|
import Qt5Compat.GraphicalEffects
|
2021-12-25 00:18:38 +00:00
|
|
|
|
2023-03-19 06:46:05 +00:00
|
|
|
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
|
2015-10-28 14:02:00 +00:00
|
|
|
|
2021-12-25 03:31:33 +00:00
|
|
|
required property var taskSwitcher
|
2023-03-06 06:38:43 +00:00
|
|
|
|
|
|
|
|
required property QtObject window
|
|
|
|
|
required property int index
|
|
|
|
|
|
2021-08-31 00:02:17 +00:00
|
|
|
required property var model
|
2015-10-28 14:02:00 +00:00
|
|
|
|
2021-10-18 03:50:59 +00:00
|
|
|
required property real previewHeight
|
|
|
|
|
required property real previewWidth
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2021-12-27 23:29:14 +00:00
|
|
|
readonly property real dragOffset: -control.y
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2023-04-01 03:32:56 +00:00
|
|
|
// whether this task is being interacted with
|
|
|
|
|
readonly property bool interactingActive: control.pressed && control.passedDragThreshold
|
|
|
|
|
|
|
|
|
|
// whether to show the text header
|
2021-12-27 23:29:14 +00:00
|
|
|
property bool showHeader: true
|
2023-04-01 03:32:56 +00:00
|
|
|
|
|
|
|
|
// the amount to darken the task preview by
|
2021-12-28 00:01:01 +00:00
|
|
|
property real darken: 0
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2021-12-25 03:31:33 +00:00
|
|
|
opacity: 1 - dragOffset / taskSwitcher.height
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2021-10-31 16:40:36 +00:00
|
|
|
//BEGIN functions
|
|
|
|
|
function closeApp() {
|
2023-03-06 06:38:43 +00:00
|
|
|
delegate.window.closeWindow();
|
2021-10-31 16:40:36 +00:00
|
|
|
}
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2021-10-31 16:40:36 +00:00
|
|
|
function activateApp() {
|
2022-04-28 23:39:29 +00:00
|
|
|
taskSwitcherState.wasInActiveTask = false;
|
2023-03-06 06:38:43 +00:00
|
|
|
taskSwitcher.activateWindow(model.index, delegate.window);
|
2023-03-31 05:26:35 +00:00
|
|
|
delegate.window.setMaximize(true, true);
|
2021-10-31 16:40:36 +00:00
|
|
|
}
|
2023-03-06 06:38:43 +00:00
|
|
|
|
|
|
|
|
function minimizeApp() {
|
|
|
|
|
delegate.window.minimized = true;
|
2015-10-28 14:02:00 +00:00
|
|
|
}
|
2023-03-06 06:38:43 +00:00
|
|
|
//END functions
|
|
|
|
|
|
2022-04-07 02:08:47 +00:00
|
|
|
MouseArea {
|
2021-10-18 03:50:59 +00:00
|
|
|
id: control
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: parent.height
|
2022-05-02 23:38:32 +00:00
|
|
|
enabled: !taskSwitcher.taskSwitcherState.currentlyBeingOpened
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2022-04-07 02:08:47 +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
|
|
|
|
2021-12-31 05:18:35 +00:00
|
|
|
property bool movingUp: false
|
|
|
|
|
property real oldY: y
|
|
|
|
|
onYChanged: {
|
|
|
|
|
movingUp = y < oldY;
|
|
|
|
|
oldY = y;
|
|
|
|
|
}
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2023-03-31 06:05:27 +00:00
|
|
|
onClicked: {
|
2023-03-31 06:53:31 +00:00
|
|
|
if (!taskSwitcher.taskSwitcherState.currentlyBeingOpened && !passedDragThreshold) {
|
2023-03-31 06:05:27 +00:00
|
|
|
delegate.activateApp();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-31 06:53:31 +00:00
|
|
|
// pixels before we start treating it as drag event
|
|
|
|
|
readonly property real dragThreshold: 5
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2023-03-31 06:53:31 +00:00
|
|
|
property real startPosition: 0
|
|
|
|
|
property bool hasStartPosition: false
|
|
|
|
|
property bool passedDragThreshold: false
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2023-03-31 06:53:31 +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
|
|
|
|
2023-03-31 06:53:31 +00:00
|
|
|
// reset start position
|
|
|
|
|
if (!hasStartPosition) {
|
|
|
|
|
startPosition = yPos;
|
|
|
|
|
hasStartPosition = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set threshold
|
|
|
|
|
if (!passedDragThreshold && Math.abs(y) > dragThreshold) {
|
|
|
|
|
passedDragThreshold = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update position
|
2021-12-27 18:07:34 +00:00
|
|
|
// y < 0 - dragging up (dismissing the app)
|
2023-03-31 06:53:31 +00:00
|
|
|
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
|
|
|
|
2023-03-31 06:53:31 +00:00
|
|
|
// run animation when finger lets go
|
|
|
|
|
if (!pressed) {
|
|
|
|
|
if (control.movingUp && control.y < -PlasmaCore.Units.gridUnit * 2) {
|
2021-12-25 03:31:33 +00:00
|
|
|
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
|
|
|
|
2021-12-31 05:18:35 +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
|
2023-03-31 06:53:31 +00:00
|
|
|
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();
|
2021-12-31 05:18:35 +00:00
|
|
|
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
|
2021-12-28 00:01:01 +00:00
|
|
|
ColumnLayout {
|
2021-10-31 19:21:02 +00:00
|
|
|
id: column
|
2021-12-28 00:01:01 +00:00
|
|
|
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
|
2021-10-31 16:40:36 +00:00
|
|
|
spacing: PlasmaCore.Units.smallSpacing * 2
|
2021-12-27 06:32:24 +00:00
|
|
|
opacity: delegate.showHeader ? 1 : 0
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2021-12-27 06:32:24 +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
|
2021-12-27 23:02:41 +00:00
|
|
|
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"
|
2021-12-27 06:32:24 +00:00
|
|
|
clip: true
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2022-04-07 02:08:47 +00:00
|
|
|
// scale animation on press
|
2023-03-31 06:05:27 +00:00
|
|
|
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
|
|
|
|
2021-12-27 23:02:41 +00:00
|
|
|
Item {
|
2021-10-18 03:50:59 +00:00
|
|
|
id: item
|
2021-12-27 23:02:41 +00:00
|
|
|
anchors.fill: parent
|
2021-12-27 18:07:34 +00:00
|
|
|
|
2023-03-06 06:38:43 +00:00
|
|
|
KWinComponents.WindowThumbnail {
|
|
|
|
|
id: thumbSource
|
|
|
|
|
wId: delegate.window.internalId
|
2021-12-28 00:01:01 +00:00
|
|
|
anchors.fill: parent
|
2023-03-06 06:38:43 +00:00
|
|
|
|
|
|
|
|
layer {
|
|
|
|
|
enabled: true
|
|
|
|
|
effect: ColorOverlay {
|
|
|
|
|
color: Qt.rgba(0, 0, 0, delegate.darken)
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-28 00:01:01 +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
|
|
|
|