texcrafting/TexSlot.qml

86 lines
1.8 KiB
QML
Raw Permalink Normal View History

2024-09-09 21:12:05 +00:00
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
DropArea {
property string rectColor: "white"
property url filePath: ""
Layout.alignment: Qt.AlignCenter
width: 128
height: 128
Rectangle {
id: rectangle
anchors.fill: parent
color: rectColor
Image {
id: image
anchors.centerIn: parent
source: filePath
2024-09-09 21:12:05 +00:00
width: 96
height: 96
2024-09-10 15:47:18 +00:00
MouseArea {
id: imageMouseArea
anchors.fill: parent
Drag.dragType: Drag.Automatic
Drag.supportedActions: Qt.CopyAction
Drag.mimeData: {
"text/uri-list": filePath
}
2024-09-09 21:12:05 +00:00
2024-09-10 15:47:18 +00:00
DragHandler {
id: dragHandler
onActiveChanged:
if (active) {
parent.grabToImage(function(result) {
parent.Drag.imageSource = result.url
parent.Drag.active = true
})
} else {
parent.Drag.active = false
}
}
}
2024-09-09 21:12:05 +00:00
}
}
Label {
id: huh
text: "無"
}
onEntered: {
rectangle.color = "cyan";
drag.accept (Qt.LinkAction);
}
onDropped: {
// TODO: handle dragging all channels at once
var firstUrl = new URL(drop.urls[0]);
if (firstUrl.protocol === "file:")
{
console.log(drop.urls);
filePath = drop.urls[0];
2024-09-09 21:12:05 +00:00
}
rectangle.color = rectColor;
}
onExited: {
rectangle.color = rectColor;
}
onFilePathChanged: {
huh.text = filePath;
}
2024-09-09 21:12:05 +00:00
}