feat(extension):添加正常窗口和全凭模式下的拖拽收藏功能;收藏插件点击打开应用功能

This commit is contained in:
qiqi49 2024-02-21 16:45:58 +08:00
parent 5b5739299e
commit 4edd1ad83a
5 changed files with 225 additions and 86 deletions

View File

@ -21,6 +21,7 @@ import QtQml 2.12
import QtQuick.Controls 2.5 import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import AppControls2 1.0 as AppControls2 import AppControls2 1.0 as AppControls2
import org.ukui.quick.items 1.0 as UkuiItems
import org.ukui.menu.core 1.0 import org.ukui.menu.core 1.0
AppListView { AppListView {
@ -59,9 +60,7 @@ AppListView {
width: appListView.view ? appListView.view.width : 0 width: appListView.view ? appListView.view.width : 0
height: appListView.itemHeight height: appListView.itemHeight
acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.RightButton
// Drag.active: drag.active drag.target: appItemBase
// Drag.hotSpot.x: width / 2
// Drag.hotSpot.y: height / 2
onClicked: { onClicked: {
if (mouse.button === Qt.RightButton) { if (mouse.button === Qt.RightButton) {
appListView.model.openMenu(index, MenuInfo.AppList); appListView.model.openMenu(index, MenuInfo.AppList);
@ -72,24 +71,28 @@ AppListView {
return; return;
} }
} }
// onPressAndHold: { onPressed: parent.grabImage();
// if (mouse.button === Qt.LeftButton) {
// x = appItem.mapToItem(appListView,0,0).x;
// y = appItem.mapToItem(appListView,0,0).y;
// drag.target = appItem;
// appItem.parent = appListView;
// appItem.isSelect = true;
// }
// }
// onReleased: {
// Drag.drop();
// drag.target = null;
// appItem.parent = appItemBase;
// x = 0;
// y = 0;
// appItem.isSelect = false;
// }
} }
function grabImage() {
var icon = mouseGrabImage.createObject(appItemBase, { width: 48, height: 48, source: model.icon})
icon.grabToImage(function(result) {
appItemBase.Drag.imageSource = result.url
return result;
});
icon.opacity = 0;
}
Component {
id: mouseGrabImage
UkuiItems.Icon { }
}
Drag.supportedActions: Qt.CopyAction
Drag.dragType: Drag.Automatic
Drag.active: appItem.drag.active
Drag.mimeData: {"id": id, "favorite": favorite}
Keys.onPressed: { Keys.onPressed: {
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
appManager.launchApp(id); appManager.launchApp(id);

View File

@ -80,6 +80,7 @@ ListView {
height: GridView.view.cellHeight height: GridView.view.cellHeight
FullScreenAppItem { FullScreenAppItem {
id: appItem
anchors.fill: parent anchors.fill: parent
anchors.margins: 12 anchors.margins: 12
@ -96,7 +97,18 @@ ListView {
menuManager.showMenu(model.id, MenuInfo.FullScreen); menuManager.showMenu(model.id, MenuInfo.FullScreen);
} }
} }
drag.target: parent
onPressed: parent.grabToImage(function(result) {
parent.Drag.imageSource = result.url
})
} }
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}
} }
} }
} }
@ -137,20 +149,6 @@ ListView {
] ]
} }
//
DropArea {
width: parent.width
height: favoriteView.contentHeight
onEntered: {
if (drag.source.isFavorite) {
favoriteView.dragTypeIsMerge = false;
} else {
var id = drag.source.id;
extensionData.favoriteAppsModel.addAppToFavorites(id);
}
}
}
Column { Column {
width: parent.width width: parent.width
height: childrenRect.height + spacing height: childrenRect.height + spacing
@ -162,58 +160,132 @@ ListView {
displayName: qsTr("Favorite") displayName: qsTr("Favorite")
} }
GridView { Item {
id: favoriteView
width: parent.width width: parent.width
height: contentHeight height: favoriteView.height
property string mergeToAppId: ""
property bool isMergeToFolder: false
property bool dragTypeIsMerge: false
property int exchangedStartIndex: 0
property alias viewModel: visualModel
cellWidth: width / root.column DropArea {
cellHeight: cellWidth anchors.fill: parent
model: DelegateModel { property int addedIndex: -1
id: visualModel property string addedId: ""
model: favoriteModel
delegate: Item {
id: container
width: favoriteView.cellWidth
height: favoriteView.cellHeight
Extension.FavoriteDelegate {
anchors.fill: parent
anchors.margins: 12
visualIndex: container.DelegateModel.itemsIndex function reset() {
delegateLayout.anchors.topMargin: 16 addedId = "";
delegateLayout.anchors.bottomMargin: 16 var nullIndex = favoriteView.indexAtNullItem();
delegateLayout.spacing: 8 if (nullIndex > -1 && nullIndex < favoriteView.count) {
mergePrompt.anchors.topMargin: 10 favoriteView.viewModel.items.remove(nullIndex);
mergePrompt.width: width*0.675
// mergePrompt.width: 108
mergePrompt.radius: 32
Component.onCompleted: contentShowFinished.connect(resetOpacity)
Component.onDestruction: contentShowFinished.disconnect(resetOpacity)
} }
}
// onEntered: {
Extension.EditModeFlag { if (drag.getDataAsString("favorite") === "true") {
id: tag drag.accepted = false;
anchors.top: parent.top
anchors.topMargin: 10 } else if (drag.getDataAsString("favorite") === "false") {
anchors.right: parent.right //
anchors.rightMargin: 28 // item
onClicked: { if (addedId === drag.getDataAsString("id")) {
visualModel.model.removeAppFromFavorites(id); return;
}
addedId = drag.getDataAsString("id")
addedIndex = favoriteView.count;
visualModel.items.insert(addedIndex, {"id":"", "icon":"", "name": ""});
} else {
//
favoriteView.dragTypeIsMerge = false;
}
}
onPositionChanged: {
if (drag.getDataAsString("favorite") === "false" && addedIndex > -1) {
var dragIndex = favoriteView.indexAt(drag.x, drag.y);
if (dragIndex < 0) {
return;
}
visualModel.items.move(addedIndex, dragIndex);
addedIndex = dragIndex;
}
}
onDropped: {
if (drop.getDataAsString("favorite") === "false") {
reset();
favoriteModel.addAppToFavorites(drop.getDataAsString("id"), addedIndex);
}
}
onExited: reset()
}
GridView {
id: favoriteView
width: parent.width
height: contentHeight
property string mergeToAppId: ""
property bool isMergeToFolder: false
property bool dragTypeIsMerge: false
property int exchangedStartIndex: 0
property alias viewModel: visualModel
cellWidth: width / root.column
cellHeight: cellWidth
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
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
anchors.top: parent.top
anchors.topMargin: 10
anchors.right: parent.right
anchors.rightMargin: 28
onClicked: {
visualModel.model.removeAppFromFavorites(id);
}
} }
} }
} }
}
displaced: Transition { displaced: Transition {
NumberAnimation { properties: "x,y"; easing.type: Easing.OutQuad; duration: 200 } NumberAnimation { properties: "x,y"; easing.type: Easing.OutQuad; duration: 200 }
}
} }
} }
} }

