]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fixed some drag & drop issues:
authorPeter Penz <peter.penz19@gmail.com>
Sun, 11 Mar 2007 11:13:07 +0000 (11:13 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 11 Mar 2007 11:13:07 +0000 (11:13 +0000)
- allow drag & drop inside the view
- prevent a dragging from a directory into itself
- use QModelIndex instead of the position

svn path=/trunk/KDE/kdebase/apps/; revision=641451

src/dolphincontroller.cpp
src/dolphincontroller.h
src/dolphindetailsview.cpp
src/dolphiniconsview.cpp
src/dolphinview.cpp
src/dolphinview.h
src/sidebartreeview.cpp
src/sidebartreeview.h
src/treeviewsidebarpage.cpp
src/treeviewsidebarpage.h

index ea9c25211bdbdee895dfb44b1b985f2643c22683..28808353317957455d8c90a0e06974aa2ef8d34b 100644 (file)
@@ -43,9 +43,10 @@ void DolphinController::triggerActivation()
 }
 
 void DolphinController::indicateDroppedUrls(const KUrl::List& urls,
 }
 
 void DolphinController::indicateDroppedUrls(const KUrl::List& urls,
-                                            const QPoint& pos)
+                                            const QModelIndex& index,
+                                            QWidget* source)
 {
 {
-    emit urlsDropped(urls, pos);
+    emit urlsDropped(urls, index, source);
 }
 
 
 }
 
 
index 1bd283fd44f206dfe5c902ffba5de6b36e9396c5..6edf6eba94195d0d6ebb78631d9ec687e03a7732 100644 (file)
@@ -61,7 +61,8 @@ public:
     void triggerActivation();
 
     void indicateDroppedUrls(const KUrl::List& urls,
     void triggerActivation();
 
     void indicateDroppedUrls(const KUrl::List& urls,
-                             const QPoint& pos);
+                             const QModelIndex& index,
+                             QWidget* source);
 
     void indicateSortingChange(DolphinView::Sorting sorting);
 
 
     void indicateSortingChange(DolphinView::Sorting sorting);
 
@@ -98,14 +99,13 @@ signals:
     void activated();
 
     /**
     void activated();
 
     /**
-     * Is emitted if the URLs \a urls have been dropped.
-     * @param pos Position relative to the view widget where the
-     *            dropping has been done. It is recommended
-     *            to get the corresponding model index from
-     *            this position to find out the destination.
+     * Is emitted if the URLs \a urls have been dropped to the index
+     * \a index. \a source indicates the widget where the dragging has
+     * been started from.
      */
     void urlsDropped(const KUrl::List& urls,
      */
     void urlsDropped(const KUrl::List& urls,
-                     const QPoint& pos);
+                     const QModelIndex& index,
+                     QWidget* source);
 
     /** Is emitted if the sorting has been changed to \a sorting. */
     void sortingChanged(DolphinView::Sorting sorting);
 
     /** Is emitted if the sorting has been changed to \a sorting. */
     void sortingChanged(DolphinView::Sorting sorting);
index 7737799768dea4ad7d7b927d032029a2a9f14d14..c019f8eb05ff1fe18093ebcff1bd81576e522b6a 100644 (file)
@@ -43,6 +43,8 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
     setSortingEnabled(true);
     setUniformRowHeights(true);
     setSelectionBehavior(SelectItems);
     setSortingEnabled(true);
     setUniformRowHeights(true);
     setSelectionBehavior(SelectItems);
+    setDragDropMode(QAbstractItemView::DragDrop);
+    setDropIndicatorShown(false);
 
     viewport()->setAttribute(Qt::WA_Hover);
 
 
     viewport()->setAttribute(Qt::WA_Hover);
 
@@ -145,13 +147,13 @@ void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
 void DolphinDetailsView::dropEvent(QDropEvent* event)
 {
     const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
 void DolphinDetailsView::dropEvent(QDropEvent* event)
 {
     const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
-    if (urls.isEmpty() || (event->source() == this)) {
-        QTreeView::dropEvent(event);
-    }
-    else {
+    if (!urls.isEmpty()) {
         event->acceptProposedAction();
         event->acceptProposedAction();
-        m_controller->indicateDroppedUrls(urls, event->pos());
+        m_controller->indicateDroppedUrls(urls,
+                                          indexAt(event->pos()),
+                                          event->source());
     }
     }
+    QTreeView::dropEvent(event);
 }
 
 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
 }
 
 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
