Warning, /plasma/plasma-mobile/containments/homescreens/halcyon/package/contents/ui/GridAppDelegate.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *  SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import QtQuick.Effects
0010 import QtQuick.Controls as Controls
0011 
0012 import org.kde.plasma.core as PlasmaCore
0013 import org.kde.plasma.components 3.0 as PlasmaComponents
0014 import org.kde.kquickcontrolsaddons
0015 
0016 import org.kde.plasma.private.mobileshell as MobileShell
0017 import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings
0018 import org.kde.private.mobile.homescreen.halcyon as Halcyon
0019 
0020 import org.kde.kirigami as Kirigami
0021 
0022 MouseArea {
0023     id: delegate
0024     width: GridView.view.cellWidth
0025     height: GridView.view.cellHeight
0026 
0027     property Halcyon.Application application: model.application
0028     
0029     property int reservedSpaceForLabel
0030     property alias iconItem: icon
0031 
0032     readonly property real margins: Math.floor(width * 0.2)
0033 
0034     signal launch(int x, int y, var source, string title, string storageId)
0035     
0036     function openContextMenu() {
0037         dialogLoader.active = true;
0038         dialogLoader.item.open();
0039     }
0040     
0041     cursorShape: Qt.PointingHandCursor
0042     acceptedButtons: Qt.LeftButton | Qt.RightButton
0043     onPressAndHold: openContextMenu()
0044     
0045     function launchApp() {
0046         // launch app
0047         if (application.running) {
0048             delegate.launch(0, 0, "", application.name, application.storageId);
0049         } else {
0050             delegate.launch(delegate.x + (Kirigami.Units.smallSpacing * 2), delegate.y + (Kirigami.Units.smallSpacing * 2), icon.source, application.name, application.storageId);
0051         }
0052     }
0053     
0054     Loader {
0055         id: dialogLoader
0056         active: false
0057         
0058         sourceComponent: PlasmaComponents.Menu {
0059             title: label.text
0060             closePolicy: PlasmaComponents.Menu.CloseOnReleaseOutside | PlasmaComponents.Menu.CloseOnEscape
0061             
0062             PlasmaComponents.MenuItem {
0063                 icon.name: "emblem-favorite"
0064                 text: i18n("Add to favourites")
0065                 onClicked: {
0066                     Halcyon.PinnedModel.addApp(application.storageId, 0);
0067                 }
0068             }
0069             onClosed: dialogLoader.active = false
0070         }
0071     }
0072 
0073     // grow/shrink animation
0074     property real zoomScale: 1
0075     transform: Scale { 
0076         origin.x: delegate.width / 2; 
0077         origin.y: delegate.height / 2; 
0078         xScale: delegate.zoomScale
0079         yScale: delegate.zoomScale
0080     }
0081     
0082     property bool launchAppRequested: false
0083     
0084     NumberAnimation on zoomScale {
0085         id: shrinkAnim
0086         running: false
0087         duration: ShellSettings.Settings.animationsEnabled ? 80 : 1
0088         to: ShellSettings.Settings.animationsEnabled ? 0.8 : 1
0089         onFinished: {
0090             if (!delegate.pressed) {
0091                 growAnim.restart();
0092             }
0093         }
0094     }
0095     
0096     NumberAnimation on zoomScale {
0097         id: growAnim
0098         running: false
0099         duration: ShellSettings.Settings.animationsEnabled ? 80 : 1
0100         to: 1
0101         onFinished: {
0102             if (delegate.launchAppRequested) {
0103                 delegate.launchApp();
0104                 delegate.launchAppRequested = false;
0105             }
0106         }
0107     }
0108     
0109     onPressedChanged: {
0110         if (pressed) {
0111             growAnim.stop();
0112             shrinkAnim.restart();
0113         } else if (!pressed && !shrinkAnim.running) {
0114             growAnim.restart();
0115         }
0116     }
0117     // launch app handled by press animation
0118     onClicked: mouse => {
0119         if (mouse.button === Qt.RightButton) {
0120             openContextMenu();
0121         } else {
0122             launchAppRequested = true;
0123         }
0124     }
0125     
0126     ColumnLayout {
0127         anchors {
0128             fill: parent
0129             leftMargin: margins
0130             topMargin: margins
0131             rightMargin: margins
0132             bottomMargin: margins
0133         }
0134         spacing: 0
0135 
0136         Kirigami.Icon {
0137             id: icon
0138 
0139             Kirigami.Theme.inherit: false
0140             Kirigami.Theme.colorSet: Kirigami.Theme.Complementary
0141             
0142             Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
0143             Layout.fillWidth: true
0144             Layout.preferredHeight: Math.floor(parent.height - delegate.reservedSpaceForLabel)
0145             Layout.maximumHeight: labelFontMetrics.height * 7
0146             Layout.topMargin: Math.max(0, Layout.preferredHeight - height)
0147 
0148             source: application.icon
0149 
0150             Rectangle {
0151                 anchors {
0152                     horizontalCenter: parent.horizontalCenter
0153                     bottom: parent.bottom
0154                 }
0155                 visible: application.running
0156                 radius: width
0157                 width: Kirigami.Units.smallSpacing
0158                 height: width
0159                 color: Kirigami.Theme.highlightColor
0160             }
0161             
0162             // darken effect when hovered/pressed
0163             layer {
0164                 enabled: delegate.pressed
0165                 effect: MultiEffect {
0166                     colorization: 1.0
0167                     colorizationColor: Qt.rgba(0, 0, 0, 0.3)
0168                 }
0169             }
0170             
0171             FontMetrics {
0172                 id: labelFontMetrics
0173                 font: label.font
0174             }
0175         }
0176 
0177         PlasmaComponents.Label {
0178             id: label
0179             visible: text.length > 0
0180 
0181             Layout.fillWidth: true
0182             Layout.preferredHeight: delegate.reservedSpaceForLabel
0183             Layout.topMargin: Kirigami.Units.smallSpacing
0184             Layout.leftMargin: -parent.anchors.leftMargin + Kirigami.Units.smallSpacing
0185             Layout.rightMargin: -parent.anchors.rightMargin + Kirigami.Units.smallSpacing
0186             
0187             wrapMode: Text.WordWrap
0188             maximumLineCount: 2
0189             horizontalAlignment: Text.AlignHCenter
0190             verticalAlignment: Text.AlignTop
0191             elide: Text.ElideRight
0192 
0193             text: application.name
0194 
0195             font.pointSize: Kirigami.Theme.defaultFont.pointSize * 0.85
0196             font.weight: Font.Bold
0197             color: "white"
0198         }
0199     }
0200 }
0201 
0202