1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#include "widget/wcoverartlabel.h"
#include <QtDebug>
#include "library/dlgcoverartfullsize.h"
#include "library/coverartutils.h"
static const QSize s_labelDisplaySize = QSize(100, 100);
WCoverArtLabel::WCoverArtLabel(QWidget* parent)
: QLabel(parent),
m_pCoverMenu(new WCoverArtMenu(this)),
m_pDlgFullSize(new DlgCoverArtFullSize(this, nullptr)),
m_defaultCover(CoverArtUtils::defaultCoverLocation()) {
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setFrameShape(QFrame::Box);
setAlignment(Qt::AlignCenter);
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(slotCoverMenu(QPoint)));
connect(m_pCoverMenu, SIGNAL(coverInfoSelected(const CoverInfo&)),
this, SIGNAL(coverInfoSelected(const CoverInfo&)));
connect(m_pCoverMenu, SIGNAL(reloadCoverArt()),
this, SIGNAL(reloadCoverArt()));
m_defaultCover = m_defaultCover.scaled(s_labelDisplaySize,
Qt::KeepAspectRatio,
Qt::SmoothTransformation);
setPixmap(m_defaultCover);
}
WCoverArtLabel::~WCoverArtLabel() {
delete m_pCoverMenu;
delete m_pDlgFullSize;
}
void WCoverArtLabel::setCoverArt(const CoverInfo& coverInfo,
QPixmap px) {
qDebug() << "WCoverArtLabel::setCoverArt" << coverInfo << px.size();
m_loadedCover = px;
m_pCoverMenu->setCoverArt(coverInfo);
if (px.isNull()) {
setPixmap(m_defaultCover);
} else {
setPixmap(px.scaled(s_labelDisplaySize, Qt::KeepAspectRatio,
Qt::SmoothTransformation));
}
QSize frameSize = pixmap()->size();
frameSize += QSize(2,2); // margin
setMinimumSize(frameSize);
setMaximumSize(frameSize);
}
void WCoverArtLabel::slotCoverMenu(const QPoint& pos) {
m_pCoverMenu->popup(mapToGlobal(pos));
}
void WCoverArtLabel::loadTrack(TrackPointer pTrack) {
m_pLoadedTrack = pTrack;
}
void WCoverArtLabel::mousePressEvent(QMouseEvent* event) {
if (m_pCoverMenu->isVisible()) {
return;
}
if (event->button() == Qt::LeftButton) {
if (m_pDlgFullSize->isVisible()) {
m_pDlgFullSize->close();
} else {
m_pDlgFullSize->init(m_pLoadedTrack);
}
}
}
|