2024-01-30 09:50:09 +08:00
|
|
|
import QtQuick 2.15
|
|
|
|
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
|
|
|
|
|
|
|
|
UkuiItems.StyleBackground {
|
|
|
|
id: iconItem
|
|
|
|
property bool hold: false
|
2024-02-01 18:55:21 +08:00
|
|
|
property alias delegateLayout: itemLayout
|
|
|
|
property alias mergePrompt: mergePrompt
|
2024-01-30 09:50:09 +08:00
|
|
|
radius: 8
|
|
|
|
useStyleTransparency: false
|
|
|
|
paletteRole: Platform.Theme.Text
|
|
|
|
alpha: hold ? 0 : control.containsPress ? 0.15 : control.containsMouse ? 0.08 : 0
|
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
property int visualIndex
|
|
|
|
Binding { target: itemLoader; property: "visualIndex"; value: visualIndex }
|
|
|
|
|
|
|
|
// 合并提示框 52*52
|
2024-01-30 09:50:09 +08:00
|
|
|
UkuiItems.StyleBackground {
|
2024-02-01 18:55:21 +08:00
|
|
|
id: mergePrompt
|
2024-01-30 09:50:09 +08:00
|
|
|
height: width
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
paletteRole: Platform.Theme.Text
|
|
|
|
useStyleTransparency: false
|
|
|
|
alpha: (delegateDropArea.enterSourceId !== model.id)
|
2024-02-01 18:55:21 +08:00
|
|
|
&& delegateDropArea.containsDrag && favoriteView.dragTypeIsMerge ? 0.15 : 0
|
2024-01-30 09:50:09 +08:00
|
|
|
z: -1
|
|
|
|
}
|
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
DropArea {
|
|
|
|
id: delegateDropArea
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: 10
|
|
|
|
property string enterSourceId: ""
|
|
|
|
|
|
|
|
// drag.source [itemLoader]
|
|
|
|
onEntered: {
|
2024-02-21 16:45:58 +08:00
|
|
|
// 拖拽对象为folder 或 左侧列表应用时
|
|
|
|
if (drag.source.isFolder || !drag.source.sourceId) {
|
|
|
|
drag.accepted = false;
|
2024-02-01 18:55:21 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
enterSourceId = drag.source.sourceId;
|
|
|
|
delegateDropTimer.running = true;
|
|
|
|
}
|
|
|
|
onExited: {
|
2024-02-21 16:45:58 +08:00
|
|
|
if (!drag.source.sourceId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
if (delegateDropTimer.timeOutCount < 1) {
|
|
|
|
favoriteView.dragTypeIsMerge = false;
|
|
|
|
favoriteView.viewModel.items.move(drag.source.visualIndex, iconItem.visualIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
delegateDropTimer.running = false;
|
|
|
|
enterSourceId = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: delegateDropTimer
|
|
|
|
property int timeOutCount: 0
|
|
|
|
interval: 300
|
|
|
|
repeat: true
|
|
|
|
|
|
|
|
onTriggered: {
|
|
|
|
++timeOutCount;
|
|
|
|
if (timeOutCount == 1) {
|
|
|
|
favoriteView.mergeToAppId = model.id;
|
|
|
|
favoriteView.isMergeToFolder = (model.type === DataType.Folder);
|
|
|
|
favoriteView.dragTypeIsMerge = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onRunningChanged: timeOutCount = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: control
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
pressAndHoldInterval: 300
|
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
|
|
|
|
|
|
|
onClicked: {
|
2024-02-23 18:19:22 +08:00
|
|
|
if (mainWindow.isFullScreen) {
|
|
|
|
fullScreenUI.focus =false;
|
|
|
|
} else {
|
|
|
|
normalUI.focus = false;
|
|
|
|
}
|
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
itemLoader.item.itemClicked(mouse.button);
|
|
|
|
}
|
|
|
|
onPressAndHold: {
|
|
|
|
if (mouse.button === Qt.LeftButton) {
|
2024-02-23 18:19:22 +08:00
|
|
|
if (mainWindow.isFullScreen) {
|
|
|
|
fullScreenUI.focus =false;
|
|
|
|
} else {
|
|
|
|
normalUI.focus = false;
|
|
|
|
}
|
2024-02-01 18:55:21 +08:00
|
|
|
drag.target = itemLoader;
|
|
|
|
iconItem.hold = true;
|
|
|
|
favoriteView.exchangedStartIndex = itemLoader.visualIndex;
|
|
|
|
itemLoader.sourceId = model.id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onReleased: {
|
|
|
|
drag.target = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-30 09:50:09 +08:00
|
|
|
ColumnLayout {
|
|
|
|
id: itemLayout
|
2024-02-01 18:55:21 +08:00
|
|
|
anchors.fill: parent
|
2024-01-30 09:50:09 +08:00
|
|
|
anchors.topMargin: 8
|
2024-02-01 18:55:21 +08:00
|
|
|
anchors.bottomMargin: 14
|
2024-02-06 09:54:18 +08:00
|
|
|
spacing: 4
|
2024-01-30 09:50:09 +08:00
|
|
|
|
|
|
|
ToolTip.visible: iconText.truncated && control.containsMouse
|
|
|
|
ToolTip.text: model.name
|
|
|
|
ToolTip.delay: 500
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: loaderBase
|
2024-02-01 18:55:21 +08:00
|
|
|
Layout.preferredWidth: iconItem.width * 0.6
|
|
|
|
Layout.preferredHeight: width
|
2024-01-30 09:50:09 +08:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: itemLoader
|
|
|
|
width: loaderBase.width
|
|
|
|
height: loaderBase.height
|
|
|
|
x: 0; y: 0
|
|
|
|
Drag.active: control.drag.active
|
|
|
|
Drag.source: itemLoader
|
|
|
|
Drag.hotSpot.x: width / 2
|
|
|
|
Drag.hotSpot.y: height / 2
|
|
|
|
|
|
|
|
Drag.onActiveChanged: {
|
|
|
|
if (Drag.active) {
|
|
|
|
itemLoader.parent = favoriteView;
|
|
|
|
} else {
|
2024-02-01 18:55:21 +08:00
|
|
|
if (favoriteView.dragTypeIsMerge
|
|
|
|
&& (model.id !== favoriteView.mergeToAppId)
|
|
|
|
&& (model.type === DataType.Normal)) {
|
2024-01-30 09:50:09 +08:00
|
|
|
iconItem.hold = false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
iconResetAnimation.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ParallelAnimation {
|
|
|
|
id: iconResetAnimation
|
|
|
|
NumberAnimation {
|
|
|
|
target: itemLoader
|
|
|
|
property: "x"
|
|
|
|
to: container.x + loaderBase.x
|
|
|
|
easing.type: Easing.OutQuad
|
|
|
|
duration: 300
|
|
|
|
}
|
|
|
|
NumberAnimation {
|
|
|
|
target: itemLoader
|
|
|
|
property: "y"
|
|
|
|
to: (container.y + 8) - favoriteView.contentY
|
|
|
|
easing.type: Easing.OutQuad
|
|
|
|
duration: 300
|
|
|
|
}
|
|
|
|
|
|
|
|
onFinished: {
|
|
|
|
iconItem.hold = false;
|
|
|
|
itemLoader.parent = loaderBase;
|
|
|
|
itemLoader.x = 0; itemLoader.y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
property int visualIndex: 0
|
|
|
|
property string sourceId: ""
|
|
|
|
property bool isFolder: model.type === DataType.Folder
|
|
|
|
property string icon: model.icon
|
|
|
|
property bool isFavorite: true
|
|
|
|
sourceComponent: {
|
|
|
|
if (type === DataType.Normal) {
|
|
|
|
return appIconComponent;
|
|
|
|
}
|
|
|
|
if (type === DataType.Folder) {
|
|
|
|
return folderIconComponent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UkuiItems.StyleText {
|
|
|
|
id: iconText
|
|
|
|
Layout.fillWidth: true
|
2024-02-01 18:55:21 +08:00
|
|
|
Layout.preferredHeight: contentHeight
|
|
|
|
Layout.maximumHeight: contentHeight
|
2024-01-30 09:50:09 +08:00
|
|
|
|
|
|
|
text: name
|
|
|
|
elide: Text.ElideRight
|
|
|
|
paletteRole: Platform.Theme.Text
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
opacity: !itemLoader.Drag.active
|
|
|
|
|
|
|
|
Behavior on opacity {
|
|
|
|
NumberAnimation { duration: 150}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: appIconComponent
|
2024-02-02 16:10:09 +08:00
|
|
|
UkuiItems.Icon {
|
2024-01-30 09:50:09 +08:00
|
|
|
id: iconImage
|
|
|
|
source: icon
|
|
|
|
|
|
|
|
function itemClicked(mouseButton) {
|
|
|
|
if (mouseButton === Qt.RightButton) {
|
2024-02-01 18:55:21 +08:00
|
|
|
favoriteModel.openMenu(index)
|
2024-01-30 09:50:09 +08:00
|
|
|
} else {
|
2024-02-21 16:45:58 +08:00
|
|
|
// var data = {"id": model.id};
|
|
|
|
// send(data);
|
|
|
|
appManager.launchApp(id);
|
2024-01-30 09:50:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: folderIconComponent
|
|
|
|
Item {
|
|
|
|
AppControls2.FolderIcon {
|
|
|
|
id: folderIcon
|
2024-02-01 18:55:21 +08:00
|
|
|
height: width
|
2024-01-30 09:50:09 +08:00
|
|
|
anchors.centerIn: parent
|
2024-02-01 18:55:21 +08:00
|
|
|
alpha: 0.10
|
2024-01-30 09:50:09 +08:00
|
|
|
icons: icon
|
2024-02-01 18:55:21 +08:00
|
|
|
columns: rows
|
|
|
|
|
|
|
|
width: mainWindow.isFullScreen ? 84: 40
|
|
|
|
rows: mainWindow.isFullScreen ? 4 : 2
|
|
|
|
spacing: mainWindow.isFullScreen ? 4 : 2
|
|
|
|
padding: mainWindow.isFullScreen ? 8 : 2
|
|
|
|
radius: mainWindow.isFullScreen ? 16 :4
|
2024-01-30 09:50:09 +08:00
|
|
|
}
|
|
|
|
function itemClicked(mouseButton) {
|
|
|
|
if (mouseButton === Qt.RightButton) {
|
2024-02-01 18:55:21 +08:00
|
|
|
favoriteModel.openMenu(index);
|
2024-01-30 09:50:09 +08:00
|
|
|
} else {
|
2024-01-30 16:16:09 +08:00
|
|
|
var x = mapToGlobal(folderIcon.x, folderIcon.y).x;
|
|
|
|
var y = mapToGlobal(folderIcon.x, folderIcon.y).y
|
2024-01-30 09:50:09 +08:00
|
|
|
openFolderSignal(id, name, x, y);
|
|
|
|
// 执行隐藏动画,并且当前图标消失且鼠标区域不可用
|
|
|
|
opacity = 0;
|
|
|
|
control.enabled = false;
|
|
|
|
control.hoverEnabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// folderFunction
|
|
|
|
function resetOpacity() {
|
|
|
|
itemLoader.item.opacity = 1;
|
|
|
|
control.enabled = true;
|
|
|
|
control.hoverEnabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
onHoldChanged: {
|
|
|
|
if (hold) {
|
|
|
|
favoriteView.interactive = false;
|
|
|
|
} else {
|
|
|
|
favoriteView.interactive = contentHeight > favoriteView.parent.height;
|
2024-02-01 18:55:21 +08:00
|
|
|
if (favoriteView.dragTypeIsMerge && (model.id !== favoriteView.mergeToAppId) && (model.type === DataType.Normal)) {
|
|
|
|
if (favoriteView.isMergeToFolder) {
|
|
|
|
favoriteModel.addAppToFolder(model.id, favoriteView.mergeToAppId);
|
2024-01-30 09:50:09 +08:00
|
|
|
} else {
|
2024-02-01 18:55:21 +08:00
|
|
|
favoriteModel.addAppsToNewFolder(model.id, favoriteView.mergeToAppId);
|
2024-01-30 09:50:09 +08:00
|
|
|
}
|
|
|
|
|
2024-02-01 18:55:21 +08:00
|
|
|
} else if (favoriteView.exchangedStartIndex !== itemLoader.visualIndex) {
|
|
|
|
favoriteModel.exchangedAppsOrder(favoriteView.exchangedStartIndex, itemLoader.visualIndex);
|
2024-01-30 09:50:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|