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

0001 // SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 import QtQuick 2.12
0005 import QtQuick.Window 2.12
0006 import QtQuick.Layouts 1.1
0007 
0008 import org.kde.plasma.components 3.0 as PC3
0009 import org.kde.plasma.private.mobileshell.state as MobileShellState
0010 import org.kde.private.mobile.homescreen.folio 1.0 as Folio
0011 import org.kde.plasma.private.mobileshell as MobileShell
0012 import org.kde.kirigami 2.10 as Kirigami
0013 
0014 import "./delegate"
0015 
0016 MouseArea {
0017     id: root
0018 
0019     property var homeScreen
0020 
0021     // use to account for x-y positioning, because delegate x and y will include the screen margins
0022     property real leftMargin
0023     property real topMargin
0024 
0025     signal delegateDragRequested(var item)
0026 
0027     onPressAndHold: Folio.HomeScreenState.openSettingsView()
0028 
0029     Repeater {
0030         model: Folio.FavouritesModel
0031 
0032         delegate: Item {
0033             id: delegate
0034 
0035             property var delegateModel: model.delegate
0036             property int index: model.index
0037 
0038             property var dragState: Folio.HomeScreenState.dragState
0039             property bool isDropPositionThis: dragState.candidateDropPosition.location === Folio.DelegateDragPosition.Favourites &&
0040                                               dragState.candidateDropPosition.favouritesPosition === delegate.index
0041             property bool isAppHoveredOver: Folio.HomeScreenState.swipeState === Folio.HomeScreenState.DraggingDelegate &&
0042                                             dragState.dropDelegate &&
0043                                             dragState.dropDelegate.type === Folio.FolioDelegate.Application &&
0044                                             isDropPositionThis
0045 
0046             // only one of them will be used, because of the anchors below
0047             // this is used due to the ability for the favourites bar to be in multiple locations
0048             x: model.xPosition - leftMargin
0049             y: model.xPosition - topMargin
0050 
0051             anchors.verticalCenter: Folio.HomeScreenState.favouritesBarLocation === Folio.HomeScreenState.Bottom ? parent.verticalCenter : undefined
0052             anchors.horizontalCenter: Folio.HomeScreenState.favouritesBarLocation === Folio.HomeScreenState.Bottom ? undefined : parent.horizontalCenter
0053 
0054             Behavior on x {
0055                 NumberAnimation { duration: 250; easing.type: Easing.InOutQuad }
0056             }
0057             Behavior on y {
0058                 NumberAnimation { duration: 250; easing.type: Easing.InOutQuad }
0059             }
0060 
0061             implicitWidth: Folio.HomeScreenState.pageCellWidth
0062             implicitHeight: Folio.HomeScreenState.pageCellHeight
0063             width: Folio.HomeScreenState.pageCellWidth
0064             height: Folio.HomeScreenState.pageCellHeight
0065 
0066             Loader {
0067                 anchors.fill: parent
0068 
0069                 sourceComponent: {
0070                     if (delegate.delegateModel.type === Folio.FolioDelegate.Application) {
0071                         return appComponent;
0072                     } else if (delegate.delegateModel.type === Folio.FolioDelegate.Folder) {
0073                         return folderComponent;
0074                     } else {
0075                         // ghost entry
0076                         return placeholderComponent;
0077                     }
0078                 }
0079             }
0080 
0081             Component {
0082                 id: placeholderComponent
0083 
0084                 Item {}
0085             }
0086 
0087             Component {
0088                 id: appComponent
0089 
0090                 AppDelegate {
0091                     id: appDelegate
0092                     application: delegate.delegateModel.application
0093                     name: Folio.FolioSettings.showFavouritesAppLabels ? delegate.delegateModel.application.name : ""
0094                     shadow: true
0095 
0096                     turnToFolder: delegate.isAppHoveredOver
0097                     turnToFolderAnimEnabled: Folio.HomeScreenState.swipeState === Folio.HomeScreenState.DraggingDelegate
0098 
0099                     // do not show if the drop animation is running to this delegate
0100                     visible: !(root.homeScreen.dropAnimationRunning && delegate.isDropPositionThis)
0101 
0102                     // don't show label in drag and drop mode
0103                     labelOpacity: delegate.opacity
0104 
0105                     onPressAndHold: {
0106                         let mappedCoords = root.homeScreen.prepareStartDelegateDrag(delegate.delegateModel, appDelegate.delegateItem);
0107                         Folio.HomeScreenState.startDelegateFavouritesDrag(
0108                             mappedCoords.x,
0109                             mappedCoords.y,
0110                             appDelegate.pressPosition.x,
0111                             appDelegate.pressPosition.y,
0112                             delegate.index
0113                         );
0114 
0115                         contextMenu.open();
0116                     }
0117 
0118                     onPressAndHoldReleased: {
0119                         // cancel the event if the delegate is not dragged
0120                         if (Folio.HomeScreenState.swipeState === Folio.HomeScreenState.AwaitingDraggingDelegate) {
0121                             homeScreen.cancelDelegateDrag();
0122                         }
0123                     }
0124 
0125                     onRightMousePress: {
0126                         contextMenu.open();
0127                     }
0128 
0129                     ContextMenuLoader {
0130                         id: contextMenu
0131 
0132                         // close menu when drag starts
0133                         Connections {
0134                             target: Folio.HomeScreenState
0135 
0136                             function onSwipeStateChanged() {
0137                                 if (Folio.HomeScreenState.swipeState === Folio.HomeScreenState.DraggingDelegate) {
0138                                     contextMenu.close();
0139                                 }
0140                             }
0141                         }
0142 
0143                         actions: [
0144                             Kirigami.Action {
0145                                 icon.name: "emblem-favorite"
0146                                 text: i18n("Remove")
0147                                 onTriggered: Folio.FavouritesModel.removeEntry(delegate.index)
0148                             }
0149                         ]
0150                     }
0151                 }
0152             }
0153 
0154             Component {
0155                 id: folderComponent
0156 
0157                 AppFolderDelegate {
0158                     id: appFolderDelegate
0159                     shadow: true
0160                     folder: delegate.delegateModel.folder
0161                     name: Folio.FolioSettings.showFavouritesAppLabels ? delegate.delegateModel.folder.name : ""
0162 
0163                     // do not show if the drop animation is running to this delegate, and the drop delegate is a folder
0164                     visible: !(root.homeScreen.dropAnimationRunning &&
0165                                delegate.isDropPositionThis &&
0166                                delegate.dragState.dropDelegate.type === Folio.FolioDelegate.Folder)
0167 
0168                     appHoveredOver: delegate.isAppHoveredOver
0169 
0170                     // don't show label in drag and drop mode
0171                     labelOpacity: delegate.opacity
0172 
0173                     onAfterClickAnimation: {
0174                         const pos = homeScreen.prepareFolderOpen(appFolderDelegate.contentItem);
0175                         Folio.HomeScreenState.openFolder(pos.x, pos.y, delegate.delegateModel.folder);
0176                     }
0177 
0178                     onPressAndHold: {
0179                         let mappedCoords = root.homeScreen.prepareStartDelegateDrag(delegate.delegateModel, appFolderDelegate.delegateItem);
0180                         Folio.HomeScreenState.startDelegateFavouritesDrag(
0181                             mappedCoords.x,
0182                             mappedCoords.y,
0183                             appFolderDelegate.pressPosition.x,
0184                             appFolderDelegate.pressPosition.y,
0185                             delegate.index
0186                         );
0187 
0188                         contextMenu.open();
0189                     }
0190 
0191                     onPressAndHoldReleased: {
0192                         // cancel the event if the delegate is not dragged
0193                         if (Folio.HomeScreenState.swipeState === Folio.HomeScreenState.AwaitingDraggingDelegate) {
0194                             root.homeScreen.cancelDelegateDrag();
0195                         }
0196                     }
0197 
0198                     onRightMousePress: {
0199                         contextMenu.open();
0200                     }
0201 
0202                     // TODO don't use loader, and move outside to a page to make it more performant
0203                     ContextMenuLoader {
0204                         id: contextMenu
0205 
0206                         // close menu when drag starts
0207                         Connections {
0208                             target: Folio.HomeScreenState
0209 
0210                             function onSwipeStateChanged() {
0211                                 if (Folio.HomeScreenState.swipeState === Folio.HomeScreenState.DraggingDelegate) {
0212                                     contextMenu.close();
0213                                 }
0214                             }
0215                         }
0216 
0217                         actions: [
0218                             Kirigami.Action {
0219                                 icon.name: "emblem-favorite"
0220                                 text: i18n("Remove")
0221                                 onTriggered: Folio.FavouritesModel.removeEntry(delegate.index)
0222                             }
0223                         ]
0224                     }
0225                 }
0226             }
0227         }
0228     }
0229 }