2022-06-08 22:09:35 +00:00
|
|
|
// SPDX-FileCopyrightText: 2022 Devin Lin <espidev@gmail.com>
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
2023-03-05 02:40:06 +00:00
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Layouts
|
|
|
|
|
import QtQuick.Controls as Controls
|
2023-05-12 23:43:49 +00:00
|
|
|
import QtQuick.Effects
|
2022-06-08 22:09:35 +00:00
|
|
|
|
2023-03-05 02:40:06 +00:00
|
|
|
import org.kde.plasma.core as PlasmaCore
|
2022-06-08 22:09:35 +00:00
|
|
|
import org.kde.plasma.components 3.0 as PlasmaComponents
|
|
|
|
|
import org.kde.kquickcontrolsaddons 2.0
|
|
|
|
|
|
|
|
|
|
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
|
2023-11-02 11:08:17 +00:00
|
|
|
import org.kde.plasma.private.mobileshell as MobileShell
|
2023-03-18 19:28:17 +00:00
|
|
|
import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings
|
2023-11-02 11:08:17 +00:00
|
|
|
import org.kde.plasma.private.mobileshell.state as MobileShellState
|
2022-06-08 22:09:35 +00:00
|
|
|
|
|
|
|
|
import org.kde.kirigami 2.19 as Kirigami
|
|
|
|
|
|
2022-07-09 02:00:17 +00:00
|
|
|
Item {
|
2022-06-08 22:09:35 +00:00
|
|
|
id: delegate
|
2023-04-12 03:50:04 +00:00
|
|
|
|
2022-06-29 04:22:42 +00:00
|
|
|
property int visualIndex: 0
|
2022-07-09 16:05:58 +00:00
|
|
|
property real dragFolderAnimationProgress: 0
|
|
|
|
|
|
2022-07-11 02:49:55 +00:00
|
|
|
property list<Kirigami.Action> menuActions
|
|
|
|
|
|
2022-06-30 04:40:22 +00:00
|
|
|
// whether this delegate is a folder
|
|
|
|
|
property bool isFolder
|
|
|
|
|
|
|
|
|
|
// folder object
|
|
|
|
|
property var folder
|
|
|
|
|
readonly property string folderName: folder ? folder.name : ""
|
2022-06-18 19:42:29 +00:00
|
|
|
|
2022-06-30 04:40:22 +00:00
|
|
|
// app object
|
|
|
|
|
property var application
|
2022-06-18 19:42:29 +00:00
|
|
|
readonly property string applicationName: application ? application.name : ""
|
|
|
|
|
readonly property string applicationStorageId: application ? application.storageId : ""
|
|
|
|
|
readonly property string applicationIcon: application ? application.icon : ""
|
2022-06-08 22:09:35 +00:00
|
|
|
|
2022-06-30 04:40:22 +00:00
|
|
|
signal folderOpenRequested()
|
2022-06-08 22:09:35 +00:00
|
|
|
|
2022-07-09 02:00:17 +00:00
|
|
|
property alias drag: mouseArea.drag
|
|
|
|
|
Drag.active: delegate.drag.active
|
|
|
|
|
Drag.source: delegate
|
|
|
|
|
Drag.hotSpot.x: delegate.width / 2
|
|
|
|
|
Drag.hotSpot.y: delegate.height / 2
|
|
|
|
|
|
2022-07-09 16:05:58 +00:00
|
|
|
// close context menu if drag move
|
|
|
|
|
onXChanged: {
|
|
|
|
|
if (dialogLoader.item) {
|
2023-03-08 11:53:01 +00:00
|
|
|
dialogLoader.item.close()
|
2022-07-09 16:05:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onYChanged: {
|
|
|
|
|
if (dialogLoader.item) {
|
2023-03-08 11:53:01 +00:00
|
|
|
dialogLoader.item.close()
|
2022-07-09 16:05:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 22:38:21 +00:00
|
|
|
function openContextMenu() {
|
2022-06-08 22:09:35 +00:00
|
|
|
dialogLoader.active = true;
|
2023-03-08 11:53:01 +00:00
|
|
|
dialogLoader.item.open();
|
2022-06-08 22:09:35 +00:00
|
|
|
}
|
2022-06-21 22:38:21 +00:00
|
|
|
|
2022-06-30 04:40:22 +00:00
|
|
|
function launch() {
|
|
|
|
|
if (isFolder) {
|
|
|
|
|
folderOpenRequested();
|
2022-06-08 22:09:35 +00:00
|
|
|
} else {
|
2022-06-30 04:40:22 +00:00
|
|
|
if (application.running) {
|
|
|
|
|
launchAppWithAnim(0, 0, "", applicationName, applicationStorageId);
|
|
|
|
|
} else {
|
2023-07-25 01:13:52 +00:00
|
|
|
launchAppWithAnim(delegate.x + (Kirigami.Units.smallSpacing * 2), delegate.y + (Kirigami.Units.smallSpacing * 2), delegate.applicationIcon, applicationName, applicationStorageId);
|
2022-06-30 04:40:22 +00:00
|
|
|
}
|
2022-06-08 22:09:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-30 04:40:22 +00:00
|
|
|
function launchAppWithAnim(x: int, y: int, source, title: string, storageId: string) {
|
|
|
|
|
if (source !== "") {
|
2023-03-20 01:32:19 +00:00
|
|
|
MobileShellState.ShellDBusClient.openAppLaunchAnimation(
|
2022-06-30 04:40:22 +00:00
|
|
|
source,
|
|
|
|
|
title,
|
|
|
|
|
iconLoader.Kirigami.ScenePosition.x + iconLoader.width/2,
|
|
|
|
|
iconLoader.Kirigami.ScenePosition.y + iconLoader.height/2,
|
|
|
|
|
Math.min(iconLoader.width, iconLoader.height));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
application.setMinimizedDelegate(delegate);
|
2023-03-15 06:29:46 +00:00
|
|
|
MobileShell.AppLaunch.launchOrActivateApp(application.storageId);
|
2022-06-30 04:40:22 +00:00
|
|
|
}
|
2023-03-08 11:53:01 +00:00
|
|
|
|
2022-06-08 22:09:35 +00:00
|
|
|
Loader {
|
|
|
|
|
id: dialogLoader
|
|
|
|
|
active: false
|
|
|
|
|
|
2023-03-08 11:53:01 +00:00
|
|
|
sourceComponent: PlasmaComponents.Menu {
|
|
|
|
|
id: menu
|
2022-06-08 22:09:35 +00:00
|
|
|
title: label.text
|
2023-03-08 11:53:01 +00:00
|
|
|
closePolicy: PlasmaComponents.Menu.CloseOnReleaseOutside | PlasmaComponents.Menu.CloseOnEscape
|
|
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
|
model: menuActions
|
|
|
|
|
delegate: PlasmaComponents.MenuItem {
|
|
|
|
|
icon.name: modelData.iconName
|
|
|
|
|
text: modelData.text
|
|
|
|
|
onClicked: modelData.triggered()
|
2022-07-11 02:49:55 +00:00
|
|
|
}
|
2022-06-08 22:09:35 +00:00
|
|
|
}
|
2023-03-08 11:53:01 +00:00
|
|
|
|
|
|
|
|
onClosed: dialogLoader.active = false
|
2022-06-08 22:09:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-09 02:00:17 +00:00
|
|
|
MouseArea {
|
|
|
|
|
id: mouseArea
|
|
|
|
|
|
2022-06-23 22:14:12 +00:00
|
|
|
anchors.fill: parent
|
2022-07-09 02:00:17 +00:00
|
|
|
|
|
|
|
|
property bool inDrag: false
|
|
|
|
|
|
2022-07-13 01:02:04 +00:00
|
|
|
cursorShape: Qt.PointingHandCursor
|
2022-07-09 02:00:17 +00:00
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
|
onReleased: {
|
2022-07-09 16:05:58 +00:00
|
|
|
delegate.Drag.drop();
|
2022-07-09 02:00:17 +00:00
|
|
|
inDrag = false;
|
|
|
|
|
}
|
|
|
|
|
onPressAndHold: { inDrag = true; openContextMenu() }
|
|
|
|
|
drag.target: inDrag ? delegate : undefined
|
|
|
|
|
|
2022-07-13 01:02:04 +00:00
|
|
|
// grow/shrink animation
|
|
|
|
|
property real zoomScale: 1
|
2023-04-11 05:16:43 +00:00
|
|
|
transform: Scale {
|
2022-07-13 01:02:04 +00:00
|
|
|
origin.x: mouseArea.width / 2;
|
|
|
|
|
origin.y: mouseArea.height / 2;
|
|
|
|
|
xScale: mouseArea.zoomScale
|
|
|
|
|
yScale: mouseArea.zoomScale
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
property bool launchAppRequested: false
|
|
|
|
|
|
|
|
|
|
NumberAnimation on zoomScale {
|
|
|
|
|
id: shrinkAnim
|
|
|
|
|
running: false
|
2023-03-18 19:28:17 +00:00
|
|
|
duration: ShellSettings.Settings.animationsEnabled ? 80 : 1
|
|
|
|
|
to: ShellSettings.Settings.animationsEnabled ? 0.95 : 1
|
2022-07-13 01:02:04 +00:00
|
|
|
onFinished: {
|
|
|
|
|
if (!mouseArea.pressed) {
|
|
|
|
|
growAnim.restart();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NumberAnimation on zoomScale {
|
|
|
|
|
id: growAnim
|
|
|
|
|
running: false
|
2023-03-18 19:28:17 +00:00
|
|
|
duration: ShellSettings.Settings.animationsEnabled ? 80 : 1
|
2022-07-13 01:02:04 +00:00
|
|
|
to: 1
|
|
|
|
|
onFinished: {
|
|
|
|
|
if (mouseArea.launchAppRequested) {
|
|
|
|
|
delegate.launch();
|
|
|
|
|
mouseArea.launchAppRequested = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onPressedChanged: {
|
|
|
|
|
if (pressed) {
|
|
|
|
|
growAnim.stop();
|
|
|
|
|
shrinkAnim.restart();
|
|
|
|
|
} else if (!pressed && !shrinkAnim.running) {
|
|
|
|
|
growAnim.restart();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// launch app handled by press animation
|
2023-03-06 13:09:54 +00:00
|
|
|
onClicked: mouse => {
|
2023-04-11 05:16:43 +00:00
|
|
|
if (mouse.button === Qt.RightButton) {
|
|
|
|
|
openContextMenu();
|
|
|
|
|
} else {
|
|
|
|
|
launchAppRequested = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-13 01:02:04 +00:00
|
|
|
|
2022-07-09 02:00:17 +00:00
|
|
|
HoverHandler {
|
|
|
|
|
id: hoverHandler
|
|
|
|
|
acceptedDevices: PointerDevice.Mouse
|
2023-03-06 21:32:37 +00:00
|
|
|
acceptedPointerTypes: PointerDevice.Generic
|
2022-07-09 02:00:17 +00:00
|
|
|
}
|
2022-06-29 04:22:42 +00:00
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
radius: height / 2
|
2022-07-13 01:02:04 +00:00
|
|
|
color: mouseArea.pressed ? Qt.rgba(255, 255, 255, 0.2) : "transparent"
|
2022-06-23 22:14:12 +00:00
|
|
|
}
|
2022-06-29 04:22:42 +00:00
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
|
id: rowLayout
|
|
|
|
|
anchors {
|
|
|
|
|
fill: parent
|
2023-07-25 01:13:52 +00:00
|
|
|
leftMargin: Kirigami.Units.smallSpacing * 2
|
|
|
|
|
topMargin: Kirigami.Units.smallSpacing
|
|
|
|
|
rightMargin: Kirigami.Units.smallSpacing * 2
|
|
|
|
|
bottomMargin: Kirigami.Units.smallSpacing
|
2022-06-23 22:14:12 +00:00
|
|
|
}
|
2022-06-29 04:22:42 +00:00
|
|
|
spacing: 0
|
|
|
|
|
|
2022-06-30 04:40:22 +00:00
|
|
|
Loader {
|
|
|
|
|
id: iconLoader
|
2022-06-29 04:22:42 +00:00
|
|
|
Layout.alignment: Qt.AlignLeft
|
|
|
|
|
Layout.minimumWidth: Layout.minimumHeight
|
|
|
|
|
Layout.preferredWidth: Layout.minimumHeight
|
|
|
|
|
Layout.minimumHeight: parent.height
|
|
|
|
|
Layout.preferredHeight: Layout.minimumHeight
|
|
|
|
|
|
2022-06-30 04:40:22 +00:00
|
|
|
sourceComponent: delegate.isFolder ? folderIconComponent : appIconComponent
|
2022-06-08 22:09:35 +00:00
|
|
|
}
|
2022-06-23 22:14:12 +00:00
|
|
|
|
2022-06-29 04:22:42 +00:00
|
|
|
PlasmaComponents.Label {
|
|
|
|
|
id: label
|
|
|
|
|
visible: text.length > 0
|
2022-07-12 04:21:14 +00:00
|
|
|
textFormat: Text.MarkdownText
|
2022-06-29 04:22:42 +00:00
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2023-07-25 01:13:52 +00:00
|
|
|
Layout.leftMargin: Kirigami.Units.smallSpacing * 2
|
|
|
|
|
Layout.rightMargin: Kirigami.Units.gridUnit
|
2022-06-29 04:22:42 +00:00
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
|
maximumLineCount: 1
|
|
|
|
|
elide: Text.ElideRight
|
|
|
|
|
|
2022-06-30 04:40:22 +00:00
|
|
|
text: delegate.isFolder ? delegate.folderName : delegate.applicationName
|
2022-06-29 04:22:42 +00:00
|
|
|
|
2023-07-25 01:13:52 +00:00
|
|
|
font.pointSize: Kirigami.Theme.defaultFont.pointSize
|
2022-06-29 04:22:42 +00:00
|
|
|
font.weight: Font.Bold
|
|
|
|
|
color: "white"
|
|
|
|
|
|
|
|
|
|
layer.enabled: true
|
2023-05-12 23:43:49 +00:00
|
|
|
layer.effect: MobileShell.TextDropShadow {}
|
2022-06-08 22:09:35 +00:00
|
|
|
}
|
2022-06-30 04:40:22 +00:00
|
|
|
|
|
|
|
|
Kirigami.Icon {
|
|
|
|
|
Layout.alignment: Qt.AlignRight
|
2022-07-01 04:00:15 +00:00
|
|
|
Layout.preferredWidth: Kirigami.Units.iconSizes.small
|
|
|
|
|
Layout.preferredHeight: Kirigami.Units.iconSizes.small
|
2022-06-30 04:40:22 +00:00
|
|
|
|
|
|
|
|
isMask: true
|
|
|
|
|
color: 'white'
|
|
|
|
|
source: 'arrow-right'
|
|
|
|
|
visible: delegate.isFolder
|
|
|
|
|
|
|
|
|
|
layer.enabled: true
|
2023-05-12 23:43:49 +00:00
|
|
|
layer.effect: MultiEffect {
|
|
|
|
|
shadowEnabled: true
|
|
|
|
|
shadowVerticalOffset: 1
|
|
|
|
|
blurMax: 8
|
|
|
|
|
shadowOpacity: 0.7
|
2022-06-30 04:40:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Component {
|
|
|
|
|
id: appIconComponent
|
|
|
|
|
|
2022-07-09 16:05:58 +00:00
|
|
|
Item {
|
2022-06-30 04:40:22 +00:00
|
|
|
Rectangle {
|
2022-07-09 16:05:58 +00:00
|
|
|
anchors.fill: parent
|
2023-07-25 01:13:52 +00:00
|
|
|
anchors.margins: Kirigami.Units.smallSpacing
|
2022-07-09 16:05:58 +00:00
|
|
|
color: Qt.rgba(255, 255, 255, 0.2)
|
2023-07-25 01:13:52 +00:00
|
|
|
radius: Kirigami.Units.smallSpacing
|
2022-07-09 16:05:58 +00:00
|
|
|
opacity: delegate.dragFolderAnimationProgress
|
2022-06-30 04:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-18 09:08:07 +00:00
|
|
|
Kirigami.Icon {
|
2022-07-09 16:05:58 +00:00
|
|
|
id: icon
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
source: delegate.isFolder ? 'document-open-folder' : delegate.applicationIcon
|
|
|
|
|
|
|
|
|
|
transform: Scale {
|
|
|
|
|
origin.x: icon.width / 2
|
|
|
|
|
origin.y: icon.height / 2
|
|
|
|
|
xScale: 1 - delegate.dragFolderAnimationProgress * 0.5
|
|
|
|
|
yScale: 1 - delegate.dragFolderAnimationProgress * 0.5
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
anchors {
|
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
|
bottom: parent.bottom
|
|
|
|
|
}
|
|
|
|
|
visible: application ? application.running : false
|
|
|
|
|
radius: width
|
2023-07-25 01:13:52 +00:00
|
|
|
width: Kirigami.Units.smallSpacing
|
2022-07-09 16:05:58 +00:00
|
|
|
height: width
|
2023-07-25 01:13:52 +00:00
|
|
|
color: Kirigami.Theme.highlightColor
|
2022-07-09 16:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layer.enabled: true
|
2023-05-12 23:43:49 +00:00
|
|
|
layer.effect: MultiEffect {
|
|
|
|
|
shadowEnabled: true
|
|
|
|
|
shadowVerticalOffset: 1
|
|
|
|
|
blurMax: 16
|
|
|
|
|
shadowOpacity: 0.5
|
2022-07-09 16:05:58 +00:00
|
|
|
}
|
2022-06-30 04:40:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Component {
|
|
|
|
|
id: folderIconComponent
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
Rectangle {
|
2022-07-09 16:05:58 +00:00
|
|
|
id: rect
|
2022-06-30 04:40:22 +00:00
|
|
|
anchors.fill: parent
|
2023-07-25 01:13:52 +00:00
|
|
|
anchors.margins: Kirigami.Units.smallSpacing
|
2022-06-30 04:40:22 +00:00
|
|
|
color: Qt.rgba(255, 255, 255, 0.2)
|
2023-07-25 01:13:52 +00:00
|
|
|
radius: Kirigami.Units.smallSpacing
|
2022-06-30 04:40:22 +00:00
|
|
|
|
2022-07-09 16:05:58 +00:00
|
|
|
transform: Scale {
|
|
|
|
|
origin.x: rect.width / 2
|
|
|
|
|
origin.y: rect.height / 2
|
|
|
|
|
xScale: 1 + delegate.dragFolderAnimationProgress * 0.5
|
|
|
|
|
yScale: 1 + delegate.dragFolderAnimationProgress * 0.5
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Grid {
|
|
|
|
|
id: grid
|
|
|
|
|
anchors.fill: parent
|
2023-07-25 01:13:52 +00:00
|
|
|
anchors.margins: Kirigami.Units.smallSpacing * 2
|
2022-07-09 16:05:58 +00:00
|
|
|
columns: 2
|
2023-07-25 01:13:52 +00:00
|
|
|
spacing: Kirigami.Units.smallSpacing
|
2022-07-09 16:05:58 +00:00
|
|
|
|
|
|
|
|
property var previews: model.folder.appPreviews
|
|
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
|
model: grid.previews
|
|
|
|
|
delegate: Kirigami.Icon {
|
2023-07-25 01:13:52 +00:00
|
|
|
implicitWidth: (grid.width - Kirigami.Units.smallSpacing) / 2
|
|
|
|
|
implicitHeight: (grid.width - Kirigami.Units.smallSpacing) / 2
|
2022-07-09 16:05:58 +00:00
|
|
|
source: modelData.icon
|
|
|
|
|
|
|
|
|
|
layer.enabled: true
|
2023-05-12 23:43:49 +00:00
|
|
|
layer.effect: MultiEffect {
|
|
|
|
|
shadowEnabled: true
|
|
|
|
|
shadowVerticalOffset: 1
|
|
|
|
|
blurMax: 16
|
|
|
|
|
shadowOpacity: 0.6
|
2022-06-30 04:40:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-08 22:09:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|