2023-02-22 14:07:53 +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.12
|
|
|
|
|
import QtQml.Models 2.1
|
|
|
|
|
import QtQuick.Controls 2.5
|
|
|
|
|
import org.ukui.menu.core 1.0
|
|
|
|
|
import org.ukui.menu.extension 1.0
|
|
|
|
|
import AppControls2 1.0 as AppControls2
|
2024-01-04 11:13:41 +08:00
|
|
|
|
import org.ukui.quick.platform 1.0 as Platform
|
2023-12-11 16:13:53 +08:00
|
|
|
|
import org.ukui.quick.items 1.0 as UkuiItems
|
2024-01-08 17:25:27 +08:00
|
|
|
|
import AppUI 1.0 as AppUI
|
2023-02-22 14:07:53 +08:00
|
|
|
|
|
|
|
|
|
UkuiMenuExtension {
|
|
|
|
|
MouseArea {
|
|
|
|
|
id: viewMouseArea
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
hoverEnabled: true
|
2024-01-30 09:50:09 +08:00
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
2023-02-22 14:07:53 +08:00
|
|
|
|
|
2024-01-08 17:25:27 +08:00
|
|
|
|
onClicked: {
|
2024-01-30 09:50:09 +08:00
|
|
|
|
if (mouse.button === Qt.RightButton) {
|
2024-02-23 18:19:22 +08:00
|
|
|
|
normalUI.focus = false;
|
2024-01-30 09:50:09 +08:00
|
|
|
|
menu.open();
|
|
|
|
|
} else {
|
|
|
|
|
if (mainWindow.editMode) {
|
|
|
|
|
mainWindow.editMode = false;
|
2024-02-26 18:02:03 +08:00
|
|
|
|
} else {
|
|
|
|
|
folderLoader.isFolderOpened = false;
|
2024-01-30 09:50:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-01 18:55:21 +08:00
|
|
|
|
|
2024-01-30 09:50:09 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2023-12-11 16:13:53 +08:00
|
|
|
|
UkuiItems.StyleBackground {
|
2023-03-02 13:57:13 +08:00
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
width: parent.width; height: 1
|
2023-12-11 16:13:53 +08:00
|
|
|
|
useStyleTransparency: false
|
2023-03-02 13:57:13 +08:00
|
|
|
|
alpha: 0.15
|
2024-01-04 11:13:41 +08:00
|
|
|
|
paletteRole: Platform.Theme.Text
|
2023-03-02 13:57:13 +08:00
|
|
|
|
visible: favoriteView.contentY > 0
|
|
|
|
|
z: 1
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 16:16:09 +08:00
|
|
|
|
FolderGridView {
|
2024-01-08 17:25:27 +08:00
|
|
|
|
id: folderLoader
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
|
|
isFullScreen: false
|
2024-01-24 11:31:57 +08:00
|
|
|
|
folderModel: extensionData.folderModel
|
2024-01-08 17:25:27 +08:00
|
|
|
|
Component.onCompleted: favoriteView.openFolderSignal.connect(initFolder)
|
|
|
|
|
Component.onDestruction: favoriteView.openFolderSignal.disconnect(initFolder)
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 09:50:09 +08:00
|
|
|
|
Item {
|
2023-02-22 14:07:53 +08:00
|
|
|
|
anchors.fill: parent
|
2024-01-30 09:50:09 +08:00
|
|
|
|
anchors.bottomMargin: 8
|
2023-02-22 14:07:53 +08:00
|
|
|
|
anchors.leftMargin: 16
|
2024-01-30 09:50:09 +08:00
|
|
|
|
anchors.rightMargin: 16
|
|
|
|
|
anchors.topMargin: 8
|
|
|
|
|
|
|
|
|
|
// 拖动到文件到空白区域 添加到收藏
|
|
|
|
|
DropArea {
|
|
|
|
|
anchors.fill: parent
|
2024-02-21 16:45:58 +08:00
|
|
|
|
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-30 09:50:09 +08:00
|
|
|
|
onEntered: {
|
2024-02-21 16:45:58 +08:00
|
|
|
|
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;
|
|
|
|
|
favoriteView.viewModel.items.insert(addedIndex, {"id":"", "icon":"", "name": ""});
|
|
|
|
|
|
2024-01-30 09:50:09 +08:00
|
|
|
|
} else {
|
2024-02-21 16:45:58 +08:00
|
|
|
|
// 收藏插件内拖拽
|
|
|
|
|
favoriteView.dragTypeIsMerge = false;
|
2024-01-30 09:50:09 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
favoriteView.viewModel.items.move(addedIndex, dragIndex);
|
|
|
|
|
addedIndex = dragIndex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDropped: {
|
|
|
|
|
if (drop.getDataAsString("favorite") === "false") {
|
|
|
|
|
reset();
|
|
|
|
|
extensionData.favoriteAppsModel.addAppToFavorites(drop.getDataAsString("id"), addedIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onExited: reset()
|
2023-02-22 14:07:53 +08:00
|
|
|
|
}
|
2024-01-30 09:50:09 +08:00
|
|
|
|
|
|
|
|
|
FavoriteGridView {
|
|
|
|
|
id: favoriteView
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: (contentHeight > parent.height) ? parent.height : contentHeight
|
|
|
|
|
interactive: contentHeight > parent.height
|
2024-02-01 18:55:21 +08:00
|
|
|
|
isContentShow: !folderLoader.isFolderOpened
|
2024-01-30 09:50:09 +08:00
|
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
|
favoriteView.viewModel.model = extensionData.favoriteAppsModel
|
|
|
|
|
folderLoader.turnPageFinished.connect(contentShowFinished)
|
|
|
|
|
}
|
|
|
|
|
Component.onDestruction: folderLoader.turnPageFinished.disconnect(contentShowFinished)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-22 14:07:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|