From: Peter Penz Date: Sun, 11 Mar 2007 11:13:07 +0000 (+0000) Subject: Fixed some drag & drop issues: X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/49f881f5ec01014e7b6b0c7fa14abd7e99f605fc Fixed some drag & drop issues: - 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 --- diff --git a/src/dolphincontroller.cpp b/src/dolphincontroller.cpp index ea9c25211..288083533 100644 --- a/src/dolphincontroller.cpp +++ b/src/dolphincontroller.cpp @@ -43,9 +43,10 @@ void DolphinController::triggerActivation() } void DolphinController::indicateDroppedUrls(const KUrl::List& urls, - const QPoint& pos) + const QModelIndex& index, + QWidget* source) { - emit urlsDropped(urls, pos); + emit urlsDropped(urls, index, source); } diff --git a/src/dolphincontroller.h b/src/dolphincontroller.h index 1bd283fd4..6edf6eba9 100644 --- a/src/dolphincontroller.h +++ b/src/dolphincontroller.h @@ -61,7 +61,8 @@ public: void triggerActivation(); void indicateDroppedUrls(const KUrl::List& urls, - const QPoint& pos); + const QModelIndex& index, + QWidget* source); void indicateSortingChange(DolphinView::Sorting sorting); @@ -98,14 +99,13 @@ signals: 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, - const QPoint& pos); + const QModelIndex& index, + QWidget* source); /** Is emitted if the sorting has been changed to \a sorting. */ void sortingChanged(DolphinView::Sorting sorting); diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index 773779976..c019f8eb0 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -43,6 +43,8 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr setSortingEnabled(true); setUniformRowHeights(true); setSelectionBehavior(SelectItems); + setDragDropMode(QAbstractItemView::DragDrop); + setDropIndicatorShown(false); 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()); - if (urls.isEmpty() || (event->source() == this)) { - QTreeView::dropEvent(event); - } - else { + if (!urls.isEmpty()) { 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) diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index c2ba82d0d..1871bb6d9 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -29,6 +29,7 @@ #include #include +#include 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()); - if (urls.isEmpty() || (event->source() == this)) { - QListView::dropEvent(event); - } - else { + if (!urls.isEmpty()) { + m_controller->indicateDroppedUrls(urls, + indexAt(event->pos()), + event->source()); event->acceptProposedAction(); - m_controller->indicateDroppedUrls(urls, event->pos()); } + QListView::dropEvent(event); } void DolphinIconsView::updateGridSize(bool showPreview) diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 50f56a478..3a6a2e757 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -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&))); - 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)), @@ -971,10 +971,10 @@ void DolphinView::openContextMenu(const QPoint& pos) } void DolphinView::dropUrls(const KUrl::List& urls, - const QPoint& pos) + const QModelIndex& index, + QWidget* source) { KFileItem* directory = 0; - const QModelIndex index = itemView()->indexAt(pos); 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(); + + kDebug() << "DolphinView::dropUrls() - destination: " << destination.prettyUrl() << endl; + dropUrls(urls, destination); } diff --git a/src/dolphinview.h b/src/dolphinview.h index 5cfd7904d..8ca4a1ac3 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -449,12 +449,12 @@ private slots: 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, - const QPoint& pos); + const QModelIndex& index, + QWidget* source); /** * Drops the URLs \a urls at the diff --git a/src/sidebartreeview.cpp b/src/sidebartreeview.cpp index 52b6d5424..e5661cd0b 100644 --- a/src/sidebartreeview.cpp +++ b/src/sidebartreeview.cpp @@ -77,7 +77,10 @@ void SidebarTreeView::dropEvent(QDropEvent* event) } else { event->acceptProposedAction(); - emit urlsDropped(urls, event->pos()); + const QModelIndex index = indexAt(event->pos()); + if (index.isValid()) { + emit urlsDropped(urls, index); + } } } diff --git a/src/sidebartreeview.h b/src/sidebartreeview.h index 8b1f039a0..f7360e9c4 100644 --- a/src/sidebartreeview.h +++ b/src/sidebartreeview.h @@ -40,14 +40,11 @@ public: 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, - const QPoint& pos); + const QModelIndex& index); protected: virtual bool event(QEvent* event); diff --git a/src/treeviewsidebarpage.cpp b/src/treeviewsidebarpage.cpp index d9c2e8800..63689b6eb 100644 --- a/src/treeviewsidebarpage.cpp +++ b/src/treeviewsidebarpage.cpp @@ -78,8 +78,8 @@ TreeViewSidebarPage::TreeViewSidebarPage(DolphinMainWindow* mainWindow, 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); @@ -202,9 +202,8 @@ void TreeViewSidebarPage::updateActiveView(const QModelIndex& index) } 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); diff --git a/src/treeviewsidebarpage.h b/src/treeviewsidebarpage.h index ca98277eb..7a4541cb3 100644 --- a/src/treeviewsidebarpage.h +++ b/src/treeviewsidebarpage.h @@ -74,9 +74,9 @@ private slots: /** * 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, - const QPoint& pos); + const QModelIndex& index); private: /**