shift-shell/components/mobileshell/qml/taskswitcher/Task.qml

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

203 lines
6.4 KiB
QML
Raw Normal View History

2015-06-21 19:18:02 +00:00
/*
2021-03-01 20:03:25 +00:00
* SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com>
2021-10-18 03:50:59 +00:00
* SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
2015-06-21 19:18:02 +00:00
*
2021-03-01 20:03:25 +00:00
* SPDX-License-Identifier: LGPL-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
import org.kde.taskmanager 0.1 as TaskManager
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
2015-06-21 19:18:02 +00:00
Item {
id: delegate
required property var model
required property var displaysModel
2021-10-18 03:50:59 +00:00
readonly property point taskScreenPoint: Qt.point(model.ScreenGeometry.x, model.ScreenGeometry.y)
readonly property real dragOffset: -control.y
2021-10-18 03:50:59 +00:00
property bool active: model.IsActive
required property real previewHeight
required property real previewWidth
property real scale: 1
opacity: 1 - dragOffset / window.height
//BEGIN functions
2020-07-28 10:30:13 +00:00
function syncDelegateGeometry() {
let pos = pipeWireLoader.mapToItem(tasksView, 0, 0);
2020-07-28 10:30:13 +00:00
if (window.visible) {
tasksModel.requestPublishDelegateGeometry(tasksModel.index(model.index, 0), Qt.rect(pos.x, pos.y, pipeWireLoader.width, pipeWireLoader.height), pipeWireLoader);
2020-07-28 10:30:13 +00:00
}
}
function closeApp() {
tasksModel.requestClose(tasksModel.index(model.index, 0));
}
function activateApp() {
window.activateWindow(model.index);
}
//END functions
Component.onCompleted: syncDelegateGeometry();
2020-07-28 10:30:13 +00:00
Connections {
target: window
function onVisibleChanged() {
syncDelegateGeometry();
}
}
2021-10-18 03:50:59 +00:00
QQC2.Control {
id: control
width: parent.width
height: parent.height
2021-10-31 19:21:02 +00:00
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
2021-10-18 03:50:59 +00:00
// drag up gesture
DragHandler {
id: dragHandler
target: parent
yAxis.enabled: true
xAxis.enabled: false
yAxis.maximum: 0
onActiveChanged: {
yAnimator.stop();
if (parent.y < -PlasmaCore.Units.gridUnit * 2) {
yAnimator.to = -window.height;
} else {
yAnimator.to = 0;
}
yAnimator.start();
2015-06-21 19:26:14 +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();
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-10-31 19:21:02 +00:00
contentItem: ColumnLayout {
id: column
spacing: 0
2021-10-18 03:50:59 +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
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
source: model.decoration
2015-06-21 19:18:02 +00:00
}
2021-10-18 03:50:59 +00:00
PlasmaComponents.Label {
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
elide: Text.ElideRight
text: model.AppName
color: "white"
2015-06-21 19:18:02 +00:00
}
2021-10-18 03:50:59 +00:00
Repeater {
id: rep
model: displaysModel
2021-10-18 03:50:59 +00:00
delegate: PlasmaComponents.ToolButton {
2021-10-31 19:21:02 +00:00
Layout.alignment: Qt.AlignVCenter
2021-10-18 03:50:59 +00:00
text: model.modelName
visible: model.position !== delegate.taskScreenPoint
display: rep.count < 3 ? QQC2.Button.IconOnly : QQC2.Button.TextBesideIcon
icon.name: "tv" //TODO provide a more adequate icon
2020-08-20 14:55:14 +00:00
2021-10-18 03:50:59 +00:00
onClicked: {
displaysModel.sendWindowToOutput(delegate.model.WinIdList[0], model.output)
2020-08-20 14:55:14 +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()
}
}
2021-10-31 19:21:02 +00:00
// app preview
2021-10-18 03:50:59 +00:00
QQC2.Control {
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
2021-10-18 03:50:59 +00:00
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
transform: Scale {
origin.x: item.width / 2
origin.y: item.height / 2
xScale: delegate.scale
yScale: delegate.scale
}
background: Rectangle {
color: PlasmaCore.Theme.backgroundColor
}
contentItem: Item {
id: item
2020-08-20 14:55:14 +00:00
Loader {
id: pipeWireLoader
2021-10-18 03:50:59 +00:00
anchors.fill: parent
2021-10-31 04:11:10 +00:00
source: Qt.resolvedUrl("./Thumbnail.qml")
2020-08-20 14:55:14 +00:00
onStatusChanged: {
if (status === Loader.Error) {
source = Qt.resolvedUrl("./TaskIcon.qml");
}
}
}
2021-10-18 03:50:59 +00:00
TapHandler {
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
}
}
}
}