You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
latte-dock/containment/package/contents/ui/DragDropArea.qml

203 lines
6.2 KiB
QML

/*
SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.7
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.draganddrop 2.0 as DragDrop
import org.kde.latte.core 0.2 as LatteCore
DragDrop.DropArea {
id: dragArea
property bool containsDrag: false
readonly property Item dragInfo: Item {
readonly property bool entered: latteView && latteView.containsDrag
property bool isTask: false
property bool isPlasmoid: false
property bool isSeparator: false
property bool isLatteTasks: false
property bool onlyLaunchers: false
property bool computationsAreValid: false
}
Connections{
target: root.dragInfo
onEnteredChanged: {
if(!root.dragInfo.entered) {
dragArea.clearInfo();
}
}
}
Connections{
target: latteView
onContainsDragChanged: {
if(!latteView.containsDrag) {
dragArea.clearInfo();
}
}
}
function clearInfo() {
clearInfoTimer.restart();
}
function isDroppingOnlyLaunchers(event) {
if (!latteView) {
return
}
if (event.mimeData.hasUrls || (event.mimeData.formats.indexOf("text/x-plasmoidservicename") !== 0)) {
var onlyLaunchers = event.mimeData.urls.every(function (item) {
return latteView.extendedInterface.isApplication(item);
});
return onlyLaunchers;
}
return false;
}
//! Give the time when an applet is dropped to be positioned properly
Timer {
id: clearInfoTimer
interval: 100
onTriggered: {
dragArea.dragInfo.computationsAreValid = false;
dragArea.dragInfo.isTask = false;
dragArea.dragInfo.isPlasmoid = false;
dragArea.dragInfo.isSeparator = false;
dragArea.dragInfo.isLatteTasks = false;
dragArea.dragInfo.onlyLaunchers = false;
dndSpacer.parent = root;
dndSpacer.opacity = 0;
}
}
onDragEnter: {
containsDrag = true;
clearInfoTimer.stop();
var isTask = event !== undefined
&& event.mimeData !== undefined
&& event.mimeData.formats !== undefined
&& event.mimeData.formats.indexOf("application/x-orgkdeplasmataskmanager_taskbuttonitem") >= 0;
var isSeparator = event !== undefined
&& event.mimeData !== undefined
&& ( latteView.mimeContainsPlasmoid(event.mimeData, "audoban.applet.separator")
|| latteView.mimeContainsPlasmoid(event.mimeData, "org.kde.latte.separator") );
var isLatteTasks = event !== undefined
&& event.mimeData !== undefined
&& latteView.mimeContainsPlasmoid(event.mimeData, "org.kde.latte.plasmoid");
var isPlasmoid = event !== undefined
&& event.mimeData !== undefined
&& event.mimeData.formats !== undefined
&& !event.mimeData.hasUrls
&& event.mimeData.formats.indexOf("text/x-plasmoidservicename") === 0;
dragInfo.isTask = isTask;
dragInfo.isPlasmoid = isPlasmoid;
dragInfo.isSeparator = isSeparator;
dragInfo.isLatteTasks = isLatteTasks;
dragInfo.onlyLaunchers = isDroppingOnlyLaunchers(event);
dragInfo.computationsAreValid = true;
if (dragInfo.isTask || plasmoid.immutable || !root.myView.isShownFully) {
event.ignore();
clearInfo();
return;
}
//! Send signal AFTER the dragging is confirmed otherwise the restore mask signal from animations
//! may not be triggered #408926
animations.needLength.addEvent(dragArea);
if (root.launchers.hasStealingApplet && dragInfo.onlyLaunchers) {
root.launchers.showAddLaunchersMessageInStealingApplet();
dndSpacer.opacity = 0;
dndSpacer.parent = root;
return;
}
fastLayoutManager.insertAtCoordinates(dndSpacer, event.x, event.y);
dndSpacer.opacity = 1;
}
onDragMove: {
containsDrag = true;
clearInfoTimer.stop();
if (dragInfo.isTask) {
return;
}
if (root.launchers.hasStealingApplet && dragInfo.onlyLaunchers) {
root.launchers.showAddLaunchersMessageInStealingApplet();
dndSpacer.opacity = 0;
dndSpacer.parent = root;
return;
}
fastLayoutManager.insertAtCoordinates(dndSpacer, event.x, event.y);
dndSpacer.opacity = 1;
}
onDragLeave: {
containsDrag = false;
animations.needLength.removeEvent(dragArea);
if (root.launchers.hasStealingApplet) {
root.launchers.hideAddLaunchersMessageInStealingApplet();
}
dndSpacer.opacity = 0;
dndSpacer.parent = root;
}
onDrop: {
containsDrag = false;
animations.needLength.removeEvent(dragArea);
if (root.launchers.hasStealingApplet) {
root.launchers.hideAddLaunchersMessageInStealingApplet();
}
if (dragInfo.isTask || !root.myView.isShownFully) {
return;
}
if (root.launchers.hasStealingApplet && dragInfo.onlyLaunchers) {
root.launchers.addDroppedLaunchersInStealingApplet(event.mimeData.urls);
} else {
fix #96,FEATURE:AllScreens and AllSecondaryScreens --This is a HUGE FEATURE and so important for multi-screens users. It is introduced as one single commit because it reimplements plenty of infrastructure changes and it will be easier to identify newly introduced bugs. --Users can now choose for their docks and panels to belong at various screen groups. The first two screen groups introduced are AllScreens and AllSecondayScreens. In the future it might be possible to provide CustomScreensGroup that the user will be able to define specific screens in which a dock or panel should be always present. --Current solution specifies an Original dock or panel and clones/copies itself automatically to other screens. So docks and panels in other screens are just real docks and panels that reference themselves to original docks and panels. --Clones are destroyed during layout startup and are automaticaly recreated. It is suggested to export your layouts through the official Layouts Editor in order to share them because in that case clones are not included in the new generated layout file. If in any case you do not this and you share your layout with any previous versions then your clones will just appear as separate docks and panels that belong to specific screens. --Automatic syncing was introduced in order to keep up-to-date the configuration of Original docks and panels with their referenced Clones. --Automatic syncing currently works for all docks and panels settings, for all normal applets configurations and for all subcontaiments configuration such as systrays. --Automatic syncing does not work for applets inside subcontainments such as Group Plasmoid. In such case it is suggested to configure your applets inside your Group Plasmoid in the original dock or panel and afterwards to trigger a recreation for the relevant clones --Manual recreation of clones is easily possible by just choosing the dock or panel to be OnPrimary or OnSpecificScreen and rechoosing afterwards the AllScreensGroup or AllSecondaryScreensGroup
3 years ago
var dndindex = fastLayoutManager.dndSpacerIndex();
var eventx = event.x;
var eventy = event.y;
if (dndindex >= 0) {
var masquearadedIndexFromPoint = fastLayoutManager.indexToMasquearadedPoint(fastLayoutManager.dndSpacerIndex());
eventx = masquearadedIndexFromPoint.x;
eventy = masquearadedIndexFromPoint.y;
}
plasmoid.processMimeData(event.mimeData, eventx, eventy);
//! inform others what plasmoid was drag n' dropped to be added
latteView.extendedInterface.appletDropped(event.mimeData, eventx, eventy);
event.accept(event.proposedAction);
}
dndSpacer.opacity = 0;
}
}