diff --git a/src/libtomahawk/playlist/playlistview.cpp b/src/libtomahawk/playlist/playlistview.cpp index 9829f21c2..f389ed423 100644 --- a/src/libtomahawk/playlist/playlistview.cpp +++ b/src/libtomahawk/playlist/playlistview.cpp @@ -80,6 +80,110 @@ PlaylistView::setPlaylistModel( PlaylistModel* model ) } +/** Drop **/ + + +void +PlaylistView::dragEnterEvent( QDragEnterEvent* event ) +{ + qDebug() << Q_FUNC_INFO; + QTreeView::dragEnterEvent( event ); + + if ( DropJob::acceptsMimeData( event->mimeData() ) ) + { + m_dragging = true; + m_dropRect = QRect(); + + qDebug() << Q_FUNC_INFO << "Accepting Drag Event"; + event->acceptProposedAction(); + } +} + + +void +PlaylistView::dragMoveEvent( QDragMoveEvent* event ) +{ + QTreeView::dragMoveEvent( event ); + + if ( model()->isReadOnly() ) + { + qDebug() << Q_FUNC_INFO << "Ignoring DragMove Event"; + event->ignore(); + return; + } + + if ( DropJob::acceptsMimeData( event->mimeData() ) ) + { + qDebug() << Q_FUNC_INFO << "Accepting DragMove Event"; + } + + setDirtyRegion( m_dropRect ); +} + + +void +PlaylistView::dropEvent( QDropEvent* event ) +{ + QTreeView::dropEvent( event ); + + if ( event->isAccepted() ) + { + qDebug() << Q_FUNC_INFO << "Ignoring accepted event!"; + } + else + { + if ( DropJob::acceptsMimeData( event->mimeData()) ) + { + const QPoint pos = event->pos(); + const QModelIndex index = indexAt( pos ); + + qDebug() << Q_FUNC_INFO << "Drop Event accepted at row:" << index.row(); + event->acceptProposedAction(); + + if ( !model()->isReadOnly() ) + { + model()->dropMimeData( event->mimeData(), event->proposedAction(), index.row(), 0, index.parent() ); + } + } + } + + m_dragging = false; +} + + +void +PlaylistView::paintEvent( QPaintEvent* event ) +{ + QTreeView::paintEvent( event ); + QPainter painter( viewport() ); + + if ( m_dragging ) + { + // draw drop indicator + { + // draw indicator for inserting items + QBrush blendedBrush = viewOptions().palette.brush( QPalette::Normal, QPalette::Highlight ); + QColor color = blendedBrush.color(); + + const int y = ( m_dropRect.top() + m_dropRect.bottom() ) / 2; + const int thickness = m_dropRect.height() / 2; + + int alpha = 255; + const int alphaDec = alpha / ( thickness + 1 ); + for ( int i = 0; i < thickness; i++ ) + { + color.setAlpha( alpha ); + alpha -= alphaDec; + painter.setPen( color ); + painter.drawLine( 0, y - i, width(), y - i ); + painter.drawLine( 0, y + i, width(), y + i ); + } + } + } +} + + +/** Drop **/ void PlaylistView::keyPressEvent( QKeyEvent* event ) { diff --git a/src/libtomahawk/playlist/playlistview.h b/src/libtomahawk/playlist/playlistview.h index 1879910d7..26fe829c0 100644 --- a/src/libtomahawk/playlist/playlistview.h +++ b/src/libtomahawk/playlist/playlistview.h @@ -23,7 +23,7 @@ #include "playlist/playlistmodel.h" #include "trackview.h" #include "viewpage.h" - +#include "dropjob.h" #include "dllmacro.h" class DLLEXPORT PlaylistView : public TrackView, public Tomahawk::ViewPage @@ -46,20 +46,24 @@ public: virtual QString title() const { return playlistModel()->title(); } virtual QString description() const { return m_model->description(); } virtual QPixmap pixmap() const { return QPixmap( RESPATH "images/playlist-icon.png" ); } - virtual bool jumpToCurrentTrack(); virtual bool isTemporaryPage() const; + signals: void nameChanged( const QString& title ); void destroyed( QWidget* widget ); protected: void keyPressEvent( QKeyEvent* event ); + virtual void dragEnterEvent( QDragEnterEvent* event ); + virtual void dragLeaveEvent( QDragLeaveEvent* /*event*/ ) { m_dragging = false; setDirtyRegion( m_dropRect ); } + virtual void dragMoveEvent( QDragMoveEvent* event ); + virtual void dropEvent( QDropEvent* event ); + void paintEvent( QPaintEvent* event ); private slots: void onTrackCountChanged( unsigned int tracks ); - void onMenuTriggered( int action ); void deleteItems(); @@ -68,9 +72,12 @@ private slots: private: PlaylistModel* m_model; - + bool m_resizing; + bool m_dragging; + QRect m_dropRect; QString m_customTitle; QString m_customDescripton; + }; #endif // PLAYLISTVIEW_H