/* * Copyright (C) 2024, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ import QtQuick 2.0 import QtQml.Models 2.12 import QtQuick.Layouts 1.12 import QtQuick.Controls 2.5 import org.ukui.menu.core 1.0 import org.ukui.quick.platform 1.0 as Platform import org.ukui.quick.items 1.0 as UkuiItems Item { property var folderContentModel property alias folderSwipeView: folderSwipeView property bool mouseEnable: false property int contentMargins property int labelMagrins property bool isFullScreen: false PageIndicator { id: pageIndicator interactive: true count: folderSwipeView.count visible: count > 1 currentIndex: folderSwipeView.currentIndex anchors.bottom: parent.bottom anchors.horizontalCenter: parent.horizontalCenter delegate: Rectangle { color: "grey" width: (index === folderSwipeView.currentIndex )? 20 : 6; height: 6; radius: width / 2 opacity: (index === folderSwipeView.currentIndex )? 1 : 0.6 Behavior on width { NumberAnimation { duration: 300; easing.type: Easing.InOutCubic } } } } SwipeView { id: folderSwipeView anchors.fill: parent anchors.margins: contentMargins property bool needTurnPage: false property int contentX: contentItem.contentX property int startContentX: 0 property int startIndex: 0 function hideFolder() { // 在非第一页时,执行翻页动画 if (currentIndex > 0) { interactive = false; needTurnPage = true; pageIndicator.visible = false; contentItem.highlightFollowsCurrentItem = true; contentItem.highlightMoveDuration = 300; contentItem.highlightMoveVelocity = -1; startContentX = contentX; startIndex = currentIndex; currentIndex = 0; // 在第一页或单页时,全屏文件夹直接隐藏 } else { reset(); } } function reset() { interactive = true; root.active = false; pageIndicator.visible = false; turnPageFinished(); } // 判断执行翻页结束后,全屏文件夹隐藏 onContentXChanged: { // 对比翻页过程的位移 if (needTurnPage && startContentX - contentX === startIndex * 86) { needTurnPage = false; reset(); } } Repeater { model: Math.ceil(folderModel.count / 16) Item { id: base property int currentPage: SwipeView.index GridView { id: folderGridView cellHeight: isFullScreen ? cellWidth : (cellWidth + 12) cellWidth: width / 4 anchors.fill: parent interactive: false model: DelegateModel { property int maxItemNumPerPage: 16 filterOnGroup: "folderContent" groups: DelegateModelGroup { name: "folderContent" } items.onChanged: { var groupIndex = groups.length - 1; if (groups[groupIndex].count !== 0) { groups[groupIndex].remove(0, groups[groupIndex].count); } for (var i = base.currentPage * maxItemNumPerPage; i < Math.min((base.currentPage + 1) * maxItemNumPerPage, items.count); i ++) { items.addGroups(i, 1, "folderContent"); } } model: folderContentModel delegate: Item { width: folderGridView.cellWidth height: folderGridView.cellHeight MouseArea { hoverEnabled: true enabled: mouseEnable anchors.fill: parent anchors.margins: 2 acceptedButtons: Qt.LeftButton | Qt.RightButton UkuiItems.StyleBackground { anchors.fill: parent useStyleTransparency: false paletteRole: isFullScreen ? Platform.Theme.Light : Platform.Theme.Text radius: Platform.Theme.maxRadius alpha: parent.containsPress ? 0.25 : parent.containsMouse ? 0.15 : 0.00 clip: false ColumnLayout { anchors.fill: parent anchors.margins: labelMagrins spacing: (parent.width > 40) ? 4 : 0 Image { id: iconImage source: icon Layout.minimumHeight: 16 Layout.minimumWidth: 16 Layout.fillHeight: true Layout.preferredWidth: height Layout.alignment: Qt.AlignHCenter } UkuiItems.StyleText { text: name elide: Text.ElideRight paletteRole: isFullScreen ? Platform.Theme.HighlightedText : Platform.Theme.Text Layout.preferredHeight: contentHeight Layout.fillWidth: true horizontalAlignment: Text.AlignHCenter } } } onClicked: { if (mouse.button === Qt.RightButton) { menuManager.showMenu(id, MenuInfo.Folder); return; } if (mouse.button === Qt.LeftButton) { appManager.launchApp(id); return; } } } } } } } } } }