mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-13 20:39:57 +01:00
Add prettier drag pixmap.
Still needs to be added to PlaylistModel---potentially refactored out into somewhere shared. Also, only allow once column in the source model to be dragged, so we get the right amount of drag items.
This commit is contained in:
parent
2f14b4f753
commit
2fbd1b6bf1
BIN
data/icons/audio-x-generic-16.png
Normal file
BIN
data/icons/audio-x-generic-16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 643 B |
BIN
data/icons/audio-x-generic-22.png
Normal file
BIN
data/icons/audio-x-generic-22.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 856 B |
BIN
data/icons/audio-x-generic-32.png
Normal file
BIN
data/icons/audio-x-generic-32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
@ -67,5 +67,8 @@
|
||||
<file>./data/icons/tomahawk-icon-128.png</file>
|
||||
<file>./data/icons/tomahawk-icon-256.png</file>
|
||||
<file>./data/icons/tomahawk-icon-512.png</file>
|
||||
<file>./data/icons/audio-x-generic-22.png</file>
|
||||
<file>./data/icons/audio-x-generic-32.png</file>
|
||||
<file>./data/icons/audio-x-generic-16.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -219,6 +219,36 @@ CollectionView::keyPressEvent( QKeyEvent* event )
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CollectionView::startDrag( Qt::DropActions supportedActions )
|
||||
{
|
||||
QModelIndexList indexes = selectedIndexes();
|
||||
qDebug() << "Dragging" << indexes.count() << "indexes";
|
||||
for( int i = indexes.count() - 1 ; i >= 0; --i ) {
|
||||
if( !( m_proxyModel->flags( indexes.at( i ) ) & Qt::ItemIsDragEnabled ) )
|
||||
indexes.removeAt(i);
|
||||
}
|
||||
|
||||
if( indexes.count() == 0 )
|
||||
return;
|
||||
|
||||
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 = createDragPixmap( indexes.count() );
|
||||
drag->setPixmap( p );
|
||||
drag->setHotSpot( QPoint( -20, -20 ) );
|
||||
|
||||
// NOTE: if we support moving items in the model
|
||||
// in the future, if exec() returns Qt::MoveAction
|
||||
// we need to clean up ourselves.
|
||||
drag->exec( supportedActions, Qt::CopyAction );
|
||||
}
|
||||
|
||||
void
|
||||
CollectionView::dragEnterEvent( QDragEnterEvent* event )
|
||||
@ -331,3 +361,56 @@ CollectionView::onFilterChanged( const QString& )
|
||||
if ( selectedIndexes().count() )
|
||||
scrollTo( selectedIndexes().at( 0 ), QAbstractItemView::PositionAtCenter );
|
||||
}
|
||||
|
||||
// Inspired from dolphin's draganddrophelper.cpp
|
||||
QPixmap
|
||||
CollectionView::createDragPixmap( int itemCount ) const
|
||||
{
|
||||
// If more than one item is dragged, align the items inside a
|
||||
// rectangular grid. The maximum grid size is limited to 5 x 5 items.
|
||||
int xCount = 3;
|
||||
int size = 32;
|
||||
if ( itemCount > 16 ) {
|
||||
xCount = 5;
|
||||
size = 16;
|
||||
} else if( itemCount > 9 ) {
|
||||
xCount = 4;
|
||||
size = 22;
|
||||
}
|
||||
|
||||
if( itemCount < xCount ) {
|
||||
xCount = itemCount;
|
||||
}
|
||||
|
||||
int yCount = itemCount / xCount;
|
||||
if( itemCount % xCount != 0 ) {
|
||||
++yCount;
|
||||
}
|
||||
if( yCount > xCount ) {
|
||||
yCount = xCount;
|
||||
}
|
||||
// Draw the selected items into the grid cells
|
||||
QPixmap dragPixmap( xCount * size + xCount - 1, yCount * size + yCount - 1 );
|
||||
dragPixmap.fill( Qt::transparent );
|
||||
|
||||
QPainter painter(&dragPixmap);
|
||||
painter.setRenderHint( QPainter::Antialiasing );
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
for( int i = 0; i < itemCount; ++i ) {
|
||||
const QPixmap pixmap = QPixmap( QString( ":/data/icons/audio-x-generic-%2.png" ).arg( size ) );
|
||||
painter.drawPixmap(x, y, pixmap);
|
||||
|
||||
x += size + 1;
|
||||
if (x >= dragPixmap.width()) {
|
||||
x = 0;
|
||||
y += size + 1;
|
||||
}
|
||||
if (y >= dragPixmap.height()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return dragPixmap;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,8 @@ public:
|
||||
protected:
|
||||
virtual void resizeEvent( QResizeEvent* event );
|
||||
virtual void keyPressEvent( QKeyEvent* event );
|
||||
|
||||
|
||||
virtual void startDrag( Qt::DropActions supportedActions );
|
||||
virtual void dragEnterEvent( QDragEnterEvent* event );
|
||||
virtual void dragLeaveEvent( QDragLeaveEvent* event ) { m_dragging = false; setDirtyRegion( m_dropRect ); }
|
||||
virtual void dragMoveEvent( QDragMoveEvent* event );
|
||||
@ -52,6 +53,7 @@ private slots:
|
||||
private:
|
||||
void restoreColumnsState();
|
||||
void saveColumnsState();
|
||||
QPixmap createDragPixmap( int itemCount ) const;
|
||||
|
||||
TrackModel* m_model;
|
||||
PlaylistInterface* m_modelInterface;
|
||||
|
@ -127,7 +127,7 @@ TrackModel::flags( const QModelIndex& index ) const
|
||||
{
|
||||
Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
|
||||
|
||||
if ( index.isValid() )
|
||||
if ( index.isValid() && index.column() == 0 )
|
||||
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
|
||||
else
|
||||
return Qt::ItemIsDropEnabled | defaultFlags;
|
||||
|
Loading…
x
Reference in New Issue
Block a user