Commit 23807eca authored by Scott Wheeler's avatar Scott Wheeler

Remove the now uneeded CoverPopup class and simplify things a bit. This

now automatically pops up near to the mouse pointer and does checks to make
sure that everything will fit on the screen.

svn path=/trunk/kdemultimedia/juk/; revision=362359
parent 1d6d2e9f
......@@ -22,10 +22,31 @@
#include <qregexp.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qcursor.h>
#include "coverinfo.h"
#include "tag.h"
struct CoverPopup : public QWidget
{
CoverPopup(const QPixmap &image, const QPoint &p) :
QWidget(0, 0, WDestructiveClose | WX11BypassWM)
{
QHBoxLayout *layout = new QHBoxLayout(this);
QLabel *label = new QLabel(this);
layout->addWidget(label);
label->setFrameStyle(QFrame::Box | QFrame::Raised);
label->setLineWidth(1);
label->setPixmap(image);
setGeometry(p.x(), p.y(), label->width(), label->height());
show();
}
virtual void leaveEvent(QEvent *) { close(); }
virtual void mousePressEvent(QMouseEvent *) { close(); }
};
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
......@@ -34,8 +55,7 @@
CoverInfo::CoverInfo(const FileHandle &file) :
m_file(file),
m_hasCover(false),
m_haveCheckedForCover(false),
m_popup(0)
m_haveCheckedForCover(false)
{
}
......@@ -52,8 +72,8 @@ bool CoverInfo::hasCover()
void CoverInfo::clearCover()
{
QFile::remove(coverLocation(CoverInfo::FullSize));
QFile::remove(coverLocation(CoverInfo::Thumbnail));
QFile::remove(coverLocation(FullSize));
QFile::remove(coverLocation(Thumbnail));
m_hasCover = false;
m_haveCheckedForCover = false;
}
......@@ -68,7 +88,7 @@ void CoverInfo::setCover(const QImage &image)
if(m_hasCover)
clearCover();
image.save(coverLocation(CoverInfo::FullSize), "PNG");
image.save(coverLocation(FullSize), "PNG");
}
QPixmap CoverInfo::pixmap(CoverSize size) const
......@@ -87,6 +107,36 @@ QPixmap CoverInfo::pixmap(CoverSize size) const
return QPixmap(coverLocation(size));
}
void CoverInfo::popup(PopupCorner corner)
{
QPoint p = QCursor::pos();
QPixmap image = pixmap(FullSize);
if(corner == BottomRightCorner) {
p.setX(p.x() - image.width());
p.setY(p.y() - image.height());
if(p.x() < 0)
p.setX(0);
if(p.y() < 0)
p.setY(0);
}
else {
QRect r = KApplication::desktop()->screenGeometry(kapp->mainWidget());
if(p.x() + image.width() > r.right())
p.setX(r.right() - image.width());
if(p.y() + image.height() > r.bottom())
p.setX(r.bottom() - image.height());
}
int offset = corner == TopLeftCorner ? -10 : 10;
p.setX(p.x() + offset);
p.setY(p.y() + offset);
new CoverPopup(image, p);
}
QString CoverInfo::coverLocation(CoverSize size) const
{
QString fileName(QFile::encodeName(m_file.tag()->artist() + " - " + m_file.tag()->album()));
......@@ -110,56 +160,4 @@ QString CoverInfo::coverLocation(CoverSize size) const
return fileLocation;
}
void CoverInfo::popupCover(int x, int y)
{
QPixmap largeCover = pixmap(FullSize);
if(largeCover.isNull())
return;
if(!m_popup)
m_popup = new CoverPopup(largeCover);
m_popup->popup(x, y);
}
struct CoverPopupWidget : public QWidget
{
CoverPopupWidget(const QPixmap &image, int x, int y) : QWidget(0, 0, WX11BypassWM)
{
QHBoxLayout *layout = new QHBoxLayout(this);
QLabel *label = new QLabel(this);
layout->addWidget(label);
label->setFrameStyle(QFrame::Box | QFrame::Raised);
label->setLineWidth(1);
label->setPixmap(image);
setGeometry(x - 10, y - 10, label->width(), label->height());
show();
}
};
void CoverPopup::popup(int x, int y)
{
if(m_popupWidget)
delete m_popupWidget;
m_popupWidget = new CoverPopupWidget(m_pixmap, x, y);
m_popupWidget->installEventFilter(this);
}
bool CoverPopup::eventFilter(QObject *object, QEvent *event)
{
if(object == m_popupWidget && (event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::Leave))
{
delete m_popupWidget;
m_popupWidget = 0;
return true;
}
return QLabel::eventFilter(object, event);
}
// vim: set et sw=4 ts=8:
......@@ -21,25 +21,13 @@
#include "filehandle.h"
class CoverPopup : public QLabel
{
public:
CoverPopup(QPixmap &pixmap):QLabel(0),m_popupWidget(0),m_pixmap(pixmap){}
virtual bool eventFilter(QObject *object, QEvent *event);
void popup(int x, int y);
private:
QWidget *m_popupWidget;
QPixmap m_pixmap;
};
class CoverInfo
{
friend class FileHandle;
public:
enum CoverSize { FullSize, Thumbnail };
enum PopupCorner { TopLeftCorner, BottomRightCorner };
CoverInfo(const FileHandle &file);
......@@ -49,7 +37,7 @@ public:
void setCover(const QImage &image = QImage());
QPixmap pixmap(CoverSize size) const;
void popupCover(int x = 10, int y = 10);
void popup(PopupCorner corner = TopLeftCorner);
private:
QString coverLocation(CoverSize size) const;
......@@ -57,7 +45,6 @@ private:
FileHandle m_file;
bool m_hasCover;
bool m_haveCheckedForCover;
CoverPopup *m_popup;
};
#endif
......@@ -115,7 +115,7 @@ void CoverItem::mousePressEvent(QMouseEvent *event)
if(event->button() == LeftButton &&
m_file.coverInfo()->hasCover())
{
m_file.coverInfo()->popupCover(event->globalX(), event->globalY());
m_file.coverInfo()->popup();
}
QLabel::mousePressEvent(event);
......
......@@ -731,7 +731,7 @@ void Playlist::slotViewCover()
if (items.isEmpty())
return;
for(PlaylistItemList::Iterator it = items.begin(); it != items.end(); ++it)
(*it)->file().coverInfo()->popupCover();
(*it)->file().coverInfo()->popup();
}
void Playlist::slotRemoveCover()
......
......@@ -193,7 +193,7 @@ void SystemTray::slotPopupLargeCover()
return;
FileHandle playingFile = PlayerManager::instance()->playingFile();
playingFile.coverInfo()->popupCover();
playingFile.coverInfo()->popup(CoverInfo::BottomRightCorner);
}
void SystemTray::slotStop()
......
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