status-desktop/ui/app/mainui/panels/DropAreaPanel.qml
Jonathan Rainville e5ff0b4a6a fix(images): fix second pasted image replaces the first one
Fixes #9966

Uses the validate function to paste images so that it concatenates the previous images.
FIxes the validate function to also accept data images.
Moves the size validation function to Utils to reuse the data path prefix constant and fix the possible crash when we try to get the size of a data image.
2023-03-28 13:48:10 -04:00

70 lines
1.6 KiB
QML

import QtQuick 2.14
import utils 1.0
DropArea {
id: root
property bool enabled: false
property alias droppedUrls: rptDraggedPreviews.model
signal droppedOnValidScreen(var drop)
function cleanup() {
rptDraggedPreviews.model = []
}
Component.onCompleted: {
Global.dragArea = this;
}
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
rptDraggedPreviews.model = drag.urls.filter(img => Utils.isValidDragNDropImage(img))
}
onPositionChanged: {
rptDraggedPreviews.x = drag.x
rptDraggedPreviews.y = drag.y
}
onExited: cleanup()
Loader {
active: root.containsDrag
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
}
}
}