Warning, /plasma/plasma-desktop/applets/kickoff/package/contents/ui/SectionView.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com>
0003
0004 SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006
0007 import QtQuick 2.15
0008
0009 import org.kde.plasma.components 3.0 as PC3
0010 import org.kde.plasma.plasmoid 2.0
0011
0012 KickoffGridView {
0013 id: root
0014
0015 property string currentSection
0016 property KickoffListView parentView
0017
0018 /**
0019 * Request hiding the section view
0020 */
0021 signal hideSectionViewRequested(int index)
0022
0023 // prevent binding loops and preserve minimum popup size
0024 view.implicitWidth: parentView.view.implicitWidth
0025 view.implicitHeight: parentView.view.implicitHeight
0026
0027 // Using implicitWidth instead of width so that delegates don't
0028 // become super big when using the new popup resizing feature.
0029 view.cellWidth: Math.floor((view.implicitWidth - view.leftMargin - view.rightMargin) / (kickoff.minimumGridRowCount * 1.75))
0030 view.cellHeight: view.cellWidth
0031
0032 delegate: PC3.AbstractButton {
0033 width: view.cellWidth
0034 height: view.cellHeight
0035
0036 hoverEnabled: true
0037 onHoveredChanged: if (hovered) {
0038 root.view.currentIndex = index;
0039 }
0040
0041 padding: fontMetrics.descent / 2
0042
0043 contentItem: PC3.Label {
0044 horizontalAlignment: Text.AlignHCenter
0045 verticalAlignment: Text.AlignVCenter
0046 maximumLineCount: 1
0047 elide: Text.ElideRight
0048
0049 // Sets max size for fontSizeMode, not true size.
0050 // Also affects implicit size,
0051 // so do not rely on this Label's implicit size.
0052 font.pixelSize: fontMetrics.font.pixelSize
0053 fontSizeMode: Text.VerticalFit
0054
0055 text: model.section
0056 textFormat: Text.PlainText
0057 }
0058
0059 onClicked: {
0060 const isGridView = Plasmoid.configuration.applicationsDisplay === 0
0061 const destinationIndex = isGridView ? index : model.firstIndex
0062 root.hideSectionViewRequested(destinationIndex)
0063 }
0064 }
0065
0066 FontMetrics {
0067 id: fontMetrics
0068 // This size doesn't actually fill the cell height perfectly.
0069 // It goes out of bounts and is slightly below center with Noto Sans.
0070 // It's close enough for the calculations this will be used for.
0071 // The calculations seem to work fairly well with other fonts too.
0072 font.pixelSize: root.view.cellHeight
0073 }
0074
0075 Component.onCompleted: {
0076 for (let i = 0; i < model.count; i++) {
0077 if (model.data(model.index([i], 0), Qt.DisplayRole) === root.currentSection) {
0078 view.positionViewAtIndex(i, ListView.Beginning);
0079 view.currentIndex = i;
0080 return;
0081 }
0082 }
0083 }
0084 }