mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-02 14:45:04 +00:00
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
This commit is contained in:
parent
277e385fd8
commit
49f881f5ec
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <kfileitemdelegate.h>
|
||||
|
||||
#include <QAbstractProxyModel>
|
||||
#include <QPoint>
|
||||
|
||||
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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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:
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue