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

DlgTrackInfo: add track color selector #11436

Merged
merged 3 commits into from
Apr 24, 2023
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
61 changes: 56 additions & 5 deletions src/library/dlgtrackinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ DlgTrackInfo::DlgTrackInfo(
m_tapFilter(this, kFilterLength, kMaxInterval),
m_pWCoverArtMenu(make_parented<WCoverArtMenu>(this)),
m_pWCoverArtLabel(make_parented<WCoverArtLabel>(this, m_pWCoverArtMenu)),
m_pWStarRating(make_parented<WStarRating>(nullptr, this)) {
m_pWStarRating(make_parented<WStarRating>(nullptr, this)),
m_pColorPicker(make_parented<WColorPickerAction>(
WColorPicker::Option::AllowNoColor |
// TODO(xxx) remove this once the preferences are themed via QSS
WColorPicker::Option::NoExtStyleSheet,
ColorPaletteSettings(m_pUserSettings).getTrackColorPalette(),
this)) {
init();
}

Expand Down Expand Up @@ -245,6 +251,23 @@ void DlgTrackInfo::init() {
&WCoverArtMenu::reloadCoverArt,
this,
&DlgTrackInfo::slotReloadCoverArt);

btnColorPicker->setStyle(QStyleFactory::create(QStringLiteral("fusion")));
QMenu* pColorPickerMenu = new QMenu(this);
pColorPickerMenu->addAction(m_pColorPicker);
btnColorPicker->setMenu(pColorPickerMenu);

connect(btnColorPicker,
&QPushButton::clicked,
this,
&DlgTrackInfo::slotColorButtonClicked);
connect(m_pColorPicker.get(),
&WColorPickerAction::colorPicked,
this,
[this](const mixxx::RgbColor::optional_t& newColor) {
trackColorDialogSetColor(newColor);
m_trackRecord.setColor(newColor);
});
}

void DlgTrackInfo::slotApply() {
Expand All @@ -262,9 +285,6 @@ void DlgTrackInfo::slotCancel() {
reject();
}

void DlgTrackInfo::trackUpdated() {
}

void DlgTrackInfo::slotNextButton() {
loadNextTrack();
}
Expand Down Expand Up @@ -311,6 +331,9 @@ void DlgTrackInfo::updateFromTrack(const Track& track) {
track.getRecord(),
track.getLocation());

// paint the color selector and check the respective color picker button
trackColorDialogSetColor(track.getColor());

txtLocation->setText(QDir::toNativeSeparators(track.getLocation()));

reloadTrackBeats(track);
Expand Down Expand Up @@ -491,10 +514,38 @@ 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::trackColorDialogSetColor(const mixxx::RgbColor::optional_t& newColor) {
m_pColorPicker->setSelectedColor(newColor);
btnColorPicker->menu()->close();

if (newColor) {
btnColorPicker->setText("");
const QColor ccolor = mixxx::RgbColor::toQColor(newColor);
const QString styleSheet =
QStringLiteral(
"QPushButton { background-color: %1; color: %2; }")
.arg(ccolor.name(QColor::HexRgb),
Color::isDimColor(ccolor)
? "white"
: "black");
btnColorPicker->setStyleSheet(styleSheet);
} else { // no color
btnColorPicker->setText(tr("(no color)"));
// clear custom stylesheet, i.e. restore Fusion style,
btnColorPicker->setStyleSheet("");
}
}

void DlgTrackInfo::saveTrack() {
if (!m_pLoadedTrack) {
return;
Expand Down
7 changes: 5 additions & 2 deletions src/library/dlgtrackinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,8 +54,6 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {
void slotApply();
void slotCancel();

void trackUpdated();

void slotBpmScale(mixxx::Beats::BpmScale bpmScale);
void slotBpmClear();
void slotBpmConstChanged(int state);
Expand All @@ -67,6 +67,7 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {

void slotTrackChanged(TrackId trackId);
void slotOpenInFileBrowser();
void slotColorButtonClicked();

void slotCoverFound(
const QObject* pRequestor,
Expand All @@ -82,6 +83,7 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {
void loadPrevTrack();
void loadTrackInternal(const TrackPointer& pTrack);
void reloadTrackBeats(const Track& track);
void trackColorDialogSetColor(const mixxx::RgbColor::optional_t& color);
void saveTrack();
void clear();
void init();
Expand Down Expand Up @@ -122,6 +124,7 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {
parented_ptr<WCoverArtMenu> m_pWCoverArtMenu;
parented_ptr<WCoverArtLabel> m_pWCoverArtLabel;
parented_ptr<WStarRating> m_pWStarRating;
parented_ptr<WColorPickerAction> m_pColorPicker;

std::unique_ptr<DlgTagFetcher> m_pDlgTagFetcher;
};
41 changes: 39 additions & 2 deletions src/library/dlgtrackinfo.ui
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@
</property>
</widget>
</item>

<item row="0" column="2" colspan="2" rowspan="3">
<item row="0" column="2" rowspan="3" colspan="2">
<widget class="QWidget" name="verticalWidgetCover" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
Expand Down Expand Up @@ -438,8 +437,45 @@
</layout>
</item>

<item row="9" column="0">
<widget class="QLabel" name="lblTrackColor">
<property name="text">
<string>Color</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>

<item row="9" column="1" colspan="3">
<widget class="QPushButton" name="btnColorPicker">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>

<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>


</layout>
</widget>
</item>
Expand Down Expand Up @@ -1000,6 +1036,7 @@ Often results in higher quality beatgrids, but will not do well on tracks that h
<tabstop>txtTrackNumber</tabstop>
<tabstop>btnImportMetadataFromMusicBrainz</tabstop>
<tabstop>btnImportMetadataFromFile</tabstop>
<tabstop>btnColorPicker</tabstop>
<tabstop>btnOpenFileBrowser</tabstop>
<tabstop>spinBpm</tabstop>
<tabstop>bpmConst</tabstop>
Expand Down