aerothemeplasma/plasma/plasmoids/org.kde.desktopcontainment/contents/ui/FolderViewDropArea.qml

61 lines
1.7 KiB
QML
Raw Normal View History

/*
SPDX-FileCopyrightText: 2014-2017 Eike Hein <hein@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.4
import org.kde.draganddrop 2.0 as DragDrop
2024-08-09 01:20:25 +00:00
import org.kde.kirigami 2.20 as Kirigami
DragDrop.DropArea {
id: dropArea
property Item folderView: null
function handleDragMove(folderView, pos) {
// Trigger autoscroll.
2024-08-09 01:20:25 +00:00
folderView.scrollLeft = (pos.x < (Kirigami.Units.iconSizes.small * 3));
folderView.scrollRight = (pos.x > width - (Kirigami.Units.iconSizes.small * 3));
folderView.scrollUp = (pos.y < (Kirigami.Units.iconSizes.small * 3));
folderView.scrollDown = (pos.y > height - (Kirigami.Units.iconSizes.small * 3));
folderView.handleDragMove(pos.x, pos.y);
}
function handleDragEnd(folderView) {
// Cancel autoscroll.
folderView.scrollLeft = false;
folderView.scrollRight = false;
folderView.scrollUp = false;
folderView.scrollDown = false;
folderView.endDragMove();
}
2024-08-09 01:20:25 +00:00
onDragMove: event => {
// TODO: We should reject drag moves onto file items that don't accept drops
// (cf. QAbstractItemModel::flags() here, but DeclarativeDropArea currently
// is currently incapable of rejecting drag events.
if (folderView) {
handleDragMove(folderView, mapToItem(folderView, event.x, event.y));
}
}
2024-08-09 01:20:25 +00:00
onDragLeave: event => {
if (folderView) {
handleDragEnd(folderView);
}
}
2024-08-09 01:20:25 +00:00
onDrop: event => {
if (folderView) {
handleDragEnd(folderView);
folderView.drop(folderView, event, mapToItem(folderView, event.x, event.y));
}
}
}