Skip to content

Commit

Permalink
DlgTrackInfo: add track color selector
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Apr 22, 2023
1 parent 425ad1e commit e283a3b
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 4 deletions.
58 changes: 56 additions & 2 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,20 @@ 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,
&DlgTrackInfo::slotColorPicked);
}

void DlgTrackInfo::slotApply() {
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
slotColorPicked(track.getColor());

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

reloadTrackBeats(track);
Expand Down Expand Up @@ -491,10 +514,41 @@ 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);

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
5 changes: 5 additions & 0 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 @@ -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,
Expand Down Expand Up @@ -122,6 +126,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

0 comments on commit e283a3b

Please sign in to comment.