mirror of
https://invent.kde.org/system/dolphin
synced 2024-07-04 17:30:55 +00:00
Reanimated drag & drop support for the icons view.
svn path=/trunk/playground/utils/dolphin/; revision=620649
This commit is contained in:
parent
86ad5d0a63
commit
8fb8b7d711
|
@ -19,14 +19,17 @@
|
|||
***************************************************************************/
|
||||
|
||||
#include "dolphiniconsview.h"
|
||||
#include "dolphinmainwindow.h"
|
||||
#include "dolphinview.h"
|
||||
|
||||
#include <kdirmodel.h>
|
||||
#include <kfileitem.h>
|
||||
|
||||
#include <QAbstractProxyModel>
|
||||
|
||||
DolphinIconsView::DolphinIconsView(DolphinView* parent) :
|
||||
QListView(parent),
|
||||
m_parentView( parent )
|
||||
m_parentView(parent)
|
||||
{
|
||||
setResizeMode(QListView::Adjust);
|
||||
}
|
||||
|
@ -58,11 +61,8 @@ void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
|
|||
|
||||
const QModelIndex index = indexAt(event->pos());
|
||||
if (index.isValid()) {
|
||||
// TODO: assuming that model() returns an instance of the class
|
||||
// KDirModel is dangerous, especially in combination with a proxy model.
|
||||
// As the current test implementation of proxy model does not work, this
|
||||
// will be cleaned up later.
|
||||
KDirModel* dirModel = static_cast<KDirModel*>(model());
|
||||
const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
|
||||
const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
|
||||
item = dirModel->itemForIndex(index);
|
||||
}
|
||||
|
||||
|
@ -75,4 +75,24 @@ void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event)
|
|||
m_parentView->declareViewActive();
|
||||
}
|
||||
|
||||
void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls()) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
void DolphinIconsView::dropEvent(QDropEvent* event)
|
||||
{
|
||||
const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
|
||||
if (!urls.isEmpty()) {
|
||||
event->acceptProposedAction();
|
||||
|
||||
// TODO: handle dropping above a directory
|
||||
|
||||
const KUrl& destination = m_parentView->url();
|
||||
m_parentView->mainWindow()->dropUrls(urls, destination);
|
||||
}
|
||||
}
|
||||
|
||||
#include "dolphiniconsview.moc"
|
||||
|
|
|
@ -45,6 +45,8 @@ protected:
|
|||
virtual QStyleOptionViewItem viewOptions() const;
|
||||
virtual void contextMenuEvent(QContextMenuEvent* event);
|
||||
virtual void mouseReleaseEvent(QMouseEvent* event);
|
||||
virtual void dragEnterEvent(QDragEnterEvent* event);
|
||||
virtual void dropEvent(QDropEvent* event);
|
||||
|
||||
private:
|
||||
DolphinView* m_parentView;
|
||||
|
|
|
@ -105,6 +105,7 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow,
|
|||
|
||||
m_dirModel = new KDirModel();
|
||||
m_dirModel->setDirLister(m_dirLister);
|
||||
m_dirModel->setDropsAllowed(KDirModel::DropOnDirectory);
|
||||
|
||||
m_proxyModel = new DolphinSortFilterProxyModel(this);
|
||||
m_proxyModel->setSourceModel(m_dirModel);
|
||||
|
|
Loading…
Reference in New Issue
Block a user