Verified Commit ed6895fe authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

applets/kickoff: add a page to show all sections in "All Applications"

This allows navigating to the first item in a specified section.

CCBUG: 433297
parent 7b7da92f
......@@ -59,6 +59,7 @@ BasePage {
Component {
id: applicationsListViewComponent
KickoffListView {
id: applicationsListView
objectName: "applicationsListView"
......@@ -66,6 +67,29 @@ BasePage {
model: stackView.appsModel
section.property: model && model.description == "KICKER_ALL_MODEL" ? "group" : ""
section.criteria: ViewSection.FirstCharacter
hasSectionView: stackView.appsModelRow === 1
onShowSectionViewRequested: {
stackView.push(applicationsSectionViewComponent, {
"currentSection": sectionName,
"view.implicitWidth": applicationsListView.view.implicitWidth,
});
}
}
}
Component {
id: applicationsSectionViewComponent
SectionView {
id: sectionView
model: stackView.appsModel.sections
onHideSectionViewRequested: {
stackView.pop();
stackView.currentItem.view.positionViewAtIndex(index, ListView.Beginning);
stackView.currentItem.currentIndex = index;
}
}
}
......
......@@ -26,6 +26,12 @@ EmptyPage {
property alias view: view
property bool mainContentView: false
property bool hasSectionView: false
/**
* Request showing the section view
*/
signal showSectionViewRequested(string sectionName)
clip: view.height < view.contentHeight
......@@ -133,24 +139,37 @@ EmptyPage {
section {
property: "group"
criteria: ViewSection.FullString
delegate: PC3.Label {
//readonly property bool visualFocus: false
width: section.length === 1
? KickoffSingleton.listDelegateContentHeight + leftPadding + rightPadding
// Accessing implicitWidth fixes the width being 0 when loaded.
: Math.min(Math.ceil(implicitWidth), view.availableWidth)
delegate: PC3.AbstractButton {
width: view.availableWidth
height: KickoffSingleton.listDelegateHeight
leftPadding: view.effectiveLayoutDirection === Qt.LeftToRight
? KickoffSingleton.listItemMetrics.margins.left : 0
rightPadding: view.effectiveLayoutDirection === Qt.RightToLeft
? KickoffSingleton.listItemMetrics.margins.right : 0
horizontalAlignment: section.length === 1 ? Text.AlignHCenter : Text.AlignLeft
verticalAlignment: Text.AlignVCenter
maximumLineCount: 1
elide: Text.ElideRight
font.pixelSize: KickoffSingleton.listDelegateContentHeight
enabled: false
text: section.length === 1 ? section.toUpperCase() : section
PC3.Label {
id: contentLabel
anchors.left: parent.left
width: section.length === 1
? KickoffSingleton.listDelegateContentHeight + leftPadding + rightPadding
: parent.width
height: parent.height
leftPadding: view.effectiveLayoutDirection === Qt.LeftToRight
? KickoffSingleton.listItemMetrics.margins.left : 0
rightPadding: view.effectiveLayoutDirection === Qt.RightToLeft
? KickoffSingleton.listItemMetrics.margins.right : 0
horizontalAlignment: section.length === 1 ? Text.AlignHCenter : Text.AlignLeft
verticalAlignment: Text.AlignVCenter
maximumLineCount: 1
elide: Text.ElideRight
font.pixelSize: KickoffSingleton.listDelegateContentHeight
enabled: hoverHandler.hovered
text: section.length === 1 ? section.toUpperCase() : section
}
HoverHandler {
id: hoverHandler
enabled: root.hasSectionView
cursorShape: enabled ? Qt.PointingHandCursor : undefined
}
onClicked: root.showSectionViewRequested(contentLabel.text)
}
}
......
/*
SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.15
import org.kde.plasma.components 3.0 as PC3
KickoffGridView {
id: root
view.cellWidth: Math.round(KickoffSingleton.listDelegateContentHeight * 2.5)
view.cellHeight: view.cellWidth
/**
* Request hiding the section view
*/
signal hideSectionViewRequested(int index)
property string currentSection
delegate: PC3.AbstractButton {
id: sectionButton
width: view.cellWidth
height: view.cellHeight
hoverEnabled: true
onHoveredChanged: if (hovered) {
root.view.currentIndex = index;
}
contentItem: PC3.Label {
anchors {
fill: parent
bottomMargin: KickoffSingleton.fontMetrics.descent
}
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
maximumLineCount: 1
elide: Text.ElideRight
font.pixelSize: KickoffSingleton.listDelegateContentHeight
text: modelData["section"]
}
onClicked: root.hideSectionViewRequested(modelData["firstIndex"])
}
Component.onCompleted: {
for (let i = 0; i < model.length; i++) {
if (model[i]["section"] === root.currentSection) {
view.positionViewAtIndex(i, ListView.Beginning);
view.currentIndex = i;
return;
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment