Commit d49a3263 authored by Jakob Leben's avatar Jakob Leben

Qt: use Qt::DropAction properly throughout playlist drag-and-drop

parent 79944bce
......@@ -33,6 +33,7 @@
#include <QFontMetrics>
#include <QPixmapCache>
#include <QDrag>
#include <QDragMoveEvent>
#include "assert.h"
......@@ -319,6 +320,14 @@ static void plViewStartDrag( QAbstractItemView *view, const Qt::DropActions & su
drag->exec( supportedActions );
}
static void plViewDragMoveEvent( QAbstractItemView *view, QDragMoveEvent * event )
{
if( event->keyboardModifiers() & Qt::ControlModifier &&
event->possibleActions() & Qt::CopyAction )
event->setDropAction( Qt::CopyAction );
else event->acceptProposedAction();
}
PlIconView::PlIconView( PLModel *model, QWidget *parent ) : QListView( parent )
{
PlIconViewItemDelegate *delegate = new PlIconViewItemDelegate( this );
......@@ -344,6 +353,12 @@ void PlIconView::startDrag ( Qt::DropActions supportedActions )
plViewStartDrag( this, supportedActions );
}
void PlIconView::dragMoveEvent ( QDragMoveEvent * event )
{
plViewDragMoveEvent( this, event );
QAbstractItemView::dragMoveEvent( event );
}
PlListView::PlListView( PLModel *model, QWidget *parent ) : QListView( parent )
{
setModel( model );
......@@ -364,8 +379,19 @@ void PlListView::startDrag ( Qt::DropActions supportedActions )
plViewStartDrag( this, supportedActions );
}
void PlListView::dragMoveEvent ( QDragMoveEvent * event )
{
plViewDragMoveEvent( this, event );
QAbstractItemView::dragMoveEvent( event );
}
void PlTreeView::startDrag ( Qt::DropActions supportedActions )
{
plViewStartDrag( this, supportedActions );
}
void PlTreeView::dragMoveEvent ( QDragMoveEvent * event )
{
plViewDragMoveEvent( this, event );
QAbstractItemView::dragMoveEvent( event );
}
......@@ -70,6 +70,7 @@ public:
PlIconView( PLModel *model, QWidget *parent = 0 );
private:
void startDrag ( Qt::DropActions supportedActions );
void dragMoveEvent ( QDragMoveEvent * event );
};
class PlListView : public QListView
......@@ -80,6 +81,7 @@ public:
PlListView( PLModel *model, QWidget *parent = 0 );
private:
void startDrag ( Qt::DropActions supportedActions );
void dragMoveEvent ( QDragMoveEvent * event );
};
class PlTreeView : public QTreeView
......@@ -88,6 +90,7 @@ class PlTreeView : public QTreeView
private:
void startDrag ( Qt::DropActions supportedActions );
void dragMoveEvent ( QDragMoveEvent * event );
};
#endif
......
......@@ -108,7 +108,7 @@ PLModel::~PLModel()
Qt::DropActions PLModel::supportedDropActions() const
{
return Qt::CopyAction; /* Why not Qt::MoveAction */
return Qt::CopyAction | Qt::MoveAction;
}
Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
......@@ -189,33 +189,13 @@ QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent )
{
bool copy = action == Qt::CopyAction;
if( !copy && action != Qt::MoveAction )
return true;
const PlMimeData *plMimeData = qobject_cast<const PlMimeData*>( data );
if( plMimeData )
{
if( action == Qt::IgnoreAction )
return true;
PL_LOCK;
playlist_item_t *p_parent =
playlist_ItemGetById( p_playlist, itemId( parent ) );
if( !p_parent || p_parent->i_children == -1 )
{
PL_UNLOCK;
return false;
}
bool copy = false;
playlist_item_t *p_pl = p_playlist->p_playing;
playlist_item_t *p_ml = p_playlist->p_media_library;
if
(
row == -1 && (
( p_pl && p_parent == p_pl ) ||
( p_ml && p_parent == p_ml ) )
)
copy = true;
PL_UNLOCK;
if( copy )
dropAppendCopy( plMimeData, getItem( parent ) );
else
......
......@@ -372,6 +372,12 @@ bool PLSelector::dropMimeData ( QTreeWidgetItem * parent, int index,
return true;
}
void PLSelector::dragMoveEvent ( QDragMoveEvent * event )
{
event->setDropAction( Qt::CopyAction );
QAbstractItemView::dragMoveEvent( event );
}
void PLSelector::plItemAdded( int item, int parent )
{
if( parent != podcastsParentId ) return;
......
......@@ -119,6 +119,7 @@ protected:
private:
QStringList mimeTypes () const;
bool dropMimeData ( QTreeWidgetItem *, int, const QMimeData *, Qt::DropAction );
void dragMoveEvent ( QDragMoveEvent * event );
void createItems();
void drawBranches ( QPainter *, const QRect &, const QModelIndex & ) const;
PLSelItem * addItem (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment