2022-06-08 22:09:35 +00:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
*/
|
|
|
|
|
|
2023-03-05 02:40:06 +00:00
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Layouts
|
2023-05-12 23:43:49 +00:00
|
|
|
import QtQuick.Effects
|
2023-03-05 02:40:06 +00:00
|
|
|
import QtQuick.Controls as Controls
|
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
|
2023-03-05 02:40:06 +00:00
|
|
|
import org.kde.kquickcontrolsaddons
|
2022-06-08 22:09:35 +00:00
|
|
|
|
2023-03-05 02:40:06 +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-03-05 02:40:06 +00:00
|
|
|
import org.kde.private.mobile.homescreen.halcyon as Halcyon
|
2022-06-08 22:09:35 +00:00
|
|
|
|
2023-03-05 02:40:06 +00:00
|
|
|
import org.kde.kirigami as Kirigami
|
2022-06-08 22:09:35 +00:00
|
|
|
|
2022-07-13 01:02:04 +00:00
|
|
|
MouseArea {
|
2022-06-08 22:09:35 +00:00
|
|
|
id: delegate
|
|
|
|
|
width: GridView.view.cellWidth
|
|
|
|
|
height: GridView.view.cellHeight
|
|
|
|
|
|
2022-06-18 19:42:29 +00:00
|
|
|
property Halcyon.Application application: model.application
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2022-06-08 22:09:35 +00:00
|
|
|
property int reservedSpaceForLabel
|
|
|
|
|
property alias iconItem: icon
|
|
|
|
|
|
|
|
|
|
readonly property real margins: Math.floor(width * 0.2)
|
|
|
|
|
|
|
|
|
|
signal launch(int x, int y, var source, string title, string storageId)
|
2024-07-27 03:47:44 +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
|
|
|
}
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2022-06-28 17:26:36 +00:00
|
|
|
cursorShape: Qt.PointingHandCursor
|
2022-07-13 01:02:04 +00:00
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
2022-06-28 17:26:36 +00:00
|
|
|
onPressAndHold: openContextMenu()
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2022-06-08 22:09:35 +00:00
|
|
|
function launchApp() {
|
|
|
|
|
// launch app
|
2022-06-18 19:42:29 +00:00
|
|
|
if (application.running) {
|
|
|
|
|
delegate.launch(0, 0, "", application.name, application.storageId);
|
2022-06-08 22:09:35 +00:00
|
|
|
} else {
|
2023-07-25 01:13:52 +00:00
|
|
|
delegate.launch(delegate.x + (Kirigami.Units.smallSpacing * 2), delegate.y + (Kirigami.Units.smallSpacing * 2), icon.source, application.name, application.storageId);
|
2022-06-08 22:09:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2022-06-08 22:09:35 +00:00
|
|
|
Loader {
|
|
|
|
|
id: dialogLoader
|
|
|
|
|
active: false
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2023-03-08 11:53:01 +00:00
|
|
|
sourceComponent: PlasmaComponents.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
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2023-03-08 11:53:01 +00:00
|
|
|
PlasmaComponents.MenuItem {
|
|
|
|
|
icon.name: "emblem-favorite"
|
|
|
|
|
text: i18n("Add to favourites")
|
|
|
|
|
onClicked: {
|
|
|
|
|
Halcyon.PinnedModel.addApp(application.storageId, 0);
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// grow/shrink animation
|
|
|
|
|
property real zoomScale: 1
|
2024-07-27 03:47:44 +00:00
|
|
|
transform: Scale {
|
|
|
|
|
origin.x: delegate.width / 2;
|
|
|
|
|
origin.y: delegate.height / 2;
|
2022-06-08 22:09:35 +00:00
|
|
|
xScale: delegate.zoomScale
|
|
|
|
|
yScale: delegate.zoomScale
|
|
|
|
|
}
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2022-06-08 22:09:35 +00:00
|
|
|
property bool launchAppRequested: false
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2022-06-08 22:09:35 +00:00
|
|
|
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.8 : 1
|
2022-06-08 22:09:35 +00:00
|
|
|
onFinished: {
|
2022-06-28 17:26:36 +00:00
|
|
|
if (!delegate.pressed) {
|
2022-06-08 22:09:35 +00:00
|
|
|
growAnim.restart();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2022-06-08 22:09:35 +00:00
|
|
|
NumberAnimation on zoomScale {
|
|
|
|
|
id: growAnim
|
|
|
|
|
running: false
|
2023-03-18 19:28:17 +00:00
|
|
|
duration: ShellSettings.Settings.animationsEnabled ? 80 : 1
|
2022-06-08 22:09:35 +00:00
|
|
|
to: 1
|
|
|
|
|
onFinished: {
|
|
|
|
|
if (delegate.launchAppRequested) {
|
|
|
|
|
delegate.launchApp();
|
|
|
|
|
delegate.launchAppRequested = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2022-06-28 17:26:36 +00:00
|
|
|
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-03-31 06:05:27 +00:00
|
|
|
if (mouse.button === Qt.RightButton) {
|
|
|
|
|
openContextMenu();
|
|
|
|
|
} else {
|
|
|
|
|
launchAppRequested = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2022-06-08 22:09:35 +00:00
|
|
|
ColumnLayout {
|
|
|
|
|
anchors {
|
|
|
|
|
fill: parent
|
|
|
|
|
leftMargin: margins
|
|
|
|
|
topMargin: margins
|
|
|
|
|
rightMargin: margins
|
|
|
|
|
bottomMargin: margins
|
|
|
|
|
}
|
|
|
|
|
spacing: 0
|
|
|
|
|
|
2023-08-18 09:08:07 +00:00
|
|
|
Kirigami.Icon {
|
2022-06-08 22:09:35 +00:00
|
|
|
id: icon
|
|
|
|
|
|
2022-11-12 03:10:17 +00:00
|
|
|
Kirigami.Theme.inherit: false
|
|
|
|
|
Kirigami.Theme.colorSet: Kirigami.Theme.Complementary
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2022-06-08 22:09:35 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
|
|
|
|
|
Layout.fillWidth: true
|
2022-11-12 03:10:17 +00:00
|
|
|
Layout.preferredHeight: Math.floor(parent.height - delegate.reservedSpaceForLabel)
|
|
|
|
|
Layout.maximumHeight: labelFontMetrics.height * 7
|
|
|
|
|
Layout.topMargin: Math.max(0, Layout.preferredHeight - height)
|
2022-06-08 22:09:35 +00:00
|
|
|
|
2022-06-18 19:42:29 +00:00
|
|
|
source: application.icon
|
2022-06-08 22:09:35 +00:00
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
anchors {
|
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
|
bottom: parent.bottom
|
|
|
|
|
}
|
2022-06-18 19:42:29 +00:00
|
|
|
visible: application.running
|
2022-06-08 22:09:35 +00:00
|
|
|
radius: width
|
2023-07-25 01:13:52 +00:00
|
|
|
width: Kirigami.Units.smallSpacing
|
2022-06-08 22:09:35 +00:00
|
|
|
height: width
|
2023-09-27 04:08:49 +00:00
|
|
|
color: Kirigami.Theme.highlightColor
|
2022-06-08 22:09:35 +00:00
|
|
|
}
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2022-06-21 22:38:21 +00:00
|
|
|
// darken effect when hovered/pressed
|
|
|
|
|
layer {
|
2022-07-13 01:02:04 +00:00
|
|
|
enabled: delegate.pressed
|
2023-05-12 23:43:49 +00:00
|
|
|
effect: MultiEffect {
|
|
|
|
|
colorization: 1.0
|
|
|
|
|
colorizationColor: Qt.rgba(0, 0, 0, 0.3)
|
2022-06-21 22:38:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2022-11-12 03:10:17 +00:00
|
|
|
FontMetrics {
|
|
|
|
|
id: labelFontMetrics
|
|
|
|
|
font: label.font
|
|
|
|
|
}
|
2022-06-08 22:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlasmaComponents.Label {
|
|
|
|
|
id: label
|
|
|
|
|
visible: text.length > 0
|
|
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.preferredHeight: delegate.reservedSpaceForLabel
|
2023-07-25 01:13:52 +00:00
|
|
|
Layout.topMargin: Kirigami.Units.smallSpacing
|
|
|
|
|
Layout.leftMargin: -parent.anchors.leftMargin + Kirigami.Units.smallSpacing
|
|
|
|
|
Layout.rightMargin: -parent.anchors.rightMargin + Kirigami.Units.smallSpacing
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2022-06-24 19:31:46 +00:00
|
|
|
wrapMode: Text.WordWrap
|
2022-06-08 22:09:35 +00:00
|
|
|
maximumLineCount: 2
|
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
verticalAlignment: Text.AlignTop
|
|
|
|
|
elide: Text.ElideRight
|
|
|
|
|
|
2022-06-18 19:42:29 +00:00
|
|
|
text: application.name
|
2022-06-08 22:09:35 +00:00
|
|
|
|
2023-09-27 04:08:49 +00:00
|
|
|
font.pointSize: Kirigami.Theme.defaultFont.pointSize * 0.85
|
2022-06-08 22:09:35 +00:00
|
|
|
font.weight: Font.Bold
|
|
|
|
|
color: "white"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|