simplify dragging architecture

--simpler implementation both for plasmoid
mousehandler and containment droparea
work/spdx
Michail Vourlakos 4 years ago
parent cadae33a39
commit f37fde5824

@ -35,6 +35,7 @@
#include <PlasmaQuick/AppletQuickItem>
// KDE
#include <KDesktopFile>
#include <KLocalizedString>
#include <KPluginMetaData>
@ -163,6 +164,22 @@ bool ContainmentInterface::isCapableToShowShortcutBadges()
return m_showShortcutsMethod.isValid();
}
bool ContainmentInterface::isApplication(const QUrl &url) const
{
if (!url.isValid() || !url.isLocalFile()) {
return false;
}
const QString &localPath = url.toLocalFile();
if (!KDesktopFile::isDesktopFile(localPath)) {
return false;
}
KDesktopFile desktopFile(localPath);
return desktopFile.hasApplicationType();
}
int ContainmentInterface::applicationLauncherId() const
{
const auto applets = m_view->containment()->applets();

@ -30,6 +30,7 @@
#include <QPointer>
#include <QQuickItem>
#include <QTimer>
#include <QUrl>
namespace Plasma {
class Applet;
@ -97,6 +98,8 @@ public slots:
Q_INVOKABLE bool appletIsExpandable(const int id);
Q_INVOKABLE bool appletIsExpanded(const int id);
Q_INVOKABLE bool isApplication(const QUrl &url) const;
signals:
void expandedAppletStateChanged();
void hasExpandedAppletChanged();

@ -27,8 +27,6 @@ import org.kde.latte.core 0.2 as LatteCore
DragDrop.DropArea {
id: dragArea
property bool isForeground: false
readonly property Item dragInfo: Item {
readonly property bool entered: latteView && latteView.containsDrag
property bool isTask: false
@ -64,10 +62,26 @@ DragDrop.DropArea {
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 //dragArea.isForeground ? 100 : 500
interval: 100
onTriggered: {
dragArea.dragInfo.computationsAreValid = false;
@ -109,11 +123,12 @@ DragDrop.DropArea {
dragInfo.isPlasmoid = isPlasmoid;
dragInfo.isSeparator = isSeparator;
dragInfo.isLatteTasks = isLatteTasks;
dragInfo.onlyLaunchers = latteApplet ? latteApplet.launchersDrop(event) : false;
dragInfo.onlyLaunchers = isDroppingOnlyLaunchers(event);
dragInfo.computationsAreValid = true;
if (dragInfo.isTask || plasmoid.immutable || !root.myView.isShownFully) {
event.ignore();
clearInfo();
return;
}
@ -140,11 +155,8 @@ DragDrop.DropArea {
}
}
if (!root.ignoreRegularFilesDragging && !dragResistaner.running) {
if (!isForeground) {
dragResistaner.start();
}
if (!dragResistaner.running) {
dragResistaner.start();
root.layoutManager().insertAtCoordinates2(dndSpacer, event.x, event.y)
dndSpacer.opacity = 1;
}
@ -175,11 +187,8 @@ DragDrop.DropArea {
}
}
if (!root.ignoreRegularFilesDragging && !dragResistaner.running) {
if (!isForeground) {
dragResistaner.start();
}
if (!dragResistaner.running) {
dragResistaner.start();
root.layoutManager().insertAtCoordinates2(dndSpacer, event.x, event.y)
dndSpacer.opacity = 1;
}
@ -187,24 +196,20 @@ DragDrop.DropArea {
Timer {
id: dragResistaner
interval: 1000
interval: 450
}
onDragLeave: {
animations.needLength.removeEvent(dragArea);
root.addLaunchersMessage = false;
if (!isForeground) {
dndSpacer.opacity = 0;
dndSpacer.parent = root;
}
dndSpacer.opacity = 0;
dndSpacer.parent = root;
}
onDrop: {
animations.needLength.removeEvent(dragArea);
if ((root.ignoreRegularFilesDragging && dragInfo.isTask) || !root.myView.isShownFully) {
if (dragInfo.isTask || !root.myView.isShownFully) {
return;
}

@ -339,9 +339,9 @@ Item {
var draggingAppletInConfigure = root.dragOverlay && root.dragOverlay.currentApplet;
var isCurrentAppletInDragging = draggingAppletInConfigure && (root.dragOverlay.currentApplet === appletItem);
var dropApplet = root.dragInfo.entered && foreDropArea.visible
var dropApplet = root.dragInfo.entered && root.dragInfo.isPlasmoid
if (isCurrentAppletInDragging || !draggingAppletInConfigure && !dropApplet) {
if ((isCurrentAppletInDragging || !draggingAppletInConfigure) && !dropApplet) {
return;
}
@ -376,9 +376,9 @@ Item {
var draggingAppletInConfigure = root.dragOverlay && root.dragOverlay.currentApplet;
var isCurrentAppletInDragging = draggingAppletInConfigure && (root.dragOverlay.currentApplet === appletItem);
var dropApplet = root.dragInfo.entered && foreDropArea.visible
var dropApplet = root.dragInfo.entered && root.dragInfo.isPlasmoid
if (isCurrentAppletInDragging || !draggingAppletInConfigure && !dropApplet) {
if ((isCurrentAppletInDragging || !draggingAppletInConfigure) && !dropApplet) {
return;
}
if (!root.isVertical) {

@ -113,20 +113,13 @@ Item {
property bool blurEnabled: plasmoid.configuration.blurEnabled && (!forceTransparentPanel || forcePanelForBusyBackground)
readonly property bool ignoreRegularFilesDragging: !root.editMode
&& (dragInfo.computationsAreValid || foreDropArea.dragInfo.computationsAreValid)
&& !root.dragInfo.isPlasmoid
&& !root.dragInfo.onlyLaunchers
readonly property Item dragInfo: Item {
property bool entered: backDropArea.dragInfo.entered || foreDropArea.dragInfo.entered
property bool isTask: backDropArea.dragInfo.isTask || foreDropArea.dragInfo.isTask
property bool isPlasmoid: backDropArea.dragInfo.isPlasmoid || foreDropArea.dragInfo.isPlasmoid
property bool isSeparator: backDropArea.dragInfo.isSeparator || foreDropArea.dragInfo.isSeparator
property bool isLatteTasks: backDropArea.dragInfo.isLatteTasks || foreDropArea.dragInfo.isLatteTasks
property bool onlyLaunchers: backDropArea.dragInfo.onlyLaunchers || foreDropArea.dragInfo.onlyLaunchers
// onIsPlasmoidChanged: console.log("isPlasmoid :: " + backDropArea.dragInfo.isPlasmoid + " _ " + foreDropArea.dragInfo.isPlasmoid );
// onEnteredChanged: console.log("entered :: " + backDropArea.dragInfo.entered + " _ " + foreDropArea.dragInfo.entered );
property bool entered: backDropArea.dragInfo.entered
property bool isTask: backDropArea.dragInfo.isTask
property bool isPlasmoid: backDropArea.dragInfo.isPlasmoid
property bool isSeparator: backDropArea.dragInfo.isSeparator
property bool isLatteTasks: backDropArea.dragInfo.isLatteTasks
property bool onlyLaunchers: backDropArea.dragInfo.onlyLaunchers
}
property bool containsOnlyPlasmaTasks: latteView ? latteView.extendedInterface.hasPlasmaTasks && !latteView.extendedInterface.hasLatteTasks : false
@ -1225,9 +1218,6 @@ Item {
DragDropArea {
id: backDropArea
anchors.fill: parent
readonly property bool higherPriority: latteView && latteView.containsDrag
&& ((root.dragInfo.isPlasmoid && root.dragInfo.isSeparator)
|| (foreDropArea.dragInfo.computationsAreValid && !root.dragInfo.isPlasmoid && !root.dragInfo.onlyLaunchers))
Item{
anchors.fill: layoutsContainer
@ -1240,19 +1230,6 @@ Item {
Layouts.LayoutsContainer {
id: layoutsContainer
}
DragDropArea {
id: foreDropArea
anchors.fill: parent
visible: !backDropArea.higherPriority
isForeground: true
/* Rectangle {
anchors.fill: parent
color: "blue"
opacity: 0.5
}*/
}
}
Colorizer.Manager {

@ -373,7 +373,7 @@ Item {
interval: 450
onTriggered: {
tasksModel.syncLaunchers();
_launchers.validateSyncedLaunchersOrder();
appletAbilities.launchers.validateSyncedLaunchersOrder();
}
}

@ -65,7 +65,6 @@ Item {
property bool disableRestoreZoom: false //blocks restore animation in rightClick
property bool disableAllWindowsFunctionality: plasmoid.configuration.hideAllTasks
property bool dropNewLauncher: false
property bool inActivityChange: false
property bool inDraggingPhase: false
property bool initializationStep: false //true
@ -126,11 +125,6 @@ Item {
readonly property alias appletAbilities: _appletAbilities
readonly property alias containsDrag: mouseHandler.containsDrag
readonly property bool dragAreaEnabled: latteView ? (root.dragSource !== null
|| latteView.dragInfo.isSeparator
|| latteView.dragInfo.isTask
|| !latteView.dragInfo.isPlasmoid)
: true
//BEGIN Latte Dock properties
property bool badges3DStyle: latteView ? latteView.badges3DStyle : true
@ -936,7 +930,7 @@ Item {
target: icList
visible: root.dragAreaEnabled
visible: !root.dragSource
property int maxThickness: (appletAbilities.parabolic.isHovered || windowPreviewIsShown || appletAbilities.animations.hasThicknessAnimation) ?
appletAbilities.metrics.mask.thickness.zoomedForItems : appletAbilities.metrics.mask.thickness.normalForItems
@ -1119,7 +1113,7 @@ Item {
visible: backgroundOpacity > 0
radius: appletAbilities.metrics.iconSize/10
backgroundOpacity: root.dropNewLauncher && mouseHandler.onlyLaunchers && (root.dragSource == null)? 0.75 : 0
backgroundOpacity: mouseHandler.isDroppingOnlyLaunchers ? 0.75 : 0
duration: appletAbilities.animations.speedFactor.current
title: i18n("Tasks Area")

@ -601,8 +601,9 @@ Item{
readonly property int length: taskItem.abilities.metrics.totals.length
readonly property int thickness: taskItem.abilities.metrics.totals.thickness
readonly property real applyOpacity: root.dropNewLauncher && !mouseHandler.onlyLaunchers
&& (root.dragSource == null) && (mouseHandler.hoveredItem === taskItem) ? 0.7 : 0
readonly property real applyOpacity: (mouseHandler.isDroppingSeparator || mouseHandler.isDroppingFiles)
&& (root.dragSource === null)
&& (mouseHandler.hoveredItem === taskItem) ? 0.7 : 0
sourceComponent: LatteComponents.AddItem {
anchors.fill: parent

@ -39,7 +39,11 @@ Item {
property bool containsDrag: false
property alias hoveredItem: dropHandler.hoveredItem
property alias onlyLaunchers: dropHandler.onlyLaunchers
readonly property alias isMovingTask: dropHandler.inMovingTask
readonly property alias isDroppingFiles: dropHandler.inDroppingFiles
readonly property alias isDroppingOnlyLaunchers: dropHandler.inDroppingOnlyLaunchers
readonly property alias isDroppingSeparator: dropHandler.inDroppingSeparator
Timer {
id: ignoreItemTimer
@ -64,15 +68,17 @@ Item {
DropArea {
id: dropHandler
anchors.fill: parent
preventStealing: true
preventStealing: true;
property bool inDroppingOnlyLaunchers: false
property bool inDroppingSeparator: false
property bool inMovingTask: false
property bool inDroppingFiles: false
property int droppedPosition: -1;
property bool onlyLaunchers: false;
property bool droppingSeparator: false;
readonly property bool eventIsAccepted: inMovingTask || inDroppingSeparator || inDroppingOnlyLaunchers || inDroppingFiles
property int droppedPosition: -1;
property Item hoveredItem
function isDroppingSeparator(event) {
@ -82,49 +88,64 @@ Item {
return ((event.mimeData.formats.indexOf("text/x-plasmoidservicename") === 0) && isSeparator);
}
onHoveredItemChanged: {
if (hoveredItem && windowsPreviewDlg.activeItem && hoveredItem !== windowsPreviewDlg.activeItem ) {
windowsPreviewDlg.hide(6.7);
function isDroppingOnlyLaunchers(event) {
if (event.mimeData.hasUrls || (event.mimeData.formats.indexOf("text/x-plasmoidservicename") !== 0)) {
var onlyLaunchers = event.mimeData.urls.every(function (item) {
return backend.isApplication(item)
});
return onlyLaunchers;
}
}
onDragEnter:{
dArea.containsDrag = true;
return false;
}
if(root.dragSource == null){
onlyLaunchers = false;
droppingSeparator = false;
root.dropNewLauncher = false;
var createLaunchers = false;
function isMovingTask(event) {
return event.mimeData.formats.indexOf("application/x-orgkdeplasmataskmanager_taskbuttonitem") >= 0;
}
if (event.mimeData.hasUrls || (event.mimeData.formats.indexOf("text/x-plasmoidservicename") !== 0)) {
root.dropNewLauncher = true;
function clearDroppingFlags() {
inDroppingFiles = false;
inDroppingOnlyLaunchers = false;
inDroppingSeparator = false;
inMovingTask = false;
}
if (event.mimeData.hasUrls){
createLaunchers = event.mimeData.urls.every(function (item) {
return backend.isApplication(item)
});
}
} else if (isDroppingSeparator(event)) {
droppingSeparator = true;
root.dropNewLauncher = true;
return;
} else {
return;
//event.ignore();
}
onHoveredItemChanged: {
if (hoveredItem && windowsPreviewDlg.activeItem && hoveredItem !== windowsPreviewDlg.activeItem ) {
windowsPreviewDlg.hide(6.7);
}
}
if (createLaunchers) {
onlyLaunchers = true;
}
onDragEnter:{
inDroppingOnlyLaunchers = isDroppingOnlyLaunchers(event);
inDroppingSeparator = isDroppingSeparator(event);
inDroppingFiles = event.mimeData.hasUrls && !inDroppingOnlyLaunchers;
inMovingTask = isMovingTask(event);
/*console.log(" tasks moving task :: " + inMovingTask);
console.log(" tasks only launchers :: " + inDroppingOnlyLaunchers);
console.log(" tasks separator :: " + inDroppingSeparator);
console.log(" tasks only files :: " + inDroppingFiles);
console.log(" tasks event accepted :: " + eventIsAccepted);*/
if (!eventIsAccepted) {
clearDroppingFlags();
event.ignore();
return;
}
dArea.containsDrag = true;
}
onDragMove: {
if (!eventIsAccepted) {
clearDroppingFlags();
event.ignore();
return;
}
dArea.containsDrag = true;
/* if(root.dragSource == null){
root.dropNewLauncher = true;
} */
if (target.animating) {
return;
@ -176,10 +197,8 @@ Item {
}
} else if (!root.dragSource && above && hoveredItem != above) {
hoveredItem = above;
//root.dropNewLauncher = true;
activationTimer.restart();
} else if (!above) {
//root.dropNewLauncher = true;
hoveredItem = null;
activationTimer.stop();
}
@ -192,34 +211,32 @@ Item {
onDragLeave: {
dArea.containsDrag = false;
hoveredItem = null;
root.dropNewLauncher = false;
onlyLaunchers = false;
clearDroppingFlags();
activationTimer.stop();
}
onDrop: {
// Reject internal drops.
dArea.containsDrag = false;
root.dropNewLauncher = false;
onlyLaunchers = false;
if (event.mimeData.formats.indexOf("application/x-orgkdeplasmataskmanager_taskbuttonitem") >= 0) {
if (!eventIsAccepted) {
clearDroppingFlags();
event.ignore();
return;
}
if (droppingSeparator) {
droppingSeparator = false;
// Reject internal drops.
dArea.containsDrag = false;
if (inDroppingSeparator) {
if (hoveredItem && hoveredItem.itemIndex >=0){
appletAbilities.launchers.addInternalSeparatorAtPos(hoveredItem.itemIndex);
} else {
appletAbilities.launchers.addInternalSeparatorAtPos(0);
}
return;
}
if (event.mimeData.hasUrls) {
} else if (inDroppingOnlyLaunchers || inDroppingFiles) {
parent.urlsDropped(event.mimeData.urls);
}
clearDroppingFlags();
}
Timer {
@ -229,7 +246,7 @@ Item {
repeat: false
onTriggered: {
if (dropHandler.onlyLaunchers || !root.dropNewLauncher || dropHandler.droppingSeparator) {
if (dropHandler.inDroppingOnlyLaunchers || dropHandler.inDroppingSeparator) {
return;
}

Loading…
Cancel
Save