mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-25 06:51:13 +02:00
added drag capabilities to albumview ins sourceinfowidget and welcomewidget
This commit is contained in:
@@ -32,6 +32,7 @@ using namespace Tomahawk;
|
||||
|
||||
DropJob::DropJob( QObject *parent )
|
||||
: QObject( parent )
|
||||
, m_queryCount( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -187,8 +188,11 @@ DropJob::tracksFromAlbumMetaData( const QMimeData *data )
|
||||
artist_ptr artistPtr = Artist::get( artist );
|
||||
album_ptr albumPtr = Album::get( artistPtr, album );
|
||||
if ( albumPtr->tracks().isEmpty() )
|
||||
{
|
||||
connect( albumPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
||||
m_queryCount++;
|
||||
}
|
||||
else
|
||||
queries << albumPtr->tracks();
|
||||
}
|
||||
@@ -209,8 +213,11 @@ DropJob::tracksFromArtistMetaData( const QMimeData *data )
|
||||
|
||||
artist_ptr artistPtr = Artist::get( artist );
|
||||
if ( artistPtr->tracks().isEmpty() )
|
||||
{
|
||||
connect( artistPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
||||
m_queryCount++;
|
||||
}
|
||||
else
|
||||
queries << artistPtr->tracks();
|
||||
}
|
||||
@@ -309,5 +316,6 @@ DropJob::onTracksAdded( const QList<Tomahawk::query_ptr>& tracksList )
|
||||
{
|
||||
qDebug() << "here i am with" << tracksList.count() << "tracks";
|
||||
emit tracks( tracksList );
|
||||
deleteLater();
|
||||
if ( --m_queryCount == 0 )
|
||||
deleteLater();
|
||||
}
|
||||
|
@@ -63,6 +63,7 @@ private:
|
||||
QList< Tomahawk::query_ptr > tracksFromAlbumMetaData( const QMimeData* d );
|
||||
QList< Tomahawk::query_ptr > tracksFromMixedData( const QMimeData* d );
|
||||
|
||||
int m_queryCount;
|
||||
};
|
||||
|
||||
#endif // DROPJOB_H
|
||||
|
@@ -159,6 +159,7 @@ AlbumModel::headerData( int section, Qt::Orientation orientation, int role ) con
|
||||
Qt::ItemFlags
|
||||
AlbumModel::flags( const QModelIndex& index ) const
|
||||
{
|
||||
qDebug() << "asking for flags for index" << index;
|
||||
Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
|
||||
|
||||
if ( index.isValid() && index.column() == 0 )
|
||||
@@ -195,12 +196,13 @@ AlbumModel::mimeData( const QModelIndexList &indexes ) const
|
||||
if ( item )
|
||||
{
|
||||
const album_ptr& album = item->album();
|
||||
queryStream << qlonglong( &album );
|
||||
queryStream << album->artist()->name();
|
||||
queryStream << album->name();
|
||||
}
|
||||
}
|
||||
|
||||
QMimeData* mimeData = new QMimeData();
|
||||
mimeData->setData( "application/tomahawk.query.list", queryData );
|
||||
mimeData->setData( "application/tomahawk.metadata.album", queryData );
|
||||
|
||||
return mimeData;
|
||||
}
|
||||
|
@@ -188,27 +188,6 @@ AlbumView::onScrollTimeout()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlbumView::dragEnterEvent( QDragEnterEvent* event )
|
||||
{
|
||||
QListView::dragEnterEvent( event );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlbumView::dragMoveEvent( QDragMoveEvent* event )
|
||||
{
|
||||
QListView::dragMoveEvent( event );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlbumView::dropEvent( QDropEvent* event )
|
||||
{
|
||||
QListView::dropEvent( event );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlbumView::paintEvent( QPaintEvent* event )
|
||||
{
|
||||
@@ -227,14 +206,30 @@ AlbumView::onFilterChanged( const QString& )
|
||||
void
|
||||
AlbumView::startDrag( Qt::DropActions supportedActions )
|
||||
{
|
||||
Q_UNUSED( supportedActions );
|
||||
}
|
||||
QList<QPersistentModelIndex> pindexes;
|
||||
QModelIndexList indexes;
|
||||
foreach( const QModelIndex& idx, selectedIndexes() )
|
||||
{
|
||||
if ( ( m_proxyModel->flags( idx ) & Qt::ItemIsDragEnabled ) )
|
||||
{
|
||||
indexes << idx;
|
||||
pindexes << idx;
|
||||
}
|
||||
}
|
||||
|
||||
if ( indexes.count() == 0 )
|
||||
return;
|
||||
|
||||
// Inspired from dolphin's draganddrophelper.cpp
|
||||
QPixmap
|
||||
AlbumView::createDragPixmap( int itemCount ) const
|
||||
{
|
||||
Q_UNUSED( itemCount );
|
||||
return QPixmap();
|
||||
qDebug() << "Dragging" << indexes.count() << "indexes";
|
||||
QMimeData* data = m_proxyModel->mimeData( indexes );
|
||||
if ( !data )
|
||||
return;
|
||||
|
||||
QDrag* drag = new QDrag( this );
|
||||
drag->setMimeData( data );
|
||||
const QPixmap p = TomahawkUtils::createDragPixmap( indexes.count() );
|
||||
drag->setPixmap( p );
|
||||
drag->setHotSpot( QPoint( -20, -20 ) );
|
||||
|
||||
Qt::DropAction action = drag->exec( supportedActions, Qt::CopyAction );
|
||||
}
|
||||
|
@@ -60,9 +60,6 @@ public slots:
|
||||
|
||||
protected:
|
||||
virtual void startDrag( Qt::DropActions supportedActions );
|
||||
virtual void dragEnterEvent( QDragEnterEvent* event );
|
||||
virtual void dragMoveEvent( QDragMoveEvent* event );
|
||||
virtual void dropEvent( QDropEvent* event );
|
||||
|
||||
void paintEvent( QPaintEvent* event );
|
||||
|
||||
@@ -73,8 +70,6 @@ private slots:
|
||||
void onScrollTimeout();
|
||||
|
||||
private:
|
||||
QPixmap createDragPixmap( int itemCount ) const;
|
||||
|
||||
AlbumModel* m_model;
|
||||
AlbumProxyModel* m_proxyModel;
|
||||
// PlaylistItemDelegate* m_delegate;
|
||||
|
@@ -40,6 +40,15 @@
|
||||
<height>192</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::DragDrop</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -84,16 +93,16 @@
|
||||
<extends>QLabel</extends>
|
||||
<header location="global">widgets/HeaderLabel.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>PlaylistView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header>playlist/playlistview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>AlbumView</class>
|
||||
<extends>QListView</extends>
|
||||
<header>playlist/albumview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>PlaylistView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header>playlist/playlistview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>CollectionView</class>
|
||||
<extends>QTreeView</extends>
|
||||
|
@@ -30,7 +30,14 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="AlbumView" name="additionsView"/>
|
||||
<widget class="AlbumView" name="additionsView">
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@@ -49,7 +56,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="">
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="HeaderLabel" name="label_3">
|
||||
@@ -80,16 +87,16 @@
|
||||
<extends>QLabel</extends>
|
||||
<header location="global">widgets/HeaderLabel.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>PlaylistView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header>playlist/playlistview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>AlbumView</class>
|
||||
<extends>QListView</extends>
|
||||
<header>playlist/albumview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>PlaylistView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header>playlist/playlistview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>PlaylistWidget</class>
|
||||
<extends>QListWidget</extends>
|
||||
|
Reference in New Issue
Block a user