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 3, 2023
1 parent b0c22f3 commit 29dc7fe
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 4 deletions.
69 changes: 67 additions & 2 deletions src/library/dlgtrackinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ 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,
ColorPaletteSettings(m_pUserSettings).getTrackColorPalette(),
this)) {
init();
}

Expand Down Expand Up @@ -245,6 +249,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() {
Expand Down Expand Up @@ -311,6 +342,8 @@ void DlgTrackInfo::updateFromTrack(const Track& track) {
track.getRecord(),
track.getLocation());

slotColorPicked(track.getColor());

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

reloadTrackBeats(track);
Expand Down Expand Up @@ -491,10 +524,42 @@ 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) {
btnColorPicker->menu()->close();

m_trackRecord.setColor(newColor);
const QColor ccolor = mixxx::RgbColor::toQColor(newColor);

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 {
bool refocus = btnColorPicker->hasFocus();
btnColorPicker->hide();
btnColorPickerNoColor->show();
if (refocus) {
btnColorPickerNoColor->setFocus();
}
}
}

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;
};
55 changes: 53 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,58 @@
</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">
<layout class="QVBoxLayout" name="colorPickerLayout">
<item>
<widget class="QPushButton" name="btnColorPicker">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnColorPickerNoColor">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<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>
</item>


</layout>
</widget>
</item>
Expand Down Expand Up @@ -1000,6 +1049,8 @@ 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>btnColorPickerNoColor</tabstop>
<tabstop>btnOpenFileBrowser</tabstop>
<tabstop>spinBpm</tabstop>
<tabstop>bpmConst</tabstop>
Expand Down

0 comments on commit 29dc7fe

Please sign in to comment.