2024-01-15 07:16:59 +08:00
|
|
|
|
/*
|
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* Authors: hxf <hewenfei@kylinos.cn>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2024-01-24 10:16:54 +08:00
|
|
|
|
import QtQuick 2.15
|
2024-01-15 07:16:59 +08:00
|
|
|
|
import QtQml.Models 2.12
|
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
|
|
|
|
|
|
import org.ukui.menu.core 1.0
|
2024-01-24 10:16:54 +08:00
|
|
|
|
import org.ukui.menu.extension 1.0
|
2024-02-01 18:55:21 +08:00
|
|
|
|
import "../extensions" as Extension
|
2024-01-15 07:16:59 +08:00
|
|
|
|
import AppControls2 1.0 as AppControls2
|
|
|
|
|
|
|
|
|
|
import org.ukui.quick.items 1.0 as UkuiItems
|
|
|
|
|
import org.ukui.quick.platform 1.0 as Platform
|
|
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
|
id: root
|
2024-02-01 18:55:21 +08:00
|
|
|
|
signal openFolderSignal(string folderId, string folderName, int x, int y)
|
|
|
|
|
signal contentShowFinished()
|
|
|
|
|
property bool isContentShow
|
|
|
|
|
|
2024-01-15 07:16:59 +08:00
|
|
|
|
property int itemHeight: 40
|
|
|
|
|
property alias sourceModel: appGroupModel.sourceModel
|
2024-03-08 17:51:44 +08:00
|
|
|
|
property int cellWidth: 180
|
|
|
|
|
property int cellHeight: 180
|
|
|
|
|
property int column: Math.floor(width / cellWidth)
|
2024-01-15 07:16:59 +08:00
|
|
|
|
|
|
|
|
|
spacing: 5
|
|
|
|
|
clip: true
|
|
|
|
|
boundsBehavior: Flickable.StopAtBounds
|
|
|
|
|
|
|
|
|
|
model: AppGroupModel {
|
|
|
|
|
id: appGroupModel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delegate: Item {
|
|
|
|
|
width: ListView.view.width
|
|
|
|
|
height: childrenRect.height
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: childrenRect.height
|
|
|
|
|
spacing: 0
|
|
|
|
|
|
|
|
|
|
AppControls2.LabelItem {
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: root.itemHeight
|
|
|
|
|
displayName: model.name
|
2024-01-24 10:16:54 +08:00
|
|
|
|
visible: displayName !== ""
|
2024-01-15 07:16:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GridView {
|
2024-03-08 17:51:44 +08:00
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
width: root.cellWidth * root.column
|
|
|
|
|
height: contentHeight
|
|
|
|
|
cellWidth: root.cellWidth
|
|
|
|
|
cellHeight: root.cellHeight
|
2024-01-15 07:16:59 +08:00
|
|
|
|
interactive: false
|
|
|
|
|
|
|
|
|
|
model: DelegateModel {
|
|
|
|
|
model: appGroupModel
|
2024-06-13 14:11:54 +08:00
|
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
|
// Warning: rootIndex只需要设置一次,多次设置会导致对应关系错误,
|
|
|
|
|
// delegateModel使用persistedIndex保存rootIndex,会自动进行修正
|
|
|
|
|
rootIndex = modelIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-15 07:16:59 +08:00
|
|
|
|
delegate: Item {
|
|
|
|
|
width: GridView.view.cellWidth
|
|
|
|
|
height: GridView.view.cellHeight
|
|
|
|
|
|
|
|
|
|
FullScreenAppItem {
|
2024-02-21 16:45:58 +08:00
|
|
|
|
id: appItem
|
2024-01-15 07:16:59 +08:00
|
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.margins: 12
|
|
|
|
|
|
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
|
|
|
|
|
|
text.text: model.name
|
|
|
|
|
icon.source: model.icon
|
2024-05-24 16:43:51 +08:00
|
|
|
|
isRecentInstalled: model.recentInstall
|
2024-01-15 07:16:59 +08:00
|
|
|
|
|
|
|
|
|
onClicked: (event) => {
|
|
|
|
|
if (event.button === Qt.LeftButton) {
|
|
|
|
|
// openApplication
|
|
|
|
|
appManager.launchApp(id);
|
2024-02-04 11:46:11 +08:00
|
|
|
|
} else if (event.button === Qt.RightButton) {
|
|
|
|
|
menuManager.showMenu(model.id, MenuInfo.FullScreen);
|
2024-01-15 07:16:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-21 16:45:58 +08:00
|
|
|
|
|
2024-02-26 14:24:30 +08:00
|
|
|
|
drag.target: appItem
|
2024-02-23 18:19:22 +08:00
|
|
|
|
onPressed: {
|
|
|
|
|
fullScreenUI.focus = false;
|
|
|
|
|
grabToImage(function(result) {
|
|
|
|
|
Drag.imageSource = result.url
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-02-26 14:24:30 +08:00
|
|
|
|
Drag.supportedActions: Qt.CopyAction
|
|
|
|
|
Drag.dragType: Drag.Automatic
|
|
|
|
|
Drag.active: appItem.drag.active
|
|
|
|
|
Drag.hotSpot.x: width / 2
|
|
|
|
|
Drag.hotSpot.y: height / 2
|
|
|
|
|
Drag.mimeData: {"id": model.id, "favorite": model.favorite > 0}
|
2024-01-15 07:16:59 +08:00
|
|
|
|
}
|
2024-02-22 09:37:36 +08:00
|
|
|
|
|
|
|
|
|
// 收藏按钮
|
2024-02-26 18:02:03 +08:00
|
|
|
|
Extension.EditModeFlag {
|
|
|
|
|
isFavorited: model.favorite > 0
|
2024-02-22 09:37:36 +08:00
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.topMargin: 10
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
anchors.rightMargin: 28
|
2024-02-26 18:02:03 +08:00
|
|
|
|
onClicked: {
|
|
|
|
|
appManager.changeFavoriteState(id, !isFavorited);
|
2024-02-22 09:37:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-15 07:16:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-24 10:16:54 +08:00
|
|
|
|
|
2024-02-06 09:54:18 +08:00
|
|
|
|
header: MouseArea {
|
2024-02-01 18:55:21 +08:00
|
|
|
|
width: root.width
|
|
|
|
|
height: childrenRect.height
|
2024-02-06 09:54:18 +08:00
|
|
|
|
acceptedButtons: Qt.RightButton
|
2024-01-24 10:16:54 +08:00
|
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
|
property var widgets: []
|
|
|
|
|
property var widgetInfos: []
|
|
|
|
|
property int widgetCount: 1
|
2024-01-24 10:16:54 +08:00
|
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
|
Component.onCompleted: {
|
|
|
|
|
widgetInfos.push({label: "favorite", display: "non-starred-symbolic", type: WidgetMetadata.Widget});
|
|
|
|
|
widgets.push("favorite");
|
|
|
|
|
}
|
2024-01-24 10:16:54 +08:00
|
|
|
|
|
2024-02-06 09:54:18 +08:00
|
|
|
|
onClicked: {
|
|
|
|
|
if (mouse.button === Qt.RightButton) {
|
|
|
|
|
menu.open();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UkuiItems.Menu {
|
|
|
|
|
id: menu
|
|
|
|
|
content: [
|
|
|
|
|
UkuiItems.MenuItem {
|
|
|
|
|
text: qsTr("Enable editing mode")
|
|
|
|
|
onClicked: mainWindow.editMode = true;
|
|
|
|
|
},
|
|
|
|
|
UkuiItems.MenuItem {
|
|
|
|
|
text: qsTr("Remove all favorite apps")
|
|
|
|
|
onClicked: extensionData.favoriteAppsModel.clearFavorites();
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
|
Column {
|
2024-01-24 10:16:54 +08:00
|
|
|
|
width: parent.width
|
2024-02-01 18:55:21 +08:00
|
|
|
|
height: childrenRect.height + spacing
|
|
|
|
|
spacing: root.spacing
|
2024-01-24 10:16:54 +08:00
|
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
|
AppControls2.LabelItem {
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: root.itemHeight
|
|
|
|
|
displayName: qsTr("Favorite")
|
2024-01-24 10:16:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-21 16:45:58 +08:00
|
|
|
|
Item {
|
2024-02-01 18:55:21 +08:00
|
|
|
|
width: parent.width
|
2024-02-21 16:45:58 +08:00
|
|
|
|
height: favoriteView.height
|
2024-02-01 18:55:21 +08:00
|
|
|
|
|
2024-02-21 16:45:58 +08:00
|
|
|
|
DropArea {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
property int addedIndex: -1
|
|
|
|
|
property string addedId: ""
|
|
|
|
|
|
|
|
|
|
function reset() {
|
|
|
|
|
addedId = "";
|
|
|
|
|
var nullIndex = favoriteView.indexAtNullItem();
|
|
|
|
|
if (nullIndex > -1 && nullIndex < favoriteView.count) {
|
|
|
|
|
favoriteView.viewModel.items.remove(nullIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-24 10:16:54 +08:00
|
|
|
|
|
2024-02-21 16:45:58 +08:00
|
|
|
|
onEntered: {
|
|
|
|
|
if (drag.getDataAsString("favorite") === "true") {
|
|
|
|
|
drag.accepted = false;
|
|
|
|
|
|
|
|
|
|
} else if (drag.getDataAsString("favorite") === "false") {
|
|
|
|
|
// 从左侧列表添加到收藏
|
|
|
|
|
// 已经触发从左侧拖动到收藏区域的事件,不需要再次添加空白item
|
|
|
|
|
if (addedId === drag.getDataAsString("id")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addedId = drag.getDataAsString("id")
|
|
|
|
|
addedIndex = favoriteView.count;
|
|
|
|
|
visualModel.items.insert(addedIndex, {"id":"", "icon":"", "name": ""});
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// 收藏插件内拖拽
|
|
|
|
|
favoriteView.dragTypeIsMerge = false;
|
2024-01-24 10:16:54 +08:00
|
|
|
|
}
|
2024-02-21 16:45:58 +08:00
|
|
|
|
}
|
2024-02-06 09:54:18 +08:00
|
|
|
|
|
2024-02-21 16:45:58 +08:00
|
|
|
|
onPositionChanged: {
|
|
|
|
|
if (drag.getDataAsString("favorite") === "false" && addedIndex > -1) {
|
|
|
|
|
var dragIndex = favoriteView.indexAt(drag.x, drag.y);
|
|
|
|
|
|
|
|
|
|
if (dragIndex < 0) {
|
|
|
|
|
return;
|
2024-02-06 09:54:18 +08:00
|
|
|
|
}
|
2024-02-21 16:45:58 +08:00
|
|
|
|
|
|
|
|
|
visualModel.items.move(addedIndex, dragIndex);
|
|
|
|
|
addedIndex = dragIndex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDropped: {
|
|
|
|
|
if (drop.getDataAsString("favorite") === "false") {
|
|
|
|
|
reset();
|
|
|
|
|
favoriteModel.addAppToFavorites(drop.getDataAsString("id"), addedIndex);
|
2024-02-06 09:54:18 +08:00
|
|
|
|
}
|
2024-01-24 10:16:54 +08:00
|
|
|
|
}
|
2024-02-21 16:45:58 +08:00
|
|
|
|
onExited: reset()
|
2024-02-01 18:55:21 +08:00
|
|
|
|
}
|
2024-01-24 10:16:54 +08:00
|
|
|
|
|
2024-02-21 16:45:58 +08:00
|
|
|
|
GridView {
|
|
|
|
|
id: favoriteView
|
2024-03-08 17:51:44 +08:00
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
width: root.cellWidth * root.column
|
2024-02-21 16:45:58 +08:00
|
|
|
|
height: contentHeight
|
|
|
|
|
property string mergeToAppId: ""
|
|
|
|
|
property bool isMergeToFolder: false
|
|
|
|
|
property bool dragTypeIsMerge: false
|
|
|
|
|
property int exchangedStartIndex: 0
|
|
|
|
|
property alias viewModel: visualModel
|
|
|
|
|
|
2024-03-08 17:51:44 +08:00
|
|
|
|
cellWidth: root.cellWidth
|
|
|
|
|
cellHeight: root.cellHeight
|
2024-02-27 17:58:23 +08:00
|
|
|
|
interactive: false
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model: DelegateModel {
|
|
|
|
|
id: visualModel
|
|
|
|
|
model: favoriteModel
|
|
|
|
|
delegate: Item {
|
|
|
|
|
id: container
|
|
|
|
|
width: favoriteView.cellWidth
|
|
|
|
|
height: favoriteView.cellHeight
|
|
|
|
|
property var id: model.id
|
|
|
|
|
Extension.FavoriteDelegate {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.margins: 12
|
2024-03-04 17:42:57 +08:00
|
|
|
|
isFullScreen: true
|
2024-02-21 16:45:58 +08:00
|
|
|
|
|
|
|
|
|
visualIndex: container.DelegateModel.itemsIndex
|
|
|
|
|
delegateLayout.anchors.topMargin: 16
|
|
|
|
|
delegateLayout.anchors.bottomMargin: 16
|
|
|
|
|
delegateLayout.spacing: 8
|
|
|
|
|
mergePrompt.anchors.topMargin: 10
|
|
|
|
|
mergePrompt.width: width*0.675
|
|
|
|
|
// mergePrompt.width: 108
|
|
|
|
|
mergePrompt.radius: 32
|
|
|
|
|
|
|
|
|
|
Component.onCompleted: contentShowFinished.connect(resetOpacity)
|
|
|
|
|
Component.onDestruction: contentShowFinished.disconnect(resetOpacity)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//编辑模式标志
|
|
|
|
|
Extension.EditModeFlag {
|
|
|
|
|
id: tag
|
2024-02-26 18:02:03 +08:00
|
|
|
|
isFavorited: true
|
2024-02-21 16:45:58 +08:00
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.topMargin: 10
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
anchors.rightMargin: 28
|
|
|
|
|
onClicked: {
|
|
|
|
|
visualModel.model.removeAppFromFavorites(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
displaced: Transition {
|
|
|
|
|
NumberAnimation { properties: "x,y"; easing.type: Easing.OutQuad; duration: 200 }
|
|
|
|
|
}
|
2024-01-24 10:16:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-15 07:16:59 +08:00
|
|
|
|
}
|