mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 16:44:05 +02:00
* PlayableCovers are now dragable.
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#include "utils/TomahawkUtilsGui.h"
|
#include "utils/TomahawkUtilsGui.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
using namespace Tomahawk;
|
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
|
void
|
||||||
PlayableCover::mouseMoveEvent( QMouseEvent* event )
|
PlayableCover::mouseMoveEvent( QMouseEvent* event )
|
||||||
{
|
{
|
||||||
@@ -110,6 +119,45 @@ PlayableCover::mouseMoveEvent( QMouseEvent* event )
|
|||||||
m_hoveredRect = QRect();
|
m_hoveredRect = QRect();
|
||||||
repaint();
|
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
|
#define PLAYABLEPIXMAP_H
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QPoint>
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
|
|
||||||
@@ -61,6 +62,7 @@ protected:
|
|||||||
virtual void resizeEvent( QResizeEvent* event );
|
virtual void resizeEvent( QResizeEvent* event );
|
||||||
virtual void paintEvent( QPaintEvent* event );
|
virtual void paintEvent( QPaintEvent* event );
|
||||||
|
|
||||||
|
virtual void mousePressEvent( QMouseEvent* event );
|
||||||
virtual void mouseMoveEvent( QMouseEvent* event );
|
virtual void mouseMoveEvent( QMouseEvent* event );
|
||||||
virtual void mouseReleaseEvent( QMouseEvent* event );
|
virtual void mouseReleaseEvent( QMouseEvent* event );
|
||||||
|
|
||||||
@@ -82,6 +84,8 @@ private:
|
|||||||
Tomahawk::album_ptr m_album;
|
Tomahawk::album_ptr m_album;
|
||||||
Tomahawk::query_ptr m_query;
|
Tomahawk::query_ptr m_query;
|
||||||
|
|
||||||
|
QPoint m_dragStartPosition;
|
||||||
|
|
||||||
QList< QRect > m_itemRects;
|
QList< QRect > m_itemRects;
|
||||||
QRect m_hoveredRect;
|
QRect m_hoveredRect;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user