mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Added drop event to playlistview
This commit is contained in:
@@ -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
|
void
|
||||||
PlaylistView::keyPressEvent( QKeyEvent* event )
|
PlaylistView::keyPressEvent( QKeyEvent* event )
|
||||||
{
|
{
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
#include "playlist/playlistmodel.h"
|
#include "playlist/playlistmodel.h"
|
||||||
#include "trackview.h"
|
#include "trackview.h"
|
||||||
#include "viewpage.h"
|
#include "viewpage.h"
|
||||||
|
#include "dropjob.h"
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
|
|
||||||
class DLLEXPORT PlaylistView : public TrackView, public Tomahawk::ViewPage
|
class DLLEXPORT PlaylistView : public TrackView, public Tomahawk::ViewPage
|
||||||
@@ -46,20 +46,24 @@ public:
|
|||||||
virtual QString title() const { return playlistModel()->title(); }
|
virtual QString title() const { return playlistModel()->title(); }
|
||||||
virtual QString description() const { return m_model->description(); }
|
virtual QString description() const { return m_model->description(); }
|
||||||
virtual QPixmap pixmap() const { return QPixmap( RESPATH "images/playlist-icon.png" ); }
|
virtual QPixmap pixmap() const { return QPixmap( RESPATH "images/playlist-icon.png" ); }
|
||||||
|
|
||||||
virtual bool jumpToCurrentTrack();
|
virtual bool jumpToCurrentTrack();
|
||||||
virtual bool isTemporaryPage() const;
|
virtual bool isTemporaryPage() const;
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void nameChanged( const QString& title );
|
void nameChanged( const QString& title );
|
||||||
void destroyed( QWidget* widget );
|
void destroyed( QWidget* widget );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent( QKeyEvent* event );
|
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:
|
private slots:
|
||||||
void onTrackCountChanged( unsigned int tracks );
|
void onTrackCountChanged( unsigned int tracks );
|
||||||
|
|
||||||
void onMenuTriggered( int action );
|
void onMenuTriggered( int action );
|
||||||
void deleteItems();
|
void deleteItems();
|
||||||
|
|
||||||
@@ -68,9 +72,12 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
PlaylistModel* m_model;
|
PlaylistModel* m_model;
|
||||||
|
bool m_resizing;
|
||||||
|
bool m_dragging;
|
||||||
|
QRect m_dropRect;
|
||||||
QString m_customTitle;
|
QString m_customTitle;
|
||||||
QString m_customDescripton;
|
QString m_customDescripton;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLAYLISTVIEW_H
|
#endif // PLAYLISTVIEW_H
|
||||||
|
Reference in New Issue
Block a user