View File

@ -41,7 +41,9 @@ UkuiItems.StyleBackground {
// drag.source [itemLoader] // drag.source [itemLoader]
onEntered: { onEntered: {
if (drag.source.isFolder) { // folder
if (drag.source.isFolder || !drag.source.sourceId) {
drag.accepted = false;
return; return;
} }
@ -49,6 +51,10 @@ UkuiItems.StyleBackground {
delegateDropTimer.running = true; delegateDropTimer.running = true;
} }
onExited: { onExited: {
if (!drag.source.sourceId) {
return;
}
if (delegateDropTimer.timeOutCount < 1) { if (delegateDropTimer.timeOutCount < 1) {
favoriteView.dragTypeIsMerge = false; favoriteView.dragTypeIsMerge = false;
favoriteView.viewModel.items.move(drag.source.visualIndex, iconItem.visualIndex); favoriteView.viewModel.items.move(drag.source.visualIndex, iconItem.visualIndex);
@ -210,8 +216,9 @@ UkuiItems.StyleBackground {
if (mouseButton === Qt.RightButton) { if (mouseButton === Qt.RightButton) {
favoriteModel.openMenu(index) favoriteModel.openMenu(index)
} else { } else {
var data = {"id": model.id}; // var data = {"id": model.id};
send(data); // send(data);
appManager.launchApp(id);
} }
} }
} }

View File

@ -88,14 +88,59 @@ UkuiMenuExtension {
// //
DropArea { DropArea {
anchors.fill: parent anchors.fill: parent
onEntered: { property int addedIndex: -1
if (drag.source.isFavorite) { property string addedId: ""
favoriteView.dragTypeIsMerge = false;
} else { function reset() {
var id = drag.source.id; addedId = "";
extensionData.favoriteAppsModel.addAppToFavorites(id); var nullIndex = favoriteView.indexAtNullItem();
if (nullIndex > -1 && nullIndex < favoriteView.count) {
favoriteView.viewModel.items.remove(nullIndex);
} }
} }
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;
favoriteView.viewModel.items.insert(addedIndex, {"id":"", "icon":"", "name": ""});
} else {
//
favoriteView.dragTypeIsMerge = false;
}
}
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()
} }
FavoriteGridView { FavoriteGridView {

View File

@ -106,6 +106,17 @@ GridView {
NumberAnimation { properties: "x,y"; easing.type: Easing.OutQuad; duration: 200 } NumberAnimation { properties: "x,y"; easing.type: Easing.OutQuad; duration: 200 }
} }
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 { model: DelegateModel {
id: visualModel id: visualModel
delegate: Item { delegate: Item {
@ -113,6 +124,7 @@ GridView {
focus: true focus: true
width: favoriteView.cellWidth width: favoriteView.cellWidth
height: favoriteView.cellHeight height: favoriteView.cellHeight
property var id: model.id
states: State { states: State {
when: activeFocus when: activeFocus