2024-01-08 17:25:27 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2023, 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQml.Models 2.1
|
|
|
|
import QtQuick.Controls 2.5
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
import org.ukui.menu.core 1.0
|
|
|
|
import org.ukui.menu.extension 1.0
|
|
|
|
import org.ukui.quick.platform 1.0 as Platform
|
|
|
|
import org.ukui.quick.items 1.0 as UkuiItems
|
|
|
|
import AppControls2 1.0 as AppControls2
|
|
|
|
|
|
|
|
GridView {
|
|
|
|
id: favoriteView
|
2024-01-30 09:50:09 +08:00
|
|
|
cellWidth: width / column
|
2024-01-30 16:16:09 +08:00
|
|
|
cellHeight: cellWidth + 12
|
2024-01-08 17:25:27 +08:00
|
|
|
signal openFolderSignal(string folderId, string folderName, int x, int y)
|
|
|
|
signal contentShowFinished()
|
2024-02-01 18:55:21 +08:00
|
|
|
property bool isContentShow
|
2024-01-08 17:25:27 +08:00
|
|
|
|
|
|
|
property int spacing: 4
|
2024-01-30 09:50:09 +08:00
|
|
|
property int column: 5
|
2024-01-08 17:25:27 +08:00
|
|
|
property alias viewModel: visualModel
|
2024-01-30 09:50:09 +08:00
|
|
|
|
2024-01-08 17:25:27 +08:00
|
|
|
property string mergeToAppId: ""
|
|
|
|
property bool isMergeToFolder: false
|
|
|
|
property bool dragTypeIsMerge: false
|
2024-01-30 09:50:09 +08:00
|
|
|
property int exchangedStartIndex: 0
|
2024-01-08 17:25:27 +08:00
|
|
|
|
|
|
|
state: isContentShow ? "contentShow" : "contentHidden"
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "contentHidden"
|
|
|
|
PropertyChanges { target: favoriteView; opacity: 0; scale: 0.95 }
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "contentShow"
|
|
|
|
PropertyChanges { target: favoriteView; opacity: 1; scale: 1 }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
transitions: [
|
|
|
|
Transition {
|
|
|
|
to:"contentHidden"
|
|
|
|
SequentialAnimation {
|
|
|
|
PropertyAnimation { properties: "opacity, scale"; duration: 300; easing.type: Easing.InOutCubic }
|
|
|
|
ScriptAction { script: favoriteView.visible = false }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Transition {
|
|
|
|
to: "contentShow"
|
2024-02-01 18:55:21 +08:00
|
|
|
SequentialAnimation {
|
|
|
|
ScriptAction { script: favoriteView.visible = true }
|
|
|
|
PropertyAnimation { properties: "opacity, scale"; duration: 300; easing.type: Easing.InOutCubic }
|
|
|
|
}
|
2024-01-08 17:25:27 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
// 按键导航处理(左右键可以循环)
|
|
|
|
focus: true
|
|
|
|
onActiveFocusChanged: currentIndex = 0
|
|
|
|
onCountChanged: currentIndex = 0
|
|
|
|
Keys.onRightPressed: {
|
|
|
|
if(currentIndex === count - 1) {
|
|
|
|
currentIndex = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentIndex++;
|
|
|
|
}
|
|
|
|
Keys.onLeftPressed: {
|
|
|
|
if(currentIndex === 0) {
|
|
|
|
currentIndex = count - 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentIndex--;
|
|
|
|
}
|
|
|
|
Keys.onDownPressed: {
|
|
|
|
if(currentIndex > count - 1 - column) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentIndex = currentIndex + column;
|
|
|
|
}
|
|
|
|
Keys.onUpPressed: {
|
|
|
|
if(currentIndex < column) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentIndex = currentIndex - column;
|
|
|
|
}
|
|
|
|
|
|
|
|
displaced: Transition {
|
|
|
|
NumberAnimation { properties: "x,y"; easing.type: Easing.OutQuad; duration: 200 }
|
|
|
|
}
|
|
|
|
|
2024-02-21 16:45:58 +08:00
|
|
|
function indexAtNullItem() {
|
|
|
|
var nullItemIndex;
|
|
|
|
for (var i = 0; i < favoriteView.count; i ++) {
|
|
|
|
if (favoriteView.itemAtIndex(i).id === "") {
|
|
|
|
nullItemIndex = i;
|
|
|
|
return nullItemIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-01-08 17:25:27 +08:00
|
|
|
model: DelegateModel {
|
|
|
|
id: visualModel
|
|
|
|
delegate: Item {
|
|
|
|
id: container
|
|
|
|
focus: true
|
|
|
|
width: favoriteView.cellWidth
|
|
|
|
height: favoriteView.cellHeight
|
2024-02-21 16:45:58 +08:00
|
|
|
property var id: model.id
|
2024-02-01 18:55:21 +08:00
|
|
|
|
2024-01-08 17:25:27 +08:00
|
|
|
states: State {
|
|
|
|
when: activeFocus
|
|
|
|
PropertyChanges {
|
|
|
|
target: iconItem
|
|
|
|
alpha: 0.6
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Keys.onReturnPressed: {
|
|
|
|
var data = {"id": model.id};
|
|
|
|
send(data);
|
|
|
|
}
|
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
FavoriteDelegate {
|
|
|
|
id: iconItem
|
2024-01-30 09:50:09 +08:00
|
|
|
anchors.fill: parent
|
2024-02-01 18:55:21 +08:00
|
|
|
anchors.margins: 2
|
2024-01-08 17:25:27 +08:00
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
visualIndex: container.DelegateModel.itemsIndex
|
|
|
|
mergePrompt.anchors.topMargin: 6
|
|
|
|
mergePrompt.width: 52
|
|
|
|
mergePrompt.radius: 14
|
2024-02-06 09:54:18 +08:00
|
|
|
delegateLayout.anchors.leftMargin: 2
|
|
|
|
delegateLayout.anchors.rightMargin: 2
|
2024-01-08 17:25:27 +08:00
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
Component.onCompleted: favoriteView.contentShowFinished.connect(resetOpacity)
|
|
|
|
Component.onDestruction: favoriteView.contentShowFinished.disconnect(resetOpacity)
|
2024-01-08 17:25:27 +08:00
|
|
|
}
|
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
//编辑模式标志
|
2024-02-06 09:54:18 +08:00
|
|
|
EditModeFlag {
|
2024-02-26 18:02:03 +08:00
|
|
|
isFavorited: true
|
2024-02-01 18:55:21 +08:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 10
|
2024-02-06 09:54:18 +08:00
|
|
|
onClicked: {
|
|
|
|
visualModel.model.removeAppFromFavorites(id);
|
2024-01-08 17:25:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|