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 @@ ...@@ -33,6 +33,7 @@
#include <QFontMetrics> #include <QFontMetrics>
#include <QPixmapCache> #include <QPixmapCache>
#include <QDrag> #include <QDrag>
#include <QDragMoveEvent>
#include "assert.h" #include "assert.h"
...@@ -319,6 +320,14 @@ static void plViewStartDrag( QAbstractItemView *view, const Qt::DropActions & su ...@@ -319,6 +320,14 @@ static void plViewStartDrag( QAbstractItemView *view, const Qt::DropActions & su
drag->exec( supportedActions ); 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 ) PlIconView::PlIconView( PLModel *model, QWidget *parent ) : QListView( parent )
{ {
PlIconViewItemDelegate *delegate = new PlIconViewItemDelegate( this ); PlIconViewItemDelegate *delegate = new PlIconViewItemDelegate( this );
...@@ -344,6 +353,12 @@ void PlIconView::startDrag ( Qt::DropActions supportedActions ) ...@@ -344,6 +353,12 @@ void PlIconView::startDrag ( Qt::DropActions supportedActions )
plViewStartDrag( this, supportedActions ); plViewStartDrag( this, supportedActions );
} }
void PlIconView::dragMoveEvent ( QDragMoveEvent * event )
{
plViewDragMoveEvent( this, event );
QAbstractItemView::dragMoveEvent( event );
}
PlListView::PlListView( PLModel *model, QWidget *parent ) : QListView( parent ) PlListView::PlListView( PLModel *model, QWidget *parent ) : QListView( parent )
{ {
setModel( model ); setModel( model );
...@@ -364,8 +379,19 @@ void PlListView::startDrag ( Qt::DropActions supportedActions ) ...@@ -364,8 +379,19 @@ void PlListView::startDrag ( Qt::DropActions supportedActions )
plViewStartDrag( this, supportedActions ); plViewStartDrag( this, supportedActions );
} }
void PlListView::dragMoveEvent ( QDragMoveEvent * event )
{
plViewDragMoveEvent( this, event );
QAbstractItemView::dragMoveEvent( event );
}
void PlTreeView::startDrag ( Qt::DropActions supportedActions ) void PlTreeView::startDrag ( Qt::DropActions supportedActions )
{ {
plViewStartDrag( this, supportedActions ); plViewStartDrag( this, supportedActions );
} }
void PlTreeView::dragMoveEvent ( QDragMoveEvent * event )
{
plViewDragMoveEvent( this, event );
QAbstractItemView::dragMoveEvent( event );
}
...@@ -70,6 +70,7 @@ public: ...@@ -70,6 +70,7 @@ public:
PlIconView( PLModel *model, QWidget *parent = 0 ); PlIconView( PLModel *model, QWidget *parent = 0 );
private: private:
void startDrag ( Qt::DropActions supportedActions ); void startDrag ( Qt::DropActions supportedActions );
void dragMoveEvent ( QDragMoveEvent * event );
}; };
class PlListView : public QListView class PlListView : public QListView
...@@ -80,6 +81,7 @@ public: ...@@ -80,6 +81,7 @@ public:
PlListView( PLModel *model, QWidget *parent = 0 ); PlListView( PLModel *model, QWidget *parent = 0 );
private: private:
void startDrag ( Qt::DropActions supportedActions ); void startDrag ( Qt::DropActions supportedActions );
void dragMoveEvent ( QDragMoveEvent * event );
}; };
class PlTreeView : public QTreeView class PlTreeView : public QTreeView
...@@ -88,6 +90,7 @@ class PlTreeView : public QTreeView ...@@ -88,6 +90,7 @@ class PlTreeView : public QTreeView
private: private:
void startDrag ( Qt::DropActions supportedActions ); void startDrag ( Qt::DropActions supportedActions );
void dragMoveEvent ( QDragMoveEvent * event );
}; };
#endif #endif
......
...@@ -108,7 +108,7 @@ PLModel::~PLModel() ...@@ -108,7 +108,7 @@ PLModel::~PLModel()
Qt::DropActions PLModel::supportedDropActions() const 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 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
...@@ -189,33 +189,13 @@ QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const ...@@ -189,33 +189,13 @@ QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action, bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent ) int row, int column, const QModelIndex &parent )
{ {
const PlMimeData *plMimeData = qobject_cast<const PlMimeData*>( data ); bool copy = action == Qt::CopyAction;
if( plMimeData ) if( !copy && action != Qt::MoveAction )
{
if( action == Qt::IgnoreAction )
return true; return true;
PL_LOCK; const PlMimeData *plMimeData = qobject_cast<const PlMimeData*>( data );
playlist_item_t *p_parent = if( plMimeData )
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 ) if( copy )
dropAppendCopy( plMimeData, getItem( parent ) ); dropAppendCopy( plMimeData, getItem( parent ) );
else else
......
...@@ -372,6 +372,12 @@ bool PLSelector::dropMimeData ( QTreeWidgetItem * parent, int index, ...@@ -372,6 +372,12 @@ bool PLSelector::dropMimeData ( QTreeWidgetItem * parent, int index,
return true; return true;
} }
void PLSelector::dragMoveEvent ( QDragMoveEvent * event )
{
event->setDropAction( Qt::CopyAction );
QAbstractItemView::dragMoveEvent( event );
}
void PLSelector::plItemAdded( int item, int parent ) void PLSelector::plItemAdded( int item, int parent )
{ {
if( parent != podcastsParentId ) return; if( parent != podcastsParentId ) return;
......
...@@ -119,6 +119,7 @@ protected: ...@@ -119,6 +119,7 @@ protected:
private: private:
QStringList mimeTypes () const; QStringList mimeTypes () const;
bool dropMimeData ( QTreeWidgetItem *, int, const QMimeData *, Qt::DropAction ); bool dropMimeData ( QTreeWidgetItem *, int, const QMimeData *, Qt::DropAction );
void dragMoveEvent ( QDragMoveEvent * event );
void createItems(); void createItems();
void drawBranches ( QPainter *, const QRect &, const QModelIndex & ) const; void drawBranches ( QPainter *, const QRect &, const QModelIndex & ) const;
PLSelItem * addItem ( 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