mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-21 00:12:06 +02:00
* PlayableCovers are now dragable.
This commit is contained in:
parent
12709a47ea
commit
51c0366190
@ -28,6 +28,7 @@
|
||||
#include "utils/TomahawkUtilsGui.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
|
||||
using namespace Tomahawk;
|
||||
@ -85,6 +86,14 @@ PlayableCover::resizeEvent( QResizeEvent* event )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableCover::mousePressEvent( QMouseEvent* event )
|
||||
{
|
||||
if ( event->button() == Qt::LeftButton )
|
||||
m_dragStartPosition = event->pos();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableCover::mouseMoveEvent( QMouseEvent* event )
|
||||
{
|
||||
@ -110,6 +119,45 @@ PlayableCover::mouseMoveEvent( QMouseEvent* event )
|
||||
m_hoveredRect = QRect();
|
||||
repaint();
|
||||
}
|
||||
|
||||
if ( !( event->buttons() & Qt::LeftButton ) )
|
||||
return;
|
||||
if ( ( event->pos() - m_dragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
|
||||
return;
|
||||
|
||||
QByteArray resultData;
|
||||
QDataStream resultStream( &resultData, QIODevice::WriteOnly );
|
||||
QMimeData* mimeData = new QMimeData();
|
||||
QPixmap pixmap;
|
||||
const int pixHeight = TomahawkUtils::defaultFontHeight() * 3;
|
||||
const QSize pixSize = QSize( pixHeight, pixHeight );
|
||||
|
||||
if ( m_artist )
|
||||
{
|
||||
pixmap = m_artist->cover( pixSize, false );
|
||||
resultStream << m_artist->name();
|
||||
mimeData->setData( "application/tomahawk.metadata.artist", resultData );
|
||||
}
|
||||
else if ( m_album )
|
||||
{
|
||||
pixmap = m_album->cover( pixSize, false );
|
||||
resultStream << m_album->artist()->name();
|
||||
resultStream << m_album->name();
|
||||
mimeData->setData( "application/tomahawk.metadata.album", resultData );
|
||||
}
|
||||
else if ( m_query )
|
||||
{
|
||||
pixmap = m_query->track()->cover( pixSize, false );
|
||||
resultStream << QString( "application/tomahawk.query.list" ) << qlonglong( &m_query );
|
||||
mimeData->setData( "application/tomahawk.mixed", resultData );
|
||||
}
|
||||
|
||||
QDrag* drag = new QDrag( this );
|
||||
drag->setMimeData( mimeData );
|
||||
drag->setPixmap( pixmap );
|
||||
drag->setHotSpot( QPoint( -20, -20 ) );
|
||||
|
||||
Qt::DropAction action = drag->exec( Qt::CopyAction, Qt::CopyAction );
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define PLAYABLEPIXMAP_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPoint>
|
||||
#include <QPaintEvent>
|
||||
#include <QResizeEvent>
|
||||
|
||||
@ -61,6 +62,7 @@ protected:
|
||||
virtual void resizeEvent( QResizeEvent* event );
|
||||
virtual void paintEvent( QPaintEvent* event );
|
||||
|
||||
virtual void mousePressEvent( QMouseEvent* event );
|
||||
virtual void mouseMoveEvent( QMouseEvent* event );
|
||||
virtual void mouseReleaseEvent( QMouseEvent* event );
|
||||
|
||||
@ -82,6 +84,8 @@ private:
|
||||
Tomahawk::album_ptr m_album;
|
||||
Tomahawk::query_ptr m_query;
|
||||
|
||||
QPoint m_dragStartPosition;
|
||||
|
||||
QList< QRect > m_itemRects;
|
||||
QRect m_hoveredRect;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user