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 60c89025 authored by Michael Pyne's avatar Michael Pyne

Add drag-and-drop support to the cover image on the new Now Playing bar. You...

Add drag-and-drop support to the cover image on the new Now Playing bar.  You can drag images (or links to images) to set the cover.

Note that this only works when the cover has already been shown.  Maybe it would be a good idea to extend this to the whole now playing bar?

svn path=/trunk/kdemultimedia/juk/; revision=361905
parent eaa9187d
......@@ -16,9 +16,14 @@
#include <kiconloader.h>
#include <klocale.h>
#include <kdebug.h>
#include <kurldrag.h>
#include <kio/netaccess.h>
#include <qimage.h>
#include <qlayout.h>
#include <qevent.h>
#include <qdragobject.h>
#include <qimage.h>
#include "nowplaying.h"
#include "playermanager.h"
......@@ -107,6 +112,7 @@ CoverItem::CoverItem(NowPlaying *parent) :
setFrameStyle(Box | Plain);
setLineWidth(1);
setMargin(1);
setAcceptDrops(true);
}
void CoverItem::update(const FileHandle &file)
......@@ -151,6 +157,38 @@ bool CoverItem::eventFilter(QObject *object, QEvent *event)
return QLabel::eventFilter(object, event);
}
void CoverItem::dragEnterEvent(QDragEnterEvent *e)
{
e->accept(QImageDrag::canDecode(e) || KURLDrag::canDecode(e));
}
void CoverItem::dropEvent(QDropEvent *e)
{
QImage image;
KURL::List urls;
if(QImageDrag::decode(e, image)) {
m_file.coverInfo()->setCover(image);
update(m_file);
}
else if(KURLDrag::decode(e, urls)) {
QString fileName;
if(KIO::NetAccess::download(urls.front(), fileName, this)) {
if(image.load(fileName)) {
m_file.coverInfo()->setCover(image);
update(m_file);
}
else
kdError(65432) << "Unable to load image from " << urls.front() << endl;
KIO::NetAccess::removeTempFile(fileName);
}
else
kdError(65432) << "Unable to download " << urls.front() << endl;
}
}
////////////////////////////////////////////////////////////////////////////////
// TrackItem
////////////////////////////////////////////////////////////////////////////////
......@@ -240,3 +278,5 @@ void HistoryItem::update(const FileHandle &file)
}
#include "nowplaying.moc"
// vim: set et sw=4 ts=8:
......@@ -71,6 +71,10 @@ public:
virtual void mousePressEvent(QMouseEvent *event);
virtual bool eventFilter(QObject *object, QEvent *event);
protected:
virtual void dragEnterEvent(QDragEnterEvent *e);
virtual void dropEvent(QDropEvent *e);
private:
FileHandle m_file;
QWidget *m_popup;
......
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