Warning, /plasma/plasma-desktop/applets/kickoff/package/contents/ui/ApplicationsPage.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
0003  * SPDX-License-Identifier: LGPL-2.0-or-later
0004  */
0005 
0006 import QtQuick 2.15
0007 import QtQuick.Layouts 1.15
0008 import QtQuick.Templates 2.15 as T
0009 import QtQml 2.15
0010 import org.kde.plasma.private.kicker 0.1 as Kicker
0011 import org.kde.kirigami 2.20 as Kirigami
0012 import org.kde.plasma.plasmoid 2.0
0013 
0014 BasePage {
0015     id: root
0016     sideBarComponent: KickoffListView {
0017         id: sideBar
0018         focus: true // needed for Loaders
0019         model: kickoff.rootModel
0020         // needed otherwise app displayed at top-level will show a first character as group.
0021         section.property: ""
0022         delegate: KickoffListDelegate {
0023             width: view.availableWidth
0024             isCategoryListItem: true
0025         }
0026     }
0027     contentAreaComponent: VerticalStackView {
0028         id: stackView
0029 
0030         popEnter: Transition {
0031             NumberAnimation {
0032                 property: "x"
0033                 from: 0.5 * root.width
0034                 to: 0
0035                 duration: Kirigami.Units.longDuration
0036                 easing.type: Easing.OutCubic
0037             }
0038             NumberAnimation {
0039                 property: "opacity"
0040                 from: 0.0
0041                 to: 1.0
0042                 duration: Kirigami.Units.longDuration
0043                 easing.type: Easing.OutCubic
0044             }
0045         }
0046 
0047         pushEnter: Transition {
0048             NumberAnimation {
0049                 property: "x"
0050                 from: 0.5 * -root.width
0051                 to: 0
0052                 duration: Kirigami.Units.longDuration
0053                 easing.type: Easing.OutCubic
0054             }
0055             NumberAnimation {
0056                 property: "opacity"
0057                 from: 0.0
0058                 to: 1.0
0059                 duration: Kirigami.Units.longDuration
0060                 easing.type: Easing.OutCubic
0061             }
0062         }
0063 
0064         readonly property string preferredFavoritesViewObjectName: Plasmoid.configuration.favoritesDisplay === 0 ? "favoritesGridView" : "favoritesListView"
0065         readonly property Component preferredFavoritesViewComponent: Plasmoid.configuration.favoritesDisplay === 0 ? favoritesGridViewComponent : favoritesListViewComponent
0066         readonly property string preferredAllAppsViewObjectName: Plasmoid.configuration.applicationsDisplay === 0 ? "listOfGridsView" : "applicationsListView"
0067         readonly property Component preferredAllAppsViewComponent: Plasmoid.configuration.applicationsDisplay === 0 ? listOfGridsViewComponent : applicationsListViewComponent
0068 
0069         readonly property string preferredAppsViewObjectName: Plasmoid.configuration.applicationsDisplay === 0 ? "applicationsGridView" : "applicationsListView"
0070         readonly property Component preferredAppsViewComponent: Plasmoid.configuration.applicationsDisplay === 0 ? applicationsGridViewComponent : applicationsListViewComponent
0071         // NOTE: The 0 index modelForRow isn't supposed to be used. That's just how it works.
0072         // But to trigger model data update, set initial value to 0
0073         property int appsModelRow: 0
0074         readonly property Kicker.AppsModel appsModel: kickoff.rootModel.modelForRow(appsModelRow)
0075         focus: true
0076         initialItem: preferredFavoritesViewComponent
0077 
0078         Component {
0079             id: favoritesListViewComponent
0080             DropAreaListView {
0081                 id: favoritesListView
0082                 objectName: "favoritesListView"
0083                 mainContentView: true
0084                 focus: true
0085                 model: kickoff.rootModel.favoritesModel
0086             }
0087         }
0088 
0089         Component {
0090             id: favoritesGridViewComponent
0091             DropAreaGridView {
0092                 id: favoritesGridView
0093                 objectName: "favoritesGridView"
0094                 focus: true
0095                 model: kickoff.rootModel.favoritesModel
0096             }
0097         }
0098 
0099         Component {
0100             id: applicationsListViewComponent
0101 
0102             KickoffListView {
0103                 id: applicationsListView
0104                 objectName: "applicationsListView"
0105                 mainContentView: true
0106                 model: stackView.appsModel
0107                 // we want to semantically switch between group and "", disabling grouping, workaround for QTBUG-121797
0108                 section.property: model && model.description === "KICKER_ALL_MODEL" ? "group" : "_unset"
0109                 section.criteria: ViewSection.FirstCharacter
0110                 hasSectionView: stackView.appsModelRow === 1
0111 
0112                 onShowSectionViewRequested: sectionName => {
0113                     stackView.push(applicationsSectionViewComponent, {
0114                         "currentSection": sectionName,
0115                         "parentView": applicationsListView
0116                     });
0117                 }
0118             }
0119         }
0120 
0121         Component {
0122             id: applicationsSectionViewComponent
0123 
0124             SectionView {
0125                 id: sectionView
0126                 model: stackView.appsModel.sections
0127 
0128                 onHideSectionViewRequested: index => {
0129                     stackView.pop();
0130                     stackView.currentItem.view.positionViewAtIndex(index, ListView.Beginning);
0131                     stackView.currentItem.currentIndex = index;
0132                 }
0133             }
0134         }
0135 
0136         Component {
0137             id: applicationsGridViewComponent
0138             KickoffGridView {
0139                 id: applicationsGridView
0140                 objectName: "applicationsGridView"
0141                 model: stackView.appsModel
0142             }
0143         }
0144 
0145         Component {
0146             id: listOfGridsViewComponent
0147 
0148             ListOfGridsView {
0149                 id: listOfGridsView
0150                 objectName: "listOfGridsView"
0151                 mainContentView: true
0152                 gridModel: stackView.appsModel
0153 
0154                 onShowSectionViewRequested: sectionName => {
0155                     stackView.push(applicationsSectionViewComponent, {
0156                         currentSection: sectionName,
0157                         parentView: listOfGridsView
0158                     });
0159                 }
0160             }
0161         }
0162 
0163         onPreferredFavoritesViewComponentChanged: {
0164             if (root.sideBarItem !== null && root.sideBarItem.currentIndex === 0) {
0165                 stackView.replace(stackView.preferredFavoritesViewComponent)
0166             }
0167         }
0168         onPreferredAllAppsViewComponentChanged: {
0169             if (root.sideBarItem !== null && root.sideBarItem.currentIndex === 1) {
0170                 stackView.replace(stackView.preferredAllAppsViewComponent)
0171             }
0172         }
0173         onPreferredAppsViewComponentChanged: {
0174             if (root.sideBarItem !== null && root.sideBarItem.currentIndex > 1) {
0175                 stackView.replace(stackView.preferredAppsViewComponent)
0176             }
0177         }
0178 
0179         Connections {
0180             target: root.sideBarItem
0181             function onCurrentIndexChanged() {
0182                 // Only update row index if the condition is met.
0183                 // The 0 index modelForRow isn't supposed to be used. That's just how it works.
0184                 if (root.sideBarItem.currentIndex > 0) {
0185                     appsModelRow = root.sideBarItem.currentIndex
0186                 }
0187                 if (root.sideBarItem.currentIndex === 0
0188                     && stackView.currentItem.objectName !== stackView.preferredFavoritesViewObjectName) {
0189                     stackView.replace(stackView.preferredFavoritesViewComponent)
0190                 } else if (root.sideBarItem.currentIndex === 1
0191                     && stackView.currentItem.objectName !== stackView.preferredAllAppsViewObjectName) {
0192                     stackView.replace(stackView.preferredAllAppsViewComponent)
0193                 } else if (root.sideBarItem.currentIndex > 1
0194                     && stackView.currentItem.objectName !== stackView.preferredAppsViewObjectName) {
0195                     stackView.replace(stackView.preferredAppsViewComponent)
0196                 }
0197             }
0198         }
0199         Connections {
0200             target: kickoff
0201             function onExpandedChanged() {
0202                 if (kickoff.expanded) {
0203                     kickoff.contentArea.currentItem.forceActiveFocus()
0204                 }
0205             }
0206         }
0207     }
0208     // NormalPage doesn't get destroyed when deactivated, so the binding uses
0209     // StackView.status and visible. This way the bindings are reset when
0210     // NormalPage is Activated again.
0211     Binding {
0212         target: kickoff
0213         property: "sideBar"
0214         value: root.sideBarItem
0215         when: root.T.StackView.status === T.StackView.Active && root.visible
0216         restoreMode: Binding.RestoreBinding
0217     }
0218     Binding {
0219         target: kickoff
0220         property: "contentArea"
0221         value: root.contentAreaItem.currentItem // NOT just root.contentAreaItem
0222         when: root.T.StackView.status === T.StackView.Active && root.visible
0223         restoreMode: Binding.RestoreBinding
0224     }
0225 }