/*SPDX-FileCopyrightText: 2015 Eike Hein <hein@kde.org>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuickimport org.kde.kirigami as Kirigamiimport org.kde.ksvg as KSvgimport org.kde.plasma.components as PlasmaComponentsimport org.kde.plasma.private.kicker as KickerPlasmaComponents.ScrollView {id: itemMultiGridanchors {top: parent.top}width: parent.widthimplicitHeight: itemColumn.implicitHeightsignal keyNavLeft(int subGridIndex)signal keyNavRight(int subGridIndex)signal keyNavUp()signal keyNavDown()property bool grabFocus: falseproperty alias model: repeater.modelproperty alias count: repeater.countproperty alias flickableItem: flickablefunction subGridAt(index) {return repeater.itemAt(index).itemGrid;}function tryActivate(row, col) { // FIXME TODO: Cleanup messy algo.if (flickable.contentY > 0) {row = 0;}var target = null;var rows = 0;for (var i = 0; i < repeater.count; i++) {var grid = subGridAt(i);if (rows <= row) {target = grid;rows += grid.lastRow() + 2; // Header counts as one.} else {break;}}if (target) {rows -= (target.lastRow() + 2);target.tryActivate(row - rows, col);}}onFocusChanged: {if (!focus) {for (var i = 0; i < repeater.count; i++) {subGridAt(i).focus = false;}}}Flickable {id: flickableflickableDirection: Flickable.VerticalFlickcontentHeight: itemColumn.implicitHeight//focusPolicy: Qt.NoFocusColumn {id: itemColumnwidth: itemMultiGrid.width - Kirigami.Units.gridUnitRepeater {id: repeaterdelegate: Item {width: itemColumn.width - Kirigami.Units.gridUnitheight: headerHeight + gridView.height + (index == repeater.count - 1 ? 0 : footerHeight)property int headerHeight: (gridViewLabel.height+ gridViewLabelUnderline.height + Kirigami.Units.gridUnit)property int footerHeight: (Math.ceil(headerHeight / cellSize) * cellSize) - headerHeightproperty Item itemGrid: gridViewvisible: gridView.count > 0Kirigami.Heading {id: gridViewLabelanchors.top: parent.topx: Kirigami.Units.smallSpacingwidth: parent.width - xheight: dummyHeading.heightelide: Text.ElideRightwrapMode: Text.NoWrapopacity: 1.0color: "white" // FIXME TODO: Respect theming?level: 1text: repeater.model.modelForRow(index).descriptiontextFormat: Text.PlainText}KSvg.SvgItem {id: gridViewLabelUnderlineanchors.top: gridViewLabel.bottomwidth: parent.width - Kirigami.Units.gridUnitheight: lineSvg.horLineHeightsvg: lineSvgelementId: "horizontal-line"}MouseArea {width: parent.widthheight: parent.heightonClicked: root.toggle()}ItemGridView {id: gridViewanchors {top: gridViewLabelUnderline.bottomtopMargin: Kirigami.Units.gridUnit}width: parent.widthheight: Math.ceil(count / Math.floor(width / cellSize)) * cellSizecellWidth: cellSizecellHeight: cellSizeiconSize: root.iconSizeverticalScrollBarPolicy: PlasmaComponents.ScrollBar.AlwaysOffmodel: repeater.model.modelForRow(index)onFocusChanged: {if (focus) {itemMultiGrid.focus = true;}}onCountChanged: {if (itemMultiGrid.grabFocus && index == 0 && count > 0) {currentIndex = 0;focus = true;}}onCurrentItemChanged: {if (!currentItem) {return;}if (index == 0 && currentRow() === 0) {flickable.contentY = 0;return;}var y = currentItem.y;y = contentItem.mapToItem(flickable.contentItem, 0, y).y;if (y < flickable.contentY) {flickable.contentY = y;} else {y += cellSize;y -= flickable.contentY;y -= itemMultiGrid.height;if (y > 0) {flickable.contentY += y;}}}onKeyNavLeft: {itemMultiGrid.keyNavLeft(index);}onKeyNavRight: {itemMultiGrid.keyNavRight(index);}onKeyNavUp: {if (index > 0) {var prevGrid = subGridAt(index - 1);prevGrid.tryActivate(prevGrid.lastRow(), currentCol());} else {itemMultiGrid.keyNavUp();}}onKeyNavDown: {if (index < repeater.count - 1) {subGridAt(index + 1).tryActivate(0, currentCol());} else {itemMultiGrid.keyNavDown();}}}// HACK: Steal wheel events from the nested grid view and forward them to// the ScrollView's internal WheelArea.Kicker.WheelInterceptor {anchors.fill: gridViewz: 1destination: findWheelArea(itemMultiGrid)}}}}}}