index c2ba82d0d4f385bc89198398da5bed7f57e2bae8..1871bb6d9e39b2b29ad20ae23f4288e0bff9f9ff 100644 (file)
@@ -29,6 +29,7 @@
 #include <kfileitemdelegate.h>
 
 #include <QAbstractProxyModel>
 #include <kfileitemdelegate.h>
 
 #include <QAbstractProxyModel>
+#include <QPoint>
 
 DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
     QListView(parent),
 
 DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
     QListView(parent),
@@ -107,13 +108,13 @@ void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
 void DolphinIconsView::dropEvent(QDropEvent* event)
 {
     const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
 void DolphinIconsView::dropEvent(QDropEvent* event)
 {
     const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
-    if (urls.isEmpty() || (event->source() == this)) {
-        QListView::dropEvent(event);
-    }
-    else {
+    if (!urls.isEmpty()) {
+        m_controller->indicateDroppedUrls(urls,
+                                          indexAt(event->pos()),
+                                          event->source());
         event->acceptProposedAction();
         event->acceptProposedAction();
-        m_controller->indicateDroppedUrls(urls, event->pos());
     }
     }
+    QListView::dropEvent(event);
 }
 
 void DolphinIconsView::updateGridSize(bool showPreview)
 }
 
 void DolphinIconsView::updateGridSize(bool showPreview)
index 50f56a478435500fdd94c6506706dd07bd212a41..3a6a2e7576e4cba23b2ea47a474385a7f719c17d 100644 (file)
@@ -132,8 +132,8 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow,
     m_controller = new DolphinController(this);
     connect(m_controller, SIGNAL(requestContextMenu(const QPoint&)),
             this, SLOT(openContextMenu(const QPoint&)));
     m_controller = new DolphinController(this);
     connect(m_controller, SIGNAL(requestContextMenu(const QPoint&)),
             this, SLOT(openContextMenu(const QPoint&)));
-    connect(m_controller, SIGNAL(urlsDropped(const KUrl::List&, const QPoint&)),
-            this, SLOT(dropUrls(const KUrl::List&, const QPoint&)));
+    connect(m_controller, SIGNAL(urlsDropped(const KUrl::List&, const QModelIndex&, QWidget*)),
+            this, SLOT(dropUrls(const KUrl::List&, const QModelIndex&, QWidget*)));
     connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)),
             this, SLOT(updateSorting(DolphinView::Sorting)));
     connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
     connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)),
             this, SLOT(updateSorting(DolphinView::Sorting)));
     connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
@@ -971,10 +971,10 @@ void DolphinView::openContextMenu(const QPoint& pos)
 }
 
 void DolphinView::dropUrls(const KUrl::List& urls,
 }
 
 void DolphinView::dropUrls(const KUrl::List& urls,
-                           const QPoint& pos)
+                           const QModelIndex& index,
+                           QWidget* source)
 {
     KFileItem* directory = 0;
 {
     KFileItem* directory = 0;
-    const QModelIndex index = itemView()->indexAt(pos);
     if (isValidNameIndex(index)) {
         KFileItem* item = fileItem(index);
         assert(item != 0);
     if (isValidNameIndex(index)) {
         KFileItem* item = fileItem(index);
         assert(item != 0);
@@ -984,8 +984,17 @@ void DolphinView::dropUrls(const KUrl::List& urls,
         }
     }
 
         }
     }
 
+    if ((directory == 0) && (source == itemView())) {
+        // The dropping is done into the same viewport where
+        // the dragging has been started. Just ignore this...
+        return;
+    }
+
     const KUrl& destination = (directory == 0) ? url() :
                                                  directory->url();
     const KUrl& destination = (directory == 0) ? url() :
                                                  directory->url();
+
+    kDebug() << "DolphinView::dropUrls() - destination: " << destination.prettyUrl() << endl;
+
     dropUrls(urls, destination);
 }
 
     dropUrls(urls, destination);
 }
 
index 5cfd7904d4ac5c1c87fc509cd7cce0c35e79bac5..8ca4a1ac3f69debf96116118e0cb7a26c23f9656 100644 (file)
@@ -449,12 +449,12 @@ private slots:
     void openContextMenu(const QPoint& pos);
 
     /**
     void openContextMenu(const QPoint& pos);
 
     /**
-     * Drops the URLs \a urls at the position \a pos.
-     * The position is used to check whether the dropping
-     * is done above an item or above the viewport.
+     * Drops the URLs \a urls to the index \a index. \a source
+     * indicates the widget where the dragging has been started from.
      */
     void dropUrls(const KUrl::List& urls,
      */
     void dropUrls(const KUrl::List& urls,
-                  const QPoint& pos);
+                  const QModelIndex& index,
+                  QWidget* source);
 
     /**
      * Drops the URLs \a urls at the
 
     /**
      * Drops the URLs \a urls at the
index 52b6d54245b00bd983cf8d8218e11c42ee8a15bc..e5661cd0b433a8616274d6d18aad4c96e5109ce9 100644 (file)
@@ -77,7 +77,10 @@ void SidebarTreeView::dropEvent(QDropEvent* event)
     }
     else {
         event->acceptProposedAction();
     }
     else {
         event->acceptProposedAction();
-        emit urlsDropped(urls, event->pos());
+        const QModelIndex index = indexAt(event->pos());
+        if (index.isValid()) {
+            emit urlsDropped(urls, index);
+        }
     }
 }
 
     }
 }
 
index 8b1f039a01efbd4ae5ca025195882f1dea3376da..f7360e9c4ee8e1b40d09b9ab2c96c4aec0cc8511 100644 (file)
@@ -40,14 +40,11 @@ public:
 
 signals:
    /**
 
 signals:
    /**
-     * Is emitted if the URLs \a urls have been dropped.
-     * @param pos Position relative to the tree view where the
-     *            dropping has been done. It is recommended
-     *            to get the corresponding model index from
-     *            this position to find out the destination.
+     * Is emitted if the URLs \a urls have been dropped to
+     * the index \a index.
      */
     void urlsDropped(const KUrl::List& urls,
      */
     void urlsDropped(const KUrl::List& urls,
-                     const QPoint& pos);
+                     const QModelIndex& index);
 
 protected:
     virtual bool event(QEvent* event);
 
 protected:
     virtual bool event(QEvent* event);
index d9c2e8800c5b21679f6a8d3e04176b02b2fdfcbe..63689b6ebff3b1bef6b16ecedad4b45cac49ac96 100644 (file)
@@ -78,8 +78,8 @@ TreeViewSidebarPage::TreeViewSidebarPage(DolphinMainWindow* mainWindow,
 
     connect(m_treeView, SIGNAL(clicked(const QModelIndex&)),
             this, SLOT(updateActiveView(const QModelIndex&)));
 
     connect(m_treeView, SIGNAL(clicked(const QModelIndex&)),
             this, SLOT(updateActiveView(const QModelIndex&)));
-    connect(m_treeView, SIGNAL(urlsDropped(const KUrl::List&, const QPoint&)),
-            this, SLOT(dropUrls(const KUrl::List&, const QPoint&)));
+    connect(m_treeView, SIGNAL(urlsDropped(const KUrl::List&, const QModelIndex&)),
+            this, SLOT(dropUrls(const KUrl::List&, const QModelIndex&)));
 
     QVBoxLayout* layout = new QVBoxLayout(this);
     layout->addWidget(m_treeView);
 
     QVBoxLayout* layout = new QVBoxLayout(this);
     layout->addWidget(m_treeView);
@@ -202,9 +202,8 @@ void TreeViewSidebarPage::updateActiveView(const QModelIndex& index)
 }
 
 void TreeViewSidebarPage::dropUrls(const KUrl::List& urls,
 }
 
 void TreeViewSidebarPage::dropUrls(const KUrl::List& urls,
-                                   const QPoint& pos)
+                                   const QModelIndex& index)
 {
 {
-    const QModelIndex index = m_treeView->indexAt(pos);
     if (index.isValid()) {
 #if defined(USE_PROXY_MODEL)
         const QModelIndex& dirIndex = m_proxyModel->mapToSource(index);
     if (index.isValid()) {
 #if defined(USE_PROXY_MODEL)
         const QModelIndex& dirIndex = m_proxyModel->mapToSource(index);
index ca98277eb72d4e6d78ddb82fec7c6fc370c793ef..7a4541cb3e2aaa77d2dc3c99681f24ed512f47a0 100644 (file)
@@ -74,9 +74,9 @@ private slots:
 
     /**
      * Is emitted if the URLs \a urls have been dropped
 
     /**
      * Is emitted if the URLs \a urls have been dropped
-     * to the position \a pos. */
+     * to the index \a index. */
     void dropUrls(const KUrl::List& urls,
     void dropUrls(const KUrl::List& urls,
-                  const QPoint& pos);
+                  const QModelIndex& index);
 
 private:
     /**
 
 private:
     /**