diff --git a/applets/systemtray/package/contents/ui/main.qml b/applets/systemtray/package/contents/ui/main.qml --- a/applets/systemtray/package/contents/ui/main.qml +++ b/applets/systemtray/package/contents/ui/main.qml @@ -21,6 +21,8 @@ import QtQuick.Layouts 1.1 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.plasmoid 2.0 +import org.kde.draganddrop 2.0 as DnD + import "items" MouseArea { @@ -230,6 +232,46 @@ location: plasmoid.location } + DnD.DropArea { + anchors.fill: parent + + preventStealing: true; + + /** Extracts the name of the system tray applet in the drag data if present + * otherwise returns null*/ + function systemTrayAppletName(event) { + if (event.mimeData.formats.indexOf("text/x-plasmoidservicename") < 0) { + return null; + } + var plasmoidId = event.mimeData.getDataAsByteArray("text/x-plasmoidservicename"); + + if (!plasmoid.nativeInterface.isSystemTrayApplet(plasmoidId)) { + return null; + } + return plasmoidId; + } + + onDragEnter: { + if (!systemTrayAppletName(event)) { + event.ignore(); + } + } + + onDrop: { + var plasmoidId = systemTrayAppletName(event); + if (!plasmoidId) { + event.ignore(); + return; + } + + if (plasmoid.configuration.extraItems.indexOf(plasmoidId) < 0) { + var extraItems = plasmoid.configuration.extraItems; + extraItems.push(plasmoidId); + plasmoid.configuration.extraItems = extraItems; + } + } + } + //Main Layout Flow { id: tasksRow diff --git a/applets/systemtray/systemtray.h b/applets/systemtray/systemtray.h --- a/applets/systemtray/systemtray.h +++ b/applets/systemtray/systemtray.h @@ -97,6 +97,8 @@ */ Q_INVOKABLE void reorderItemAfter(QQuickItem* after, QQuickItem* before); + Q_INVOKABLE bool isSystemTrayApplet(const QString &appletId); + private Q_SLOTS: void serviceNameFetchFinished(QDBusPendingCallWatcher* watcher, const QDBusConnection &connection); void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner); diff --git a/applets/systemtray/systemtray.cpp b/applets/systemtray/systemtray.cpp --- a/applets/systemtray/systemtray.cpp +++ b/applets/systemtray/systemtray.cpp @@ -316,6 +316,11 @@ after->setVisible(true); } +bool SystemTray::isSystemTrayApplet(const QString &appletId) +{ + return m_systrayApplets.contains(appletId); +} + void SystemTray::restoreContents(KConfigGroup &group) { Q_UNUSED(group);