]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Re-implement dropping of files on folders in the Places Panel.
authorFrank Reininghaus <frank78ac@googlemail.com>
Wed, 11 Jul 2012 22:27:53 +0000 (00:27 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Wed, 11 Jul 2012 22:36:32 +0000 (00:36 +0200)
This resolves a regression caused by the Places Panel rewrite. There is
a small glitch left when reordering items (dragging below the last or
above the first item only shows the drop indicator when first dragging
out of the item and then back), but I prefer not to fix this glitch
right now because this would require a more intrusive change, and I do
not want to risk regressions because is not much time left to fix them
before 4.9.0 is released.

Thanks to Peter Penz for providing some advice about this issue.

CCBUG: 302557

src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/kitemlistcontroller.h
src/kitemviews/kitemlistview.cpp
src/panels/places/placesitemlistwidget.cpp
src/panels/places/placesitemmodel.cpp
src/panels/places/placesitemmodel.h
src/panels/places/placespanel.cpp
src/panels/places/placespanel.h

index 76f7fa1cd6a76838ea8769d957c4c56a9d24c66c..88f5d9f7cff1614fb8595b470d46916584710a27 100644 (file)
@@ -778,7 +778,6 @@ bool KItemListController::dragLeaveEvent(QGraphicsSceneDragDropEvent* event, con
 
 bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform)
 {
 
 bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform)
 {
-    Q_UNUSED(transform);
     if (!m_model || !m_view) {
         return false;
     }
     if (!m_model || !m_view) {
         return false;
     }
@@ -799,20 +798,23 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons
         }
 
         if (newHoveredWidget) {
         }
 
         if (newHoveredWidget) {
+            bool droppingBetweenItems = false;
+            if (m_model->sortRole().isEmpty()) {
+                // The model supports inserting items between other items.
+                droppingBetweenItems = (m_view->showDropIndicator(pos) >= 0);
+            }
+
             const int index = newHoveredWidget->index();
             const int index = newHoveredWidget->index();
-            if (m_model->supportsDropping(index)) {
+            if (!droppingBetweenItems && m_model->supportsDropping(index)) {
+                // Something has been dragged on an item.
+                m_view->hideDropIndicator();
                 newHoveredWidget->setHovered(true);
                 newHoveredWidget->setHovered(true);
-            } else if (m_model->sortRole().isEmpty()) {
-                // The model supports inserting of items on
-                // the given index. Assure that a drop-indicator
-                // is shown by the view.
-                m_view->showDropIndicator(pos);
-            }
-            emit itemHovered(index);
+                emit itemHovered(index);
 
 
-            if (m_autoActivationTimer->interval() >= 0) {
-                m_autoActivationTimer->setProperty("index", index);
-                m_autoActivationTimer->start();
+                if (m_autoActivationTimer->interval() >= 0) {
+                    m_autoActivationTimer->setProperty("index", index);
+                    m_autoActivationTimer->start();
+                }
             }
         }
     }
             }
         }
     }
@@ -822,7 +824,6 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons
 
 bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform)
 {
 
 bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform)
 {
-    Q_UNUSED(transform)
     if (!m_view) {
         return false;
     }
     if (!m_view) {
         return false;
     }
@@ -831,13 +832,19 @@ bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QT
     m_view->setAutoScroll(false);
 
     const QPointF pos = transform.map(event->pos());
     m_view->setAutoScroll(false);
 
     const QPointF pos = transform.map(event->pos());
+
+    int dropAboveIndex = -1;
     if (m_model->sortRole().isEmpty()) {
     if (m_model->sortRole().isEmpty()) {
-        // The model supports inserting of items on
-        // a given index.
-        const int dropIndex = m_view->showDropIndicator(pos);
+        // The model supports inserting of items between other items.
+        dropAboveIndex = m_view->showDropIndicator(pos);
+    }
+
+    if (dropAboveIndex >= 0) {
+        // Something has been dropped between two items.
         m_view->hideDropIndicator();
         m_view->hideDropIndicator();
-        emit itemDropEvent(dropIndex, event);
+        emit aboveItemDropEvent(dropAboveIndex, event);
     } else {
     } else {
+        // Something has been dropped on an item or on an empty part of the view.
         emit itemDropEvent(m_view->itemAt(pos), event);
     }
 
         emit itemDropEvent(m_view->itemAt(pos), event);
     }
 
index db31d50c3d4387f517ff5a1036fe0bd5ebfaeeca..a88152622b5c8bd1c92f9386141107f50ad48f1c 100644 (file)
@@ -201,9 +201,18 @@ signals:
      * Is emitted if a drop event is done above the item with the index
      * \a index. If \a index is < 0 the drop event is done above an
      * empty area of the view.
      * Is emitted if a drop event is done above the item with the index
      * \a index. If \a index is < 0 the drop event is done above an
      * empty area of the view.
+     * TODO: Introduce a new signal viewDropEvent(QGraphicsSceneDragDropEvent),
+     *       which is emitted if the drop event occurs on an empty area in
+     *       the view, and make sure that index is always >= 0 in itemDropEvent().
      */
     void itemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
 
      */
     void itemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
 
+    /**
+     * Is emitted if a drop event is done between the item with the index
+     * \a index and the previous item.
+     */
+    void aboveItemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
+
     void modelChanged(KItemModelBase* current, KItemModelBase* previous);
     void viewChanged(KItemListView* current, KItemListView* previous);
 
     void modelChanged(KItemModelBase* current, KItemModelBase* previous);
     void viewChanged(KItemListView* current, KItemListView* previous);
 
index 64b33f96f36b658a3e0c94270513c0bfac127666..72b3fd8fcbfbaa43660fac359320c8227ade9063 100644 (file)
@@ -2318,6 +2318,13 @@ int KItemListView::showDropIndicator(const QPointF& pos)
         const QPointF mappedPos = widget->mapFromItem(this, pos);
         const QRectF rect = itemRect(widget->index());
         if (mappedPos.y() >= 0 && mappedPos.y() <= rect.height()) {
         const QPointF mappedPos = widget->mapFromItem(this, pos);
         const QRectF rect = itemRect(widget->index());
         if (mappedPos.y() >= 0 && mappedPos.y() <= rect.height()) {
+            if (m_model->supportsDropping(widget->index())) {
+                const int gap = qMax(4, m_styleOption.padding);
+                if (mappedPos.y() >= gap && mappedPos.y() <= rect.height() - gap) {
+                    return -1;
+                }
+            }
+
             const bool isAboveItem = (mappedPos.y () < rect.height() / 2);
             const qreal y = isAboveItem ? rect.top() : rect.bottom();
 
             const bool isAboveItem = (mappedPos.y () < rect.height() / 2);
             const qreal y = isAboveItem ? rect.top() : rect.bottom();
 
index 3f4c92dfad1cad13209d8d10cabf4744319d5a46..24c2b3f11ff924ccc23d41933782529f1047c193 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "placesitemlistwidget.h"
 
 
 #include "placesitemlistwidget.h"
 
+#include "kdebug.h"
+
 PlacesItemListWidget::PlacesItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) :
     KStandardItemListWidget(informant, parent)
 {
 PlacesItemListWidget::PlacesItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) :
     KStandardItemListWidget(informant, parent)
 {
index 00ab9670bb73f7e6470e71e6e3e484d530e94f6c..49790134534c8e5dd3ef0e4d2ef828d335b3b96e 100644 (file)
@@ -396,7 +396,12 @@ QMimeData* PlacesItemModel::createMimeData(const QSet<int>& indexes) const
     return mimeData;
 }
 
     return mimeData;
 }
 
-void PlacesItemModel::dropMimeData(int index, const QMimeData* mimeData)
+bool PlacesItemModel::supportsDropping(int index) const
+{
+    return index >= 0 && index < count();
+}
+
+void PlacesItemModel::dropMimeDataBefore(int index, const QMimeData* mimeData)
 {
     if (mimeData->hasFormat(internalMimeType())) {
         // The item has been moved inside the view
 {
     if (mimeData->hasFormat(internalMimeType())) {
         // The item has been moved inside the view
index a060f4549100363ade6fe57a40ed006d57e359d8..463e564e356837b1f8a92beb853ef10aaac4ed0e 100644 (file)
@@ -120,7 +120,10 @@ public:
     /** @reimp */
     virtual QMimeData* createMimeData(const QSet<int>& indexes) const;
 
     /** @reimp */
     virtual QMimeData* createMimeData(const QSet<int>& indexes) const;
 
-    void dropMimeData(int index, const QMimeData* mimeData);
+    /** @reimp */
+    virtual bool supportsDropping(int index) const;
+
+    void dropMimeDataBefore(int index, const QMimeData* mimeData);
 
     /**
      * @return Converts the URL, which contains "virtual" URLs for system-items like
 
     /**
      * @return Converts the URL, which contains "virtual" URLs for system-items like
index 64de516fae78d9160a063adeb23a51b260cd22d7..429c5399a88d7eca195ba519950cbced0e951356 100644 (file)
@@ -93,6 +93,7 @@ void PlacesPanel::showEvent(QShowEvent* event)
         connect(m_controller, SIGNAL(itemContextMenuRequested(int,QPointF)), this, SLOT(slotItemContextMenuRequested(int,QPointF)));
         connect(m_controller, SIGNAL(viewContextMenuRequested(QPointF)), this, SLOT(slotViewContextMenuRequested(QPointF)));
         connect(m_controller, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent*)));
         connect(m_controller, SIGNAL(itemContextMenuRequested(int,QPointF)), this, SLOT(slotItemContextMenuRequested(int,QPointF)));
         connect(m_controller, SIGNAL(viewContextMenuRequested(QPointF)), this, SLOT(slotViewContextMenuRequested(QPointF)));
         connect(m_controller, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent*)));
+        connect(m_controller, SIGNAL(aboveItemDropEvent(int,QGraphicsSceneDragDropEvent*)), this, SLOT(slotAboveItemDropEvent(int,QGraphicsSceneDragDropEvent*)));
 
         KItemListContainer* container = new KItemListContainer(m_controller, this);
         container->setEnabledFrame(false);
 
         KItemListContainer* container = new KItemListContainer(m_controller, this);
         container->setEnabledFrame(false);
@@ -253,7 +254,23 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos)
 
 void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
 {
 
 void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
 {
-    m_model->dropMimeData(index, event->mimeData());
+    if (index < 0) {
+        return;
+    }
+
+    KUrl destUrl = m_model->placesItem(index)->url();
+    QDropEvent dropEvent(event->pos().toPoint(),
+                         event->possibleActions(),
+                         event->mimeData(),
+                         event->buttons(),
+                         event->modifiers());
+
+    DragAndDropHelper::dropUrls(KFileItem(), destUrl, &dropEvent);
+}
+
+void PlacesPanel::slotAboveItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
+{
+    m_model->dropMimeDataBefore(index, event->mimeData());
 }
 
 void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
 }
 
 void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
index 427b01248fba5da9be583ea82587f27cfa672951..8a84e00a0baeb012f974bcca66ca7e7f9b5cea69 100644 (file)
@@ -56,6 +56,7 @@ private slots:
     void slotItemContextMenuRequested(int index, const QPointF& pos);
     void slotViewContextMenuRequested(const QPointF& pos);
     void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
     void slotItemContextMenuRequested(int index, const QPointF& pos);
     void slotViewContextMenuRequested(const QPointF& pos);
     void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
+    void slotAboveItemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
     void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent);
     void slotTrashUpdated(KJob* job);
     void slotStorageSetupDone(int index, bool success);
     void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent);
     void slotTrashUpdated(KJob* job);
     void slotStorageSetupDone(int index, bool success);