/*SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com>SPDX-License-Identifier: GPL-2.0-or-later*/pragma ComponentBehavior: Boundimport QtQuickimport org.kde.plasma.components as PC3import org.kde.plasma.extras as PlasmaExtrasimport org.kde.plasma.plasmoidKickoffGridView {id: rootproperty string currentSectionproperty KickoffListView parentView/*** Request hiding the section view*/signal hideSectionViewRequested(int index)// prevent binding loops and preserve minimum popup sizeview.implicitWidth: parentView.view.implicitWidthview.implicitHeight: parentView.view.implicitHeight// Using implicitWidth instead of width so that delegates don't// become super big when using the new popup resizing feature.view.cellWidth: Math.floor((view.implicitWidth - view.leftMargin - view.rightMargin) / (kickoff.minimumGridRowCount * 1.75))view.cellHeight: view.cellWidthdelegate: PC3.AbstractButton {id: delegaterequired property int indexrequired property int firstIndexrequired property string sectionwidth: root.view.cellWidthheight: root.view.cellHeighthoverEnabled: trueonHoveredChanged: if (hovered) {root.view.currentIndex = index;}padding: fontMetrics.descent / 2background: Loader {active: delegate.GridView.isCurrentItemsourceComponent: PlasmaExtras.Highlight {anchors.fill: parentz: (root.Drag.active ?? false) ? 3 : 0hovered: truepressed: delegate.downactive: root.view.activeFocus || (kickoff.contentArea === root && kickoff.searchField.activeFocus)}}contentItem: PC3.Label {horizontalAlignment: Text.AlignHCenterverticalAlignment: Text.AlignVCentermaximumLineCount: 1elide: Text.ElideRight// Sets max size for fontSizeMode, not true size.// Also affects implicit size,// so do not rely on this Label's implicit size.font.pixelSize: fontMetrics.font.pixelSizefontSizeMode: Text.VerticalFittext: delegate.sectiontextFormat: Text.PlainText}onClicked: {const isGridView = Plasmoid.configuration.applicationsDisplay === 0const destinationIndex = isGridView ? index : firstIndexroot.hideSectionViewRequested(destinationIndex)}}FontMetrics {id: fontMetrics// This size doesn't actually fill the cell height perfectly.// It goes out of bounts and is slightly below center with Noto Sans.// It's close enough for the calculations this will be used for.// The calculations seem to work fairly well with other fonts too.font.pixelSize: root.view.cellHeight}Component.onCompleted: {for (let i = 0; i < model.count; i++) {if (model.data(model.index([i], 0), Qt.DisplayRole) === root.currentSection) {view.positionViewAtIndex(i, ListView.Beginning);view.currentIndex = i;return;}}}}