┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dolphintabbar.cpp1
-rw-r--r--src/dolphintabbar.h1
-rw-r--r--src/dolphintabwidget.cpp10
-rw-r--r--src/dolphintabwidget.h6
-rw-r--r--src/kitemviews/kfileitemmodel.cpp3
-rw-r--r--src/panels/places/placespanel.cpp10
-rw-r--r--src/views/draganddrophelper.cpp36
-rw-r--r--src/views/draganddrophelper.h30
8 files changed, 89 insertions, 8 deletions
diff --git a/src/dolphintabbar.cpp b/src/dolphintabbar.cpp
index 4c918e611..f6af9932d 100644
--- a/src/dolphintabbar.cpp
+++ b/src/dolphintabbar.cpp
@@ -80,6 +80,7 @@ void DolphinTabBar::dragMoveEvent(QDragMoveEvent *event)
const int index = tabAt(event->position().toPoint());
if (mimeData->hasUrls()) {
+ Q_EMIT tabDragMoveEvent(index, event);
updateAutoActivationTimer(index);
}
diff --git a/src/dolphintabbar.h b/src/dolphintabbar.h
index 1177cda93..4a59199be 100644
--- a/src/dolphintabbar.h
+++ b/src/dolphintabbar.h
@@ -18,6 +18,7 @@ public:
Q_SIGNALS:
void openNewActivatedTab(int index);
+ void tabDragMoveEvent(int index, QDragMoveEvent *event);
void tabDropEvent(int index, QDropEvent *event);
void tabDetachRequested(int index);
diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp
index f274ffa2a..f80b94ea7 100644
--- a/src/dolphintabwidget.cpp
+++ b/src/dolphintabwidget.cpp
@@ -9,6 +9,7 @@
#include "dolphin_generalsettings.h"
#include "dolphintabbar.h"
#include "dolphinviewcontainer.h"
+#include "views/draganddrophelper.h"
#include <KAcceleratorManager>
#include <KConfigGroup>
@@ -33,6 +34,7 @@ DolphinTabWidget::DolphinTabWidget(DolphinNavigatorsWidgetAction *navigatorsWidg
DolphinTabBar *tabBar = new DolphinTabBar(this);
connect(tabBar, &DolphinTabBar::openNewActivatedTab, this, QOverload<int>::of(&DolphinTabWidget::openNewActivatedTab));
+ connect(tabBar, &DolphinTabBar::tabDragMoveEvent, this, &DolphinTabWidget::tabDragMoveEvent);
connect(tabBar, &DolphinTabBar::tabDropEvent, this, &DolphinTabWidget::tabDropEvent);
connect(tabBar, &DolphinTabBar::tabDetachRequested, this, &DolphinTabWidget::detachTab);
@@ -388,6 +390,14 @@ void DolphinTabWidget::openNewActivatedTab(int index)
openNewActivatedTab(tabPage->activeViewContainer()->url());
}
+void DolphinTabWidget::tabDragMoveEvent(int index, QDragMoveEvent *event)
+{
+ if (index >= 0) {
+ DolphinView *view = tabPageAt(index)->activeViewContainer()->view();
+ DragAndDropHelper::updateDropAction(event, view->url());
+ }
+}
+
void DolphinTabWidget::tabDropEvent(int index, QDropEvent *event)
{
if (index >= 0) {
diff --git a/src/dolphintabwidget.h b/src/dolphintabwidget.h
index 22f65b634..a28a6bea1 100644
--- a/src/dolphintabwidget.h
+++ b/src/dolphintabwidget.h
@@ -209,6 +209,12 @@ private Q_SLOTS:
void openNewActivatedTab(int index);
/**
+ * Is connected to the KTabBar signal receivedDragMoveEvent.
+ * Allows dragging and dropping files onto tabs.
+ */
+ void tabDragMoveEvent(int tab, QDragMoveEvent *event);
+
+ /**
* Is connected to the KTabBar signal receivedDropEvent.
* Allows dragging and dropping files onto tabs.
*/
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index f9bab74cd..99a3d163f 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -12,6 +12,7 @@
#include "dolphin_generalsettings.h"
#include "dolphindebug.h"
#include "private/kfileitemmodelsortalgorithm.h"
+#include "views/draganddrophelper.h"
#include <KDirLister>
#include <KIO/Job>
@@ -348,7 +349,7 @@ bool KFileItemModel::supportsDropping(int index) const
} else {
item = fileItem(index);
}
- return !item.isNull() && ((item.isDir() && item.isWritable()) || item.isDesktopFile());
+ return !item.isNull() && DragAndDropHelper::supportsDropping(item);
}
QString KFileItemModel::roleDescription(const QByteArray &role) const
diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp
index 2c19d8f29..ba3451bd5 100644
--- a/src/panels/places/placespanel.cpp
+++ b/src/panels/places/placespanel.cpp
@@ -156,9 +156,13 @@ void PlacesPanel::dragMoveEvent(QDragMoveEvent *event)
// Reject drag ontop of a non-writable protocol
// We don't know whether we're dropping inbetween or ontop of a place
// so still allow internal drag events so that re-arranging still works.
- const QUrl url = placesModel->url(index);
- if (url.isValid() && !isInternalDrag(event->mimeData()) && !KProtocolManager::supportsWriting(url)) {
- event->setDropAction(Qt::IgnoreAction);
+ if (!isInternalDrag(event->mimeData())) {
+ const QUrl url = placesModel->url(index);
+ if (!url.isValid() || !KProtocolManager::supportsWriting(url)) {
+ event->setDropAction(Qt::IgnoreAction);
+ } else {
+ DragAndDropHelper::updateDropAction(event, url);
+ }
}
}
diff --git a/src/views/draganddrophelper.cpp b/src/views/draganddrophelper.cpp
index 2953233d0..efdec5b92 100644
--- a/src/views/draganddrophelper.cpp
+++ b/src/views/draganddrophelper.cpp
@@ -52,15 +52,43 @@ KIO::DropJob *DragAndDropHelper::dropUrls(const QUrl &destUrl, QDropEvent *event
return nullptr;
}
- // Drop into a directory or a desktop-file
- KIO::DropJob *job = KIO::drop(event, destUrl);
- KJobWidgets::setWindow(job, window);
- return job;
+ if (supportsDropping(destUrl)) {
+ // Drop into a directory or a desktop-file
+ KIO::DropJob *job = KIO::drop(event, destUrl);
+ KJobWidgets::setWindow(job, window);
+ return job;
+ }
}
return nullptr;
}
+bool DragAndDropHelper::supportsDropping(const QUrl &destUrl)
+{
+ KFileItem item(destUrl);
+ return supportsDropping(item);
+}
+
+bool DragAndDropHelper::supportsDropping(const KFileItem &destItem)
+{
+ return (destItem.isDir() && destItem.isWritable()) || destItem.isDesktopFile();
+}
+
+void DragAndDropHelper::updateDropAction(QDropEvent *event, const QUrl &destUrl)
+{
+ if (urlListMatchesUrl(event->mimeData()->urls(), destUrl)) {
+ event->setDropAction(Qt::IgnoreAction);
+ event->ignore();
+ }
+ if (supportsDropping(destUrl)) {
+ event->setDropAction(event->proposedAction());
+ event->accept();
+ } else {
+ event->setDropAction(Qt::IgnoreAction);
+ event->ignore();
+ }
+}
+
void DragAndDropHelper::clearUrlListMatchesUrlCache()
{
DragAndDropHelper::m_urlListMatchesUrlCache.clear();
diff --git a/src/views/draganddrophelper.h b/src/views/draganddrophelper.h
index 656cefe1b..0eee34a3d 100644
--- a/src/views/draganddrophelper.h
+++ b/src/views/draganddrophelper.h
@@ -10,6 +10,8 @@
#include "dolphin_export.h"
+#include <KFileItem>
+
#include <QList>
#include <QString>
#include <QUrl>
@@ -41,6 +43,34 @@ public:
static KIO::DropJob *dropUrls(const QUrl &destUrl, QDropEvent *event, QWidget *window);
/**
+ * Checks if the destination supports dropping.
+ *
+ * @param destUrl URL of the item destination.
+ * @return True if the destination is a directory and is writable, or it's a desktop file.
+ * False otherwise.
+ */
+ static bool supportsDropping(const QUrl &destUrl);
+
+ /**
+ * Checks if the destination supports dropping.
+ *
+ * @param destItem The item destination.
+ * @return True if the destination is a directory and is writable, or it's a desktop file.
+ * False otherwise.
+ */
+ static bool supportsDropping(const KFileItem &destItem);
+
+ /**
+ * Updates the drop action according to whether the destination supports dropping.
+ * If supportsDropping(destUrl), set dropAction = proposedAction. Otherwise, set
+ * dropAction = Qt::IgnoreAction.
+ *
+ * @param event Drop event.
+ * @param destUrl Destination URL.
+ */
+ static void updateDropAction(QDropEvent *event, const QUrl &destUrl);
+
+ /**
* @return True if destUrl is contained in the urls parameter.
*/
static bool urlListMatchesUrl(const QList<QUrl> &urls, const QUrl &destUrl);