2024-10-07 12:31:53 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
2022-10-06 15:47:55 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
DropArea {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property bool enabled: false
|
|
|
|
property alias droppedUrls: rptDraggedPreviews.model
|
|
|
|
|
|
|
|
signal droppedOnValidScreen(var drop)
|
|
|
|
|
|
|
|
function cleanup() {
|
|
|
|
rptDraggedPreviews.model = []
|
|
|
|
}
|
|
|
|
|
|
|
|
onDropped: (drop) => {
|
|
|
|
if (enabled) {
|
|
|
|
droppedOnValidScreen(drop)
|
|
|
|
} else {
|
|
|
|
drop.accepted = false
|
|
|
|
}
|
|
|
|
cleanup()
|
|
|
|
}
|
|
|
|
onEntered: {
|
|
|
|
if (!enabled || !!drag.source) {
|
|
|
|
drag.accepted = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// needed because drag.urls is not a normal js array
|
2023-03-27 17:53:17 +00:00
|
|
|
rptDraggedPreviews.model = drag.urls.filter(img => Utils.isValidDragNDropImage(img))
|
2022-10-06 15:47:55 +00:00
|
|
|
}
|
|
|
|
onPositionChanged: {
|
|
|
|
rptDraggedPreviews.x = drag.x
|
|
|
|
rptDraggedPreviews.y = drag.y
|
|
|
|
}
|
|
|
|
|
|
|
|
onExited: cleanup()
|
|
|
|
|
|
|
|
Loader {
|
2024-10-07 12:31:53 +00:00
|
|
|
active: root.containsDrag && root.enabled
|
2022-10-06 15:47:55 +00:00
|
|
|
width: active ? parent.width : 0
|
|
|
|
height: active ? parent.height : 0
|
|
|
|
sourceComponent: Rectangle {
|
|
|
|
id: dropRectangle
|
|
|
|
color: Style.current.background
|
|
|
|
opacity: 0.8
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
id: rptDraggedPreviews
|
|
|
|
Image {
|
|
|
|
source: modelData
|
|
|
|
width: 80
|
|
|
|
height: 80
|
|
|
|
sourceSize.width: 160
|
|
|
|
sourceSize.height: 160
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
x: index * 10 + rptDraggedPreviews.x
|
|
|
|
y: index * 10 + rptDraggedPreviews.y
|
|
|
|
z: 1
|
2023-04-26 15:33:24 +00:00
|
|
|
cache: false
|
2022-10-06 15:47:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|