Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cover Art Label & Cover Art Full Size composition with menu #4864

Merged
merged 3 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/library/dlgcoverartfullsize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
#include "track/track.h"
#include "util/widgethelper.h"

DlgCoverArtFullSize::DlgCoverArtFullSize(QWidget* parent, BaseTrackPlayer* pPlayer)
DlgCoverArtFullSize::DlgCoverArtFullSize(
QWidget* parent,
BaseTrackPlayer* pPlayer,
WCoverArtMenu* pCoverMenu)
: QDialog(parent),
m_pPlayer(pPlayer),
m_pCoverMenu(make_parented<WCoverArtMenu>(this)) {
m_pCoverMenu(pCoverMenu) {
CoverArtCache* pCache = CoverArtCache::instance();
if (pCache) {
connect(pCache,
Expand All @@ -28,14 +31,16 @@ DlgCoverArtFullSize::DlgCoverArtFullSize(QWidget* parent, BaseTrackPlayer* pPlay
&DlgCoverArtFullSize::customContextMenuRequested,
this,
&DlgCoverArtFullSize::slotCoverMenu);
connect(m_pCoverMenu,
&WCoverArtMenu::coverInfoSelected,
this,
&DlgCoverArtFullSize::slotCoverInfoSelected);
connect(m_pCoverMenu,
&WCoverArtMenu::reloadCoverArt,
this,
&DlgCoverArtFullSize::slotReloadCoverArt);
if (m_pCoverMenu != nullptr) {
connect(m_pCoverMenu,
&WCoverArtMenu::coverInfoSelected,
this,
&DlgCoverArtFullSize::slotCoverInfoSelected);
connect(m_pCoverMenu,
&WCoverArtMenu::reloadCoverArt,
this,
&DlgCoverArtFullSize::slotReloadCoverArt);
}

if (m_pPlayer != nullptr) {
connect(pPlayer,
Expand Down Expand Up @@ -219,7 +224,10 @@ void DlgCoverArtFullSize::slotCoverInfoSelected(
}

void DlgCoverArtFullSize::mousePressEvent(QMouseEvent* event) {
if (!m_pCoverMenu->isVisible() && event->button() == Qt::LeftButton) {
if (event->button() != Qt::LeftButton) {
return;
}
if ((m_pCoverMenu != nullptr && !m_pCoverMenu->isVisible()) || m_pCoverMenu == nullptr) {
m_clickTimer.setSingleShot(true);
m_clickTimer.start(500);
m_coverPressed = true;
Expand All @@ -234,7 +242,7 @@ void DlgCoverArtFullSize::mousePressEvent(QMouseEvent* event) {

void DlgCoverArtFullSize::mouseReleaseEvent(QMouseEvent* event) {
m_coverPressed = false;
if (m_pCoverMenu->isVisible()) {
if (m_pCoverMenu != nullptr && m_pCoverMenu->isVisible()) {
return;
}

Expand Down Expand Up @@ -265,7 +273,9 @@ void DlgCoverArtFullSize::mouseMoveEvent(QMouseEvent* event) {
}

void DlgCoverArtFullSize::slotCoverMenu(const QPoint& pos) {
m_pCoverMenu->popup(mapToGlobal(pos));
if (m_pCoverMenu != nullptr) {
m_pCoverMenu->popup(mapToGlobal(pos));
}
}

void DlgCoverArtFullSize::resizeEvent(QResizeEvent* event) {
Expand Down
6 changes: 4 additions & 2 deletions src/library/dlgcoverartfullsize.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class DlgCoverArtFullSize
public Ui::DlgCoverArtFullSize {
Q_OBJECT
public:
explicit DlgCoverArtFullSize(QWidget* parent, BaseTrackPlayer* pPlayer = nullptr);
explicit DlgCoverArtFullSize(QWidget* parent,
BaseTrackPlayer* pPlayer = nullptr,
WCoverArtMenu* pCoverMenu = nullptr);
~DlgCoverArtFullSize() override = default;

void init(TrackPointer pTrack);
Expand Down Expand Up @@ -46,7 +48,7 @@ class DlgCoverArtFullSize
QPixmap m_pixmap;
TrackPointer m_pLoadedTrack;
BaseTrackPlayer* m_pPlayer;
parented_ptr<WCoverArtMenu> m_pCoverMenu;
WCoverArtMenu* m_pCoverMenu;
QTimer m_clickTimer;
QPoint m_dragStartPosition;
bool m_coverPressed;
Expand Down
14 changes: 9 additions & 5 deletions src/library/dlgtrackinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "util/desktophelper.h"
#include "util/duration.h"
#include "widget/wcoverartlabel.h"
#include "widget/wcoverartmenu.h"
#include "widget/wstarrating.h"

namespace {
Expand All @@ -42,7 +43,8 @@ DlgTrackInfo::DlgTrackInfo(
: QDialog(nullptr),
m_pTrackModel(trackModel),
m_tapFilter(this, kFilterLength, kMaxInterval),
m_pWCoverArtLabel(make_parented<WCoverArtLabel>(this)),
m_pWCoverArtMenu(make_parented<WCoverArtMenu>(this)),
m_pWCoverArtLabel(make_parented<WCoverArtLabel>(this, m_pWCoverArtMenu)),
m_pWStarRating(make_parented<WStarRating>(nullptr, this)) {
init();
}
Expand Down Expand Up @@ -230,12 +232,14 @@ void DlgTrackInfo::init() {
this,
&DlgTrackInfo::slotCoverFound);
}
connect(m_pWCoverArtLabel.get(),
&WCoverArtLabel::coverInfoSelected,

connect(m_pWCoverArtMenu,
&WCoverArtMenu::coverInfoSelected,
this,
&DlgTrackInfo::slotCoverInfoSelected);
connect(m_pWCoverArtLabel.get(),
&WCoverArtLabel::reloadCoverArt,

connect(m_pWCoverArtMenu,
&WCoverArtMenu::reloadCoverArt,
this,
&DlgTrackInfo::slotReloadCoverArt);
}
Expand Down
2 changes: 2 additions & 0 deletions src/library/dlgtrackinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class TrackModel;
class DlgTagFetcher;
class WCoverArtLabel;
class WCoverArtMenu;
class WStarRating;

/// A dialog box to display and edit track properties.
Expand Down Expand Up @@ -114,6 +115,7 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {
TapFilter m_tapFilter;
mixxx::Bpm m_lastTapedBpm;

parented_ptr<WCoverArtMenu> m_pWCoverArtMenu;
parented_ptr<WCoverArtLabel> m_pWCoverArtLabel;
parented_ptr<WStarRating> m_pWStarRating;

Expand Down
8 changes: 4 additions & 4 deletions src/widget/wcoverart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
#include "widget/wskincolor.h"

WCoverArt::WCoverArt(QWidget* parent,
UserSettingsPointer pConfig,
const QString& group,
BaseTrackPlayer* pPlayer)
fatihemreyildiz marked this conversation as resolved.
Show resolved Hide resolved
UserSettingsPointer pConfig,
const QString& group,
BaseTrackPlayer* pPlayer)
: QWidget(parent),
WBaseWidget(this),
m_group(group),
m_pConfig(pConfig),
m_bEnable(true),
m_pMenu(new WCoverArtMenu(this)),
m_pPlayer(pPlayer),
m_pDlgFullSize(new DlgCoverArtFullSize(this, pPlayer)) {
m_pDlgFullSize(new DlgCoverArtFullSize(this, pPlayer, m_pMenu)) {
// Accept drops if we have a group to load tracks into.
setAcceptDrops(!m_group.isEmpty());

Expand Down
27 changes: 14 additions & 13 deletions src/widget/wcoverartlabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,51 +30,52 @@ QPixmap createDefaultCover(QWidget* parent) {

} // anonymous namespace

WCoverArtLabel::WCoverArtLabel(QWidget* parent)
WCoverArtLabel::WCoverArtLabel(QWidget* parent, WCoverArtMenu* pCoverMenu)
: QLabel(parent),
m_pCoverMenu(make_parented<WCoverArtMenu>(this)),
m_pDlgFullSize(make_parented<DlgCoverArtFullSize>(this)),
m_pCoverMenu(pCoverMenu),
m_pDlgFullSize(make_parented<DlgCoverArtFullSize>(this, nullptr, pCoverMenu)),
m_defaultCover(createDefaultCover(this)) {
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setFrameShape(QFrame::Box);
setAlignment(Qt::AlignCenter);
connect(m_pCoverMenu,
&WCoverArtMenu::coverInfoSelected,
this,
&WCoverArtLabel::coverInfoSelected);
connect(m_pCoverMenu, &WCoverArtMenu::reloadCoverArt, this, &WCoverArtLabel::reloadCoverArt);

setPixmap(m_defaultCover);
}

WCoverArtLabel::~WCoverArtLabel() = default;

void WCoverArtLabel::setCoverArt(const CoverInfo& coverInfo,
const QPixmap& px) {
m_pCoverMenu->setCoverArt(coverInfo);
if (m_pCoverMenu != nullptr) {
m_pCoverMenu->setCoverArt(coverInfo);
}
if (px.isNull()) {
m_loadedCover = px;
setPixmap(m_defaultCover);
} else {
m_loadedCover = scaleCoverLabel(this, px);
setPixmap(m_loadedCover);
}

#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
QSize frameSize = pixmap(Qt::ReturnByValue).size() / devicePixelRatioF();
#else
QSize frameSize = pixmap()->size() / devicePixelRatioF();
#endif
frameSize += QSize(2,2); // margin
frameSize += QSize(2, 2); // margin
setMinimumSize(frameSize);
setMaximumSize(frameSize);
}

void WCoverArtLabel::slotCoverMenu(const QPoint& pos) {
if (m_pCoverMenu == nullptr) {
return;
}
m_pCoverMenu->popup(mapToGlobal(pos));
}

void WCoverArtLabel::contextMenuEvent(QContextMenuEvent* event) {
if (m_pCoverMenu == nullptr) {
return;
}
event->accept();
m_pCoverMenu->popup(event->globalPos());
}
Expand All @@ -84,7 +85,7 @@ void WCoverArtLabel::loadTrack(TrackPointer pTrack) {
}

void WCoverArtLabel::mousePressEvent(QMouseEvent* event) {
if (m_pCoverMenu->isVisible()) {
if (m_pCoverMenu != nullptr && m_pCoverMenu->isVisible()) {
return;
}

Expand Down
10 changes: 4 additions & 6 deletions src/widget/wcoverartlabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ class CoverInfoRelative;
class WCoverArtLabel : public QLabel {
Q_OBJECT
public:
explicit WCoverArtLabel(QWidget* parent = nullptr);
explicit WCoverArtLabel(QWidget* parent = nullptr, WCoverArtMenu* m_pWCoverArtMenu = nullptr);

~WCoverArtLabel() override; // Verifies that the base destructor is virtual

void setCoverArt(const CoverInfo& coverInfo, const QPixmap& px);
void loadTrack(TrackPointer pTrack);

signals:
void coverInfoSelected(const CoverInfoRelative& coverInfo);
void reloadCoverArt();

protected:
void mousePressEvent(QMouseEvent* event) override;
void contextMenuEvent(QContextMenuEvent* event) override;
Expand All @@ -34,7 +31,8 @@ class WCoverArtLabel : public QLabel {
void slotCoverMenu(const QPoint& pos);

private:
const parented_ptr<WCoverArtMenu> m_pCoverMenu;
WCoverArtMenu* m_pCoverMenu;

const parented_ptr<DlgCoverArtFullSize> m_pDlgFullSize;

const QPixmap m_defaultCover;
Expand Down
4 changes: 2 additions & 2 deletions src/widget/wspinny.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ WSpinny::WSpinny(
m_bClampFailedWarning(false),
m_bGhostPlayback(false),
m_pPlayer(pPlayer),
m_pDlgCoverArt(new DlgCoverArtFullSize(parent, pPlayer)),
m_pCoverMenu(new WCoverArtMenu(this)) {
m_pCoverMenu(new WCoverArtMenu(this)),
m_pDlgCoverArt(new DlgCoverArtFullSize(parent, pPlayer, m_pCoverMenu)) {
#ifdef __VINYLCONTROL__
m_pVCManager = pVCMan;
#else
Expand Down
2 changes: 1 addition & 1 deletion src/widget/wspinny.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ class WSpinny : public QGLWidget, public WBaseWidget, public VinylSignalQualityL
bool m_bGhostPlayback;

BaseTrackPlayer* m_pPlayer;
DlgCoverArtFullSize* m_pDlgCoverArt;
WCoverArtMenu* m_pCoverMenu;
DlgCoverArtFullSize* m_pDlgCoverArt;
};