- 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
}
void DolphinController::indicateDroppedUrls(const KUrl::List& urls,
}
void DolphinController::indicateDroppedUrls(const KUrl::List& urls,
+ const QModelIndex& index,
+ QWidget* source)
- emit urlsDropped(urls, pos);
+ emit urlsDropped(urls, index, source);
void triggerActivation();
void indicateDroppedUrls(const KUrl::List& urls,
void triggerActivation();
void indicateDroppedUrls(const KUrl::List& urls,
+ const QModelIndex& index,
+ QWidget* source);
void indicateSortingChange(DolphinView::Sorting sorting);
void indicateSortingChange(DolphinView::Sorting sorting);
- * 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 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);
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);
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 {
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)
#include <kfileitemdelegate.h>
#include <QAbstractProxyModel>
#include <kfileitemdelegate.h>
#include <QAbstractProxyModel>
DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
QListView(parent),
DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
QListView(parent),
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)
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)),
}
void DolphinView::dropUrls(const KUrl::List& urls,
}
void DolphinView::dropUrls(const KUrl::List& urls,
+ 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);
+ 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);
}
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 QModelIndex& index,
+ QWidget* source);
/**
* Drops the URLs \a urls at the
/**
* Drops the URLs \a urls at the
}
else {
event->acceptProposedAction();
}
else {
event->acceptProposedAction();
- emit urlsDropped(urls, event->pos());
+ const QModelIndex index = indexAt(event->pos());
+ if (index.isValid()) {
+ emit urlsDropped(urls, index);
+ }
- * 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 QModelIndex& index);
protected:
virtual bool event(QEvent* event);
protected:
virtual bool event(QEvent* event);
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);
}
void TreeViewSidebarPage::dropUrls(const KUrl::List& urls,
}
void TreeViewSidebarPage::dropUrls(const KUrl::List& urls,
+ 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);
/**
* 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 QModelIndex& index);