From 2fbd1b6bf11765e1193af9d6070b9666ddf50650 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Thu, 21 Oct 2010 22:36:41 -0400 Subject: [PATCH] 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. --- data/icons/audio-x-generic-16.png | Bin 0 -> 643 bytes data/icons/audio-x-generic-22.png | Bin 0 -> 856 bytes data/icons/audio-x-generic-32.png | Bin 0 -> 1485 bytes resources.qrc | 3 ++ src/playlist/collectionview.cpp | 83 ++++++++++++++++++++++++++++++ src/playlist/collectionview.h | 4 +- src/playlist/trackmodel.cpp | 2 +- 7 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 data/icons/audio-x-generic-16.png create mode 100644 data/icons/audio-x-generic-22.png create mode 100644 data/icons/audio-x-generic-32.png diff --git a/data/icons/audio-x-generic-16.png b/data/icons/audio-x-generic-16.png new file mode 100644 index 0000000000000000000000000000000000000000..017b00da90f5f743e448303e13a74aed5f27494f GIT binary patch literal 643 zcmV-}0(||6P)#_p*zkRy zNrnOp1DdGG>^V}+I4~yliNsLEFp@8BW4pS|aU`@pF&%N2FgYl;IDZpQKRtmoFjZJ7 zkl_MM9u9~2U9C=Sw9FV*bE_zQ-$JEQf$O^5Y<2{m?fB>jsZ$qL^&b))c zV1Ps-!8y9}OC#j-dDQE5#9}cb1qFKSm+mZ~rj!*51^U(_m|+FcXcU=D2A{hh@#^?F zetbJY`|zA|bCEeXjzjN-RO(wWG4s;?_y>6Q^C311U+~s@4fF3;%JTU%n@w~&|6tpe zPv+W!2QL0DE@kkYvLB(JbK4n8;u5Xxg6-VmP%Xi0qiqDN>;M0WJ%BSB+W+h z6p5h-vfuB^ot<6IZEUQ6pnk+7=mM0yg3RdkdU9`Xe_VW7TxVhklixW-S51`}+NR>Z d+Ixr@y8u>P6SCqpiBbRn002ovPDHLkV1kEiA;16t literal 0 HcmV?d00001 diff --git a/data/icons/audio-x-generic-22.png b/data/icons/audio-x-generic-22.png new file mode 100644 index 0000000000000000000000000000000000000000..e2c40f1da4e84d06414be0afb722f02f3b85cf0d GIT binary patch literal 856 zcmeAS@N?(olHy`uVBq!ia0vp^Vj#@H3?x5i&EW)6%*9TgAsieWw;%dH0CG7CJR*yM zqGce=SbMeU3{X(A#5JNMI6tkVJh3R1p}f3YFEcN@I61K(RWH9NefB#WDFz0{<^Z1% z*Z=?j1Jy%-ii(PsmKKC}E%_5=mPiRwm^)J!IsSe2VuZIG~Cst~%^DQas}^m)~U zONQmQLdzcn)jsi?^`dIgl|{>L&02YF<=VAt*R5Z_;n>=Z8#iv+v}yCj%{%Y!-2H0J z-cJh;JUnpt=^>y4jz2qk5(u6iIraF&X&`uh?9B5MXMx}x7`!-n{`~n17cO3WdFB!j zygG9k2wq*ja^=cZAh>qz=FOXT?%cWi?(Tgccz5r~`zKGIJ%9e<#q$?0U%qhK|L*;V_dxLB!}}kvKY+l;4<8}m)5lMrK7N1u2?#!e!51+2 z3I^XG;QP1lVDJMBe*XCJ69j(!`t=(K{`~&)=g;52fB*ga7k=I9H89WxOM?7@8D!*? z3{5R8t!>?(Jp2Cr*RQZl9%W!$X?eOhhE&|jy|~}o*-(J}!~0mhZ4s+=ON)eJuee5) zyngfG#r=o%N#Ew`R|o4mg^Z`y1AkdGCiw&q*-wDbfN&t;ucLK6UNRMxft literal 0 HcmV?d00001 diff --git a/data/icons/audio-x-generic-32.png b/data/icons/audio-x-generic-32.png new file mode 100644 index 0000000000000000000000000000000000000000..8a30401bfaaab7512dfdfc799c9c1c4db9d554d7 GIT binary patch literal 1485 zcmbu<2~*QY7zf~m6uAt+60s305jmnF0*Y4DLShi8$R%Z>(pD^Dff10~1B=vZyo!WI zIYd!G$`Py+5JAX6FdPO$Kmw6)21tMehzCK=E`L8lpV|HG?9R^4?Cd*x&DYxVt);eK4}*fb1G+I?^*z~pZasM_^+UJ=H-vGvIe&I4C(e`FB=qdgDzR#G%pY^uofzBB-;dxVX4P zQc_x4$`F(>%a^bDd?xROw79yuy0*5K#bUA9oMl{YU0ofI$E&Zee+8*u@cH}(sE5}e zYiMk0dj0yf0BUIw3Wcq$tsc^^z`)hA=Hw7XaF%eFgPe1lp%%?!-x_2@cZErNG>0dE98(uAy-RJ85>Xk$ylZ`7E7j0)-j9{_<>`5jDB)vPGaVWyX z4|_$}kb5nR!Fc$Qmmms1BMKEo2H^q%jHQa+KkanlCw+{u<9tTHd2|8(I<<>_;^4Eq zzAAGQE%SjyV|F$s;b$70y!j^M7D617nn+!YOxW7G+XC& zYe{rMEkekN4ow>}n-g3+`>pK~{^(9SeV^*j8CGm@$e@?8Lbx^SZg}a=(n{+2J8qso zw~(8c#7s;-48%)b7yikxy7#iO^FB>8NM>9KyV~4J>dV);d{FMgX!BSqQLpxx9Q)L1 zQyOKnsbkd*x~MNxyXBeqj712~GQ~>AzG}Oa6Nho7{+3KN#`pb1avpO16rEL?rq$n| z#fj+?A2;ati&DF!xRtE)a{&@Ey z(MNdUn;*bVuf=Lps%m)Dtl4ZoyPg4U$(ZVv1@93j&%?ZHf9NR*tpET3 literal 0 HcmV?d00001 diff --git a/resources.qrc b/resources.qrc index 88605377d..927404b56 100644 --- a/resources.qrc +++ b/resources.qrc @@ -67,5 +67,8 @@ ./data/icons/tomahawk-icon-128.png ./data/icons/tomahawk-icon-256.png ./data/icons/tomahawk-icon-512.png +./data/icons/audio-x-generic-22.png +./data/icons/audio-x-generic-32.png +./data/icons/audio-x-generic-16.png diff --git a/src/playlist/collectionview.cpp b/src/playlist/collectionview.cpp index 4b23374ef..e983e6e6e 100644 --- a/src/playlist/collectionview.cpp +++ b/src/playlist/collectionview.cpp @@ -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; +} + diff --git a/src/playlist/collectionview.h b/src/playlist/collectionview.h index e59edd3f6..9beb39af0 100644 --- a/src/playlist/collectionview.h +++ b/src/playlist/collectionview.h @@ -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; diff --git a/src/playlist/trackmodel.cpp b/src/playlist/trackmodel.cpp index 88206115c..b1eb51e65 100644 --- a/src/playlist/trackmodel.cpp +++ b/src/playlist/trackmodel.cpp @@ -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;