Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 6714bd3a authored by Michael Pyne's avatar Michael Pyne

* Now you can drag covers to and from the little cover area on the "Now

  Playing" bar.
* When dragging a cover from the CoverManager or the Now Playing bar an image
  of the cover is attached to the cursor (it looks like you're literally
  dragging the cover. :)

svn path=/trunk/KDE/kdemultimedia/juk/; revision=433515
parent 75ef8af9
......@@ -37,6 +37,8 @@ public:
// Use this to assign to a specific cover id.
void setCoverId(coverKey id);
coverKey coverId() const { return m_coverKey; }
QPixmap pixmap(CoverSize size) const;
void popup() const;
......
......@@ -243,6 +243,9 @@ coverKey CoverManagerPrivate::nextId() const
CoverDrag::CoverDrag(coverKey id, QWidget *src) : QDragObject(src, "coverDrag"),
m_id(id)
{
QPixmap cover = CoverManager::coverFromId(id);
if(!cover.isNull())
setPixmap(cover);
}
const char *CoverDrag::format(int i) const
......
......@@ -25,11 +25,13 @@
#include <qdragobject.h>
#include <qimage.h>
#include <qtimer.h>
#include <qpoint.h>
#include "nowplaying.h"
#include "playlistcollection.h"
#include "playermanager.h"
#include "coverinfo.h"
#include "covermanager.h"
#include "tag.h"
#include "playlistitem.h"
#include "collectionlist.h"
......@@ -124,6 +126,11 @@ void CoverItem::update(const FileHandle &file)
void CoverItem::mouseReleaseEvent(QMouseEvent *event)
{
if(m_dragging) {
m_dragging = false;
return;
}
if(event->x() >= 0 && event->y() >= 0 &&
event->x() < width() && event->y() < height() &&
event->button() == LeftButton &&
......@@ -135,20 +142,51 @@ void CoverItem::mouseReleaseEvent(QMouseEvent *event)
QLabel::mousePressEvent(event);
}
void CoverItem::mousePressEvent(QMouseEvent *e)
{
m_dragging = false;
m_dragStart = e->globalPos();
}
void CoverItem::mouseMoveEvent(QMouseEvent *e)
{
if(m_dragging)
return;
QPoint diff = m_dragStart - e->globalPos();
if(QABS(diff.x()) > 1 || QABS(diff.y()) > 1) {
// Start a drag.
m_dragging = true;
CoverDrag *drag = new CoverDrag(m_file.coverInfo()->coverId(), this);
drag->drag();
}
}
void CoverItem::dragEnterEvent(QDragEnterEvent *e)
{
e->accept(QImageDrag::canDecode(e) || KURLDrag::canDecode(e));
e->accept(QImageDrag::canDecode(e) || KURLDrag::canDecode(e) || CoverDrag::canDecode(e));
}
void CoverItem::dropEvent(QDropEvent *e)
{
QImage image;
KURL::List urls;
coverKey key;
if(e->source() == this)
return;
if(QImageDrag::decode(e, image)) {
m_file.coverInfo()->setCover(image);
update(m_file);
}
else if(CoverDrag::decode(e, key)) {
m_file.coverInfo()->setCoverId(key);
update(m_file);
}
else if(KURLDrag::decode(e, urls)) {
QString fileName;
......
......@@ -26,6 +26,7 @@
#include "playlist.h"
class QTimer;
class QPoint;
class NowPlayingItem;
class PlaylistCollection;
......@@ -97,8 +98,13 @@ protected:
virtual void dragEnterEvent(QDragEnterEvent *e);
virtual void dropEvent(QDropEvent *e);
virtual void mousePressEvent(QMouseEvent *e);
virtual void mouseMoveEvent(QMouseEvent *e);
private:
FileHandle m_file;
bool m_dragging;
QPoint m_dragStart;
};
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment