2022-06-08 22:09:35 +00:00
|
|
|
// SPDX-FileCopyrightText: 2022 Devin Lin <espidev@gmail.com>
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
2022-06-28 14:51:57 +00:00
|
|
|
import QtQuick 2.15
|
2022-06-08 22:09:35 +00:00
|
|
|
import QtQuick.Layouts 1.1
|
|
|
|
|
import QtQuick.Controls 2.3 as Controls
|
|
|
|
|
import QtGraphicalEffects 1.6
|
|
|
|
|
|
|
|
|
|
import org.kde.plasma.plasmoid 2.0
|
|
|
|
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
|
|
|
|
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
|
|
|
|
|
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
|
2022-06-18 19:42:29 +00:00
|
|
|
import org.kde.phone.homescreen.halcyon 1.0 as Halcyon
|
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
|
2022-06-29 04:22:42 +00:00
|
|
|
property int visualIndex: 0
|
|
|
|
|
|
|
|
|
|
property real leftPadding
|
|
|
|
|
property real rightPadding
|
2022-06-18 19:42:29 +00:00
|
|
|
|
2022-07-09 16:05:58 +00:00
|
|
|
property real dragFolderAnimationProgress: 0
|
|
|
|
|
|
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-07-11 01:08:03 +00:00
|
|
|
signal removeRequested()
|
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) {
|
|
|
|
|
dialogLoader.item.close()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onYChanged: {
|
|
|
|
|
if (dialogLoader.item) {
|
|
|
|
|
dialogLoader.item.close()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 22:38:21 +00:00
|
|
|
function openContextMenu() {
|
2022-06-08 22:09:35 +00:00
|
|
|
dialogLoader.active = true;
|
|
|
|
|
dialogLoader.item.open();
|
|
|
|
|
}
|
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 {
|
|
|
|
|
launchAppWithAnim(delegate.x + (PlasmaCore.Units.smallSpacing * 2), delegate.y + (PlasmaCore.Units.smallSpacing * 2), iconLoader.source, applicationName, applicationStorageId);
|
|
|
|
|
}
|
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 !== "") {
|
|
|
|
|
MobileShell.HomeScreenControls.openAppLaunchAnimation(
|
|
|
|
|
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);
|
|
|
|
|
application.runApplication();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-08 22:09:35 +00:00
|
|
|
Loader {
|
|
|
|
|
id: dialogLoader
|
|
|
|
|
active: false
|
|
|
|
|
|
|
|
|
|
sourceComponent: PlasmaComponents.Menu {
|
|
|
|
|
title: label.text
|
2022-06-21 22:38:21 +00:00
|
|
|
closePolicy: PlasmaComponents.Menu.CloseOnReleaseOutside | PlasmaComponents.Menu.CloseOnEscape
|
2022-06-08 22:09:35 +00:00
|
|
|
|
|
|
|
|
PlasmaComponents.MenuItem {
|
|
|
|
|
icon.name: "emblem-favorite"
|
|
|
|
|
text: i18n("Remove from favourites")
|
2022-07-11 01:08:03 +00:00
|
|
|
onClicked: delegate.removeRequested()
|
2022-06-08 22:09:35 +00:00
|
|
|
}
|
|
|
|
|
onClosed: dialogLoader.active = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
anchors.leftMargin: delegate.leftPadding
|
|
|
|
|
anchors.rightMargin: delegate.rightPadding
|
|
|
|
|
|
|
|
|
|
property bool inDrag: false
|
|
|
|
|
|
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
|
onClicked: (mouse.button === Qt.RightButton) ? openContextMenu() : launch();
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
HoverHandler {
|
|
|
|
|
id: hoverHandler
|
|
|
|
|
acceptedDevices: PointerDevice.Mouse
|
|
|
|
|
acceptedPointerTypes: PointerDevice.GenericPointer
|
|
|
|
|
}
|
2022-06-29 04:22:42 +00:00
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
radius: height / 2
|
2022-07-09 02:00:17 +00:00
|
|
|
color: mouseArea.pressed ? Qt.rgba(255, 255, 255, 0.2) : (hoverHandler.hovered ? Qt.rgba(255, 255, 255, 0.1) : "transparent")
|
2022-06-23 22:14:12 +00:00
|
|
|
}
|
2022-06-29 04:22:42 +00:00
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
|
id: rowLayout
|
|
|
|
|
anchors {
|
|
|
|
|
fill: parent
|
2022-07-09 02:00:17 +00:00
|
|
|
leftMargin: PlasmaCore.Units.smallSpacing * 2
|
2022-06-29 04:22:42 +00:00
|
|
|
topMargin: PlasmaCore.Units.smallSpacing
|
2022-07-09 02:00:17 +00:00
|
|
|
rightMargin: PlasmaCore.Units.smallSpacing * 2
|
2022-06-29 04:22:42 +00:00
|
|
|
bottomMargin: PlasmaCore.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
|
|
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.leftMargin: PlasmaCore.Units.smallSpacing * 2
|
|
|
|
|
Layout.rightMargin: PlasmaCore.Units.largeSpacing
|
|
|
|
|
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
|
|
|
|
|
|
|
|
font.pointSize: PlasmaCore.Theme.defaultFont.pointSize
|
|
|
|
|
font.weight: Font.Bold
|
|
|
|
|
color: "white"
|
|
|
|
|
|
|
|
|
|
layer.enabled: true
|
|
|
|
|
layer.effect: DropShadow {
|
|
|
|
|
verticalOffset: 1
|
|
|
|
|
radius: 4
|
|
|
|
|
samples: 6
|
|
|
|
|
color: Qt.rgba(0, 0, 0, 0.5)
|
|
|
|
|
}
|
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
|
|
|
|
|
layer.effect: DropShadow {
|
|
|
|
|
verticalOffset: 1
|
|
|
|
|
radius: 4
|
|
|
|
|
samples: 6
|
|
|
|
|
color: Qt.rgba(0, 0, 0, 0.5)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
anchors.margins: PlasmaCore.Units.smallSpacing
|
|
|
|
|
color: Qt.rgba(255, 255, 255, 0.2)
|
|
|
|
|
radius: PlasmaCore.Units.smallSpacing
|
|
|
|
|
opacity: delegate.dragFolderAnimationProgress
|
2022-06-30 04:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-09 16:05:58 +00:00
|
|
|
PlasmaCore.IconItem {
|
|
|
|
|
id: icon
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
usesPlasmaTheme: false
|
|
|
|
|
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
|
|
|
|
|
width: PlasmaCore.Units.smallSpacing
|
|
|
|
|
height: width
|
|
|
|
|
color: PlasmaCore.Theme.highlightColor
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layer.enabled: true
|
|
|
|
|
layer.effect: DropShadow {
|
|
|
|
|
verticalOffset: 1
|
|
|
|
|
radius: 4
|
|
|
|
|
samples: 6
|
|
|
|
|
color: Qt.rgba(0, 0, 0, 0.5)
|
|
|
|
|
}
|
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
|
|
|
|
|
anchors.margins: PlasmaCore.Units.smallSpacing
|
|
|
|
|
color: Qt.rgba(255, 255, 255, 0.2)
|
|
|
|
|
radius: PlasmaCore.Units.smallSpacing
|
|
|
|
|
|
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
|
|
|
|
|
anchors.margins: PlasmaCore.Units.smallSpacing * 2
|
|
|
|
|
columns: 2
|
|
|
|
|
spacing: PlasmaCore.Units.smallSpacing
|
|
|
|
|
|
|
|
|
|
property var previews: model.folder.appPreviews
|
|
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
|
model: grid.previews
|
|
|
|
|
delegate: Kirigami.Icon {
|
|
|
|
|
implicitWidth: (grid.width - PlasmaCore.Units.smallSpacing) / 2
|
|
|
|
|
implicitHeight: (grid.width - PlasmaCore.Units.smallSpacing) / 2
|
|
|
|
|
source: modelData.icon
|
|
|
|
|
|
|
|
|
|
layer.enabled: true
|
|
|
|
|
layer.effect: DropShadow {
|
|
|
|
|
verticalOffset: 1
|
|
|
|
|
radius: 4
|
|
|
|
|
samples: 3
|
|
|
|
|
color: Qt.rgba(0, 0, 0, 0.5)
|
2022-06-30 04:40:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-08 22:09:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|