mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-25 23:06:23 +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 )
|
DropJob::DropJob( QObject *parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
|
, m_queryCount( 0 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,8 +188,11 @@ DropJob::tracksFromAlbumMetaData( const QMimeData *data )
|
|||||||
artist_ptr artistPtr = Artist::get( artist );
|
artist_ptr artistPtr = Artist::get( artist );
|
||||||
album_ptr albumPtr = Album::get( artistPtr, album );
|
album_ptr albumPtr = Album::get( artistPtr, album );
|
||||||
if ( albumPtr->tracks().isEmpty() )
|
if ( albumPtr->tracks().isEmpty() )
|
||||||
|
{
|
||||||
connect( albumPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
connect( albumPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
||||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
||||||
|
m_queryCount++;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
queries << albumPtr->tracks();
|
queries << albumPtr->tracks();
|
||||||
}
|
}
|
||||||
@@ -209,8 +213,11 @@ DropJob::tracksFromArtistMetaData( const QMimeData *data )
|
|||||||
|
|
||||||
artist_ptr artistPtr = Artist::get( artist );
|
artist_ptr artistPtr = Artist::get( artist );
|
||||||
if ( artistPtr->tracks().isEmpty() )
|
if ( artistPtr->tracks().isEmpty() )
|
||||||
|
{
|
||||||
connect( artistPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
connect( artistPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
||||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
||||||
|
m_queryCount++;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
queries << artistPtr->tracks();
|
queries << artistPtr->tracks();
|
||||||
}
|
}
|
||||||
@@ -309,5 +316,6 @@ DropJob::onTracksAdded( const QList<Tomahawk::query_ptr>& tracksList )
|
|||||||
{
|
{
|
||||||
qDebug() << "here i am with" << tracksList.count() << "tracks";
|
qDebug() << "here i am with" << tracksList.count() << "tracks";
|
||||||
emit tracks( tracksList );
|
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 > tracksFromAlbumMetaData( const QMimeData* d );
|
||||||
QList< Tomahawk::query_ptr > tracksFromMixedData( const QMimeData* d );
|
QList< Tomahawk::query_ptr > tracksFromMixedData( const QMimeData* d );
|
||||||
|
|
||||||
|
int m_queryCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DROPJOB_H
|
#endif // DROPJOB_H
|
||||||
|
@@ -159,6 +159,7 @@ AlbumModel::headerData( int section, Qt::Orientation orientation, int role ) con
|
|||||||
Qt::ItemFlags
|
Qt::ItemFlags
|
||||||
AlbumModel::flags( const QModelIndex& index ) const
|
AlbumModel::flags( const QModelIndex& index ) const
|
||||||
{
|
{
|
||||||
|
qDebug() << "asking for flags for index" << index;
|
||||||
Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
|
Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
|
||||||
|
|
||||||
if ( index.isValid() && index.column() == 0 )
|
if ( index.isValid() && index.column() == 0 )
|
||||||
@@ -195,12 +196,13 @@ AlbumModel::mimeData( const QModelIndexList &indexes ) const
|
|||||||
if ( item )
|
if ( item )
|
||||||
{
|
{
|
||||||
const album_ptr& album = item->album();
|
const album_ptr& album = item->album();
|
||||||
queryStream << qlonglong( &album );
|
queryStream << album->artist()->name();
|
||||||
|
queryStream << album->name();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QMimeData* mimeData = new QMimeData();
|
QMimeData* mimeData = new QMimeData();
|
||||||
mimeData->setData( "application/tomahawk.query.list", queryData );
|
mimeData->setData( "application/tomahawk.metadata.album", queryData );
|
||||||
|
|
||||||
return mimeData;
|
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
|
void
|
||||||
AlbumView::paintEvent( QPaintEvent* event )
|
AlbumView::paintEvent( QPaintEvent* event )
|
||||||
{
|
{
|
||||||
@@ -227,14 +206,30 @@ AlbumView::onFilterChanged( const QString& )
|
|||||||
void
|
void
|
||||||
AlbumView::startDrag( Qt::DropActions supportedActions )
|
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
|
qDebug() << "Dragging" << indexes.count() << "indexes";
|
||||||
QPixmap
|
QMimeData* data = m_proxyModel->mimeData( indexes );
|
||||||
AlbumView::createDragPixmap( int itemCount ) const
|
if ( !data )
|
||||||
{
|
return;
|
||||||
Q_UNUSED( itemCount );
|
|
||||||
return QPixmap();
|
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:
|
protected:
|
||||||
virtual void startDrag( Qt::DropActions supportedActions );
|
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 );
|
void paintEvent( QPaintEvent* event );
|
||||||
|
|
||||||
@@ -73,8 +70,6 @@ private slots:
|
|||||||
void onScrollTimeout();
|
void onScrollTimeout();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPixmap createDragPixmap( int itemCount ) const;
|
|
||||||
|
|
||||||
AlbumModel* m_model;
|
AlbumModel* m_model;
|
||||||
AlbumProxyModel* m_proxyModel;
|
AlbumProxyModel* m_proxyModel;
|
||||||
// PlaylistItemDelegate* m_delegate;
|
// PlaylistItemDelegate* m_delegate;
|
||||||
|
@@ -40,6 +40,15 @@
|
|||||||
<height>192</height>
|
<height>192</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</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>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@@ -84,16 +93,16 @@
|
|||||||
<extends>QLabel</extends>
|
<extends>QLabel</extends>
|
||||||
<header location="global">widgets/HeaderLabel.h</header>
|
<header location="global">widgets/HeaderLabel.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
|
||||||
<class>PlaylistView</class>
|
|
||||||
<extends>QTreeView</extends>
|
|
||||||
<header>playlist/playlistview.h</header>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>AlbumView</class>
|
<class>AlbumView</class>
|
||||||
<extends>QListView</extends>
|
<extends>QListView</extends>
|
||||||
<header>playlist/albumview.h</header>
|
<header>playlist/albumview.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>PlaylistView</class>
|
||||||
|
<extends>QTreeView</extends>
|
||||||
|
<header>playlist/playlistview.h</header>
|
||||||
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>CollectionView</class>
|
<class>CollectionView</class>
|
||||||
<extends>QTreeView</extends>
|
<extends>QTreeView</extends>
|
||||||
|
@@ -30,7 +30,14 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<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>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@@ -49,7 +56,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="">
|
<widget class="QWidget" name="layoutWidget">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="HeaderLabel" name="label_3">
|
<widget class="HeaderLabel" name="label_3">
|
||||||
@@ -80,16 +87,16 @@
|
|||||||
<extends>QLabel</extends>
|
<extends>QLabel</extends>
|
||||||
<header location="global">widgets/HeaderLabel.h</header>
|
<header location="global">widgets/HeaderLabel.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
|
||||||
<class>PlaylistView</class>
|
|
||||||
<extends>QTreeView</extends>
|
|
||||||
<header>playlist/playlistview.h</header>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>AlbumView</class>
|
<class>AlbumView</class>
|
||||||
<extends>QListView</extends>
|
<extends>QListView</extends>
|
||||||
<header>playlist/albumview.h</header>
|
<header>playlist/albumview.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>PlaylistView</class>
|
||||||
|
<extends>QTreeView</extends>
|
||||||
|
<header>playlist/playlistview.h</header>
|
||||||
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>PlaylistWidget</class>
|
<class>PlaylistWidget</class>
|
||||||
<extends>QListWidget</extends>
|
<extends>QListWidget</extends>
|
||||||
|
Reference in New Issue
Block a user