diff options
author | Ken Moore <ken@ixsystems.com> | 2018-03-08 14:42:27 -0500 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2018-03-08 14:42:27 -0500 |
commit | f98120435fe52b8e2991353d43a7c1e2de75921d (patch) | |
tree | 2c16958fb8d3fa2a4b716b1d3180d1d52f6d99cf | |
parent | Split the Lumina 2 backend: (diff) | |
download | lumina-f98120435fe52b8e2991353d43a7c1e2de75921d.tar.gz lumina-f98120435fe52b8e2991353d43a7c1e2de75921d.tar.bz2 lumina-f98120435fe52b8e2991353d43a7c1e2de75921d.zip |
Add drag-n-drop to the desktop icons.
This will let the user drag a desktop icon to any application/tool and have it react appropriately.
NOTE: Directories on the desktop are not enabled as drop targets yet.
-rw-r--r-- | src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h b/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h index c8e3a475..833a2a48 100644 --- a/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h +++ b/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h @@ -18,6 +18,8 @@ #include <QTimer> #include <QMenu> #include <QCursor> +#include <QDrag> +#include <QMimeData> #include "../LDPlugin.h" @@ -38,6 +40,7 @@ private: QInputDialog *inputDLG; QString iconID; int icosize; + QPoint dragstartpos; private slots: void loadButton(); @@ -74,5 +77,33 @@ protected: QEvent::Type tmp = ev->type(); if(tmp == QEvent::StyleChange || tmp==QEvent::ThemeChange || tmp==QEvent::LanguageChange || tmp==QEvent::LocaleChange){ loadButton(); } } + + void mousePressEvent(QMouseEvent *ev){ + if(ev->button()==Qt::LeftButton){ + dragstartpos = ev->pos(); + } + } + + void mouseMoveEvent(QMouseEvent *ev){ + if( (ev->buttons() & Qt::LeftButton) ){ + if((ev->pos() - dragstartpos).manhattanLength() > (this->width()/4) ){ + //Start the drag event for this file + QDrag *drag = new QDrag(this); + QMimeData *md = new QMimeData; + md->setUrls( QList<QUrl>() << QUrl::fromLocalFile(button->whatsThis()) ); + drag->setMimeData(md); + //Now perform the drag and react appropriately + Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction); + if(dropAction == Qt::MoveAction){ + // File Moved, remove it from here + //qDebug() << "File Moved:" << button->whatsThis(); + //DO NOT DELETE FILES - return code often is wrong (browser drops for instance) + } + } + }else{ + LDPlugin::mouseMoveEvent(ev); + } + + } }; #endif |