diff --git a/src/library/dlgtrackinfo.cpp b/src/library/dlgtrackinfo.cpp index f60aa5e39848..1ead487a76c6 100644 --- a/src/library/dlgtrackinfo.cpp +++ b/src/library/dlgtrackinfo.cpp @@ -48,7 +48,13 @@ DlgTrackInfo::DlgTrackInfo( m_tapFilter(this, kFilterLength, kMaxInterval), m_pWCoverArtMenu(make_parented(this)), m_pWCoverArtLabel(make_parented(this, m_pWCoverArtMenu)), - m_pWStarRating(make_parented(nullptr, this)) { + m_pWStarRating(make_parented(nullptr, this)), + m_pColorPicker(make_parented( + WColorPicker::Option::AllowNoColor | + // TODO(xxx) remove this once the preferences are themed via QSS + WColorPicker::Option::NoExtStyleSheet, + ColorPaletteSettings(m_pUserSettings).getTrackColorPalette(), + this)) { init(); } @@ -245,6 +251,33 @@ void DlgTrackInfo::init() { &WCoverArtMenu::reloadCoverArt, this, &DlgTrackInfo::slotReloadCoverArt); + + btnColorPicker->hide(); + btnColorPickerNoColor->hide(); + + // These are the track color picker buttons: + // colored button with 'fusion' style to allow setting a custom background color + // with a simple stylesheet (no border hacks required, see WColorPickerAction) + btnColorPicker->setStyle(QStyleFactory::create(QStringLiteral("fusion"))); + QMenu* pColorPickerMenu = new QMenu(this); + pColorPickerMenu->addAction(m_pColorPicker); + btnColorPicker->setMenu(pColorPickerMenu); + // 'no color' button (default style theme), looks like the other pushbuttons + btnColorPickerNoColor->setMenu(pColorPickerMenu); + btnColorPickerNoColor->setText(tr("(no color)")); + + connect(btnColorPicker, + &QPushButton::clicked, + this, + &DlgTrackInfo::slotColorButtonClicked); + connect(btnColorPickerNoColor, + &QPushButton::clicked, + this, + &DlgTrackInfo::slotColorButtonClicked); + connect(m_pColorPicker.get(), + &WColorPickerAction::colorPicked, + this, + &DlgTrackInfo::slotColorPicked); } void DlgTrackInfo::slotApply() { @@ -311,6 +344,9 @@ void DlgTrackInfo::updateFromTrack(const Track& track) { track.getRecord(), track.getLocation()); + // paint the color selector and check the respective color picker button + slotColorPicked(track.getColor()); + txtLocation->setText(QDir::toNativeSeparators(track.getLocation())); reloadTrackBeats(track); @@ -491,10 +527,45 @@ void DlgTrackInfo::slotOpenInFileBrowser() { if (!m_pLoadedTrack) { return; } - mixxx::DesktopHelper::openInFileBrowser(QStringList(m_pLoadedTrack->getLocation())); } +void DlgTrackInfo::slotColorButtonClicked() { + if (!m_pLoadedTrack) { + return; + } + btnColorPicker->showMenu(); +} + +void DlgTrackInfo::slotColorPicked(const mixxx::RgbColor::optional_t& newColor) { + m_pColorPicker->setSelectedColor(newColor); + btnColorPicker->menu()->close(); + + m_trackRecord.setColor(newColor); + const QColor ccolor = mixxx::RgbColor::toQColor(newColor); + + // depending on whether a color or 'no color' was selected, show the colored + // selector or the neutral 'no color' selector + if (newColor) { + btnColorPicker->setStyleSheet(QStringLiteral( + "QPushButton {background-color: %1;}") + .arg(ccolor.name(QColor::HexRgb))); + bool refocus = btnColorPickerNoColor->hasFocus(); + btnColorPickerNoColor->hide(); + btnColorPicker->show(); + if (refocus) { + btnColorPicker->setFocus(); + } + } else { // no color + bool refocus = btnColorPicker->hasFocus(); + btnColorPicker->hide(); + btnColorPickerNoColor->show(); + if (refocus) { + btnColorPickerNoColor->setFocus(); + } + } +} + void DlgTrackInfo::saveTrack() { if (!m_pLoadedTrack) { return; diff --git a/src/library/dlgtrackinfo.h b/src/library/dlgtrackinfo.h index c21f38115ad6..66246cc7f513 100644 --- a/src/library/dlgtrackinfo.h +++ b/src/library/dlgtrackinfo.h @@ -13,12 +13,14 @@ #include "track/trackrecord.h" #include "util/parented_ptr.h" #include "util/tapfilter.h" +#include "widget/wcolorpickeraction.h" class TrackModel; class DlgTagFetcher; class WCoverArtLabel; class WCoverArtMenu; class WStarRating; +class WColorPickerAction; /// A dialog box to display and edit track properties. /// Use TrackPointer to load a track into the dialog or @@ -67,6 +69,8 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo { void slotTrackChanged(TrackId trackId); void slotOpenInFileBrowser(); + void slotColorButtonClicked(); + void slotColorPicked(const mixxx::RgbColor::optional_t& color); void slotCoverFound( const QObject* pRequestor, @@ -122,6 +126,7 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo { parented_ptr m_pWCoverArtMenu; parented_ptr m_pWCoverArtLabel; parented_ptr m_pWStarRating; + parented_ptr m_pColorPicker; std::unique_ptr m_pDlgTagFetcher; }; diff --git a/src/library/dlgtrackinfo.ui b/src/library/dlgtrackinfo.ui index 12484d712b7d..32a3ecf7aa25 100644 --- a/src/library/dlgtrackinfo.ui +++ b/src/library/dlgtrackinfo.ui @@ -93,8 +93,7 @@ - - + @@ -438,8 +437,58 @@ + + + + Color + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + + 40 + 10 + + + + + + + + @@ -1000,6 +1049,8 @@ Often results in higher quality beatgrids, but will not do well on tracks that h txtTrackNumber btnImportMetadataFromMusicBrainz btnImportMetadataFromFile + btnColorPicker + btnColorPickerNoColor btnOpenFileBrowser spinBpm bpmConst