summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--src/engine/controls/cuecontrol.cpp69
-rw-r--r--src/engine/controls/cuecontrol.h9
-rw-r--r--src/library/dao/cuedao.cpp18
-rw-r--r--src/library/dlgtrackinfo.cpp54
-rw-r--r--src/library/dlgtrackinfo.h3
-rw-r--r--src/track/cue.cpp16
-rw-r--r--src/track/cue.h17
-rw-r--r--src/util/color/hotcuecolorpalette.cpp6
-rw-r--r--src/util/color/hotcuecolorpalette.h26
-rw-r--r--src/waveform/renderers/waveformrendermark.cpp2
-rw-r--r--src/widget/wcolorpicker.cpp170
-rw-r--r--src/widget/wcolorpicker.h18
-rw-r--r--src/widget/wcolorpickeraction.cpp8
-rw-r--r--src/widget/wcolorpickeraction.h5
-rw-r--r--src/widget/wcuemenupopup.cpp10
-rw-r--r--src/widget/wcuemenupopup.h6
-rw-r--r--src/widget/woverview.cpp11
-rw-r--r--src/widget/wtracktableview.cpp28
-rw-r--r--src/widget/wtracktableview.h2
20 files changed, 288 insertions, 194 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fe138a654e..24996722a4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -313,7 +313,6 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/errordialoghandler.cpp
src/library/analysisfeature.cpp
src/library/analysislibrarytablemodel.cpp
- src/library/trackloader.cpp
src/library/autodj/autodjfeature.cpp
src/library/autodj/autodjprocessor.cpp
src/library/autodj/dlgautodj.cpp
@@ -410,6 +409,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/library/tableitemdelegate.cpp
src/library/trackcollection.cpp
src/library/trackcollectionmanager.cpp
+ src/library/trackloader.cpp
src/library/traktor/traktorfeature.cpp
src/library/treeitem.cpp
src/library/treeitemmodel.cpp
@@ -473,6 +473,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/preferences/dialog/dlgprefwaveformdlg.ui
src/preferences/dlgpreferencepage.cpp
src/preferences/effectsettingsmodel.cpp
+ src/preferences/hotcuecolorpalettesettings.cpp
src/preferences/replaygainsettings.cpp
src/preferences/settingsmanager.cpp
src/preferences/upgrade.cpp
@@ -533,6 +534,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/util/cache.cpp
src/util/cmdlineargs.cpp
src/util/color/color.cpp
+ src/util/color/hotcuecolorpalette.cpp
src/util/color/predefinedcolor.cpp
src/util/console.cpp
src/util/db/dbconnection.cpp
diff --git a/src/engine/controls/cuecontrol.cpp b/src/engine/controls/cuecontrol.cpp
index 8205ab61e0..830c4f52b8 100644
--- a/src/engine/controls/cuecontrol.cpp
+++ b/src/engine/controls/cuecontrol.cpp
@@ -6,12 +6,13 @@
#include "engine/enginebuffer.h"
#include "engine/controls/cuecontrol.h"
+#include "control/controlindicator.h"
#include "control/controlobject.h"
#include "control/controlpushbutton.h"
-#include "control/controlindicator.h"
-#include "vinylcontrol/defs_vinylcontrol.h"
-#include "util/sample.h"
+#include "preferences/hotcuecolorpalettesettings.h"
#include "util/color/color.h"
+#include "util/sample.h"
+#include "vinylcontrol/defs_vinylcontrol.h"
// TODO: Convert these doubles to a standard enum
// and convert elseif logic to switch statements
@@ -25,6 +26,7 @@ static const double CUE_MODE_CUP = 5.0;
CueControl::CueControl(QString group,
UserSettingsPointer pConfig) :
EngineControl(group, pConfig),
+ m_pConfig(pConfig),
m_bPreviewing(false),
// m_pPlay->toBoo() -> engine play state
// m_pPlay->set(1.0) -> emulate play button press
@@ -597,9 +599,12 @@ void CueControl::hotcueSet(HotcueControl* pControl, double v) {
// TODO(XXX) deal with spurious signals
attachCue(pCue, pControl);
- if (getConfig()->getValue(ConfigKey("[Controls]", "auto_hotcue_colors"), false)) {
- const QList<PredefinedColorPointer> predefinedColors = Color::kPredefinedColorsSet.allColors;
- pCue->setColor(predefinedColors.at((hotcue % (predefinedColors.count() - 1)) + 1));
+ ConfigKey autoHotcueColorsKey("[Controls]", "auto_hotcue_colors");
+ if (getConfig()->getValue(autoHotcueColorsKey, false)) {
+ HotcueColorPaletteSettings colorPaletteSettings(getConfig());
+ auto hotcueColorPalette = colorPaletteSettings.getHotcueColorPalette();
+ auto colors = hotcueColorPalette.m_colorList;
+ pCue->setColor(colors.at((hotcue % (colors.count() - 1)) + 1));
};
// If quantize is enabled and we are not playing, jump to the cue point
@@ -1684,20 +1689,20 @@ void CueControl::hotcueFocusColorPrev(double v) {
return;
}
- PredefinedColorPointer pColor = pControl->getColor();
- if (!pColor) {
- return;
- }
+ QColor color = pControl->getColor();
+ DEBUG_ASSERT(color.isValid());
+
+ HotcueColorPaletteSettings colorPaletteSettings(m_pConfig);
+ HotcueColorPalette colorPalette = colorPaletteSettings.getHotcueColorPalette();
// Get previous color in color set
- int iColorIndex = Color::kPredefinedColorsSet.predefinedColorIndex(pColor) - 1;
+ int iColorIndex = colorPalette.indexOf(color) - 1;
if (iColorIndex <= 0) {
- iColorIndex = Color::kPredefinedColorsSet.allColors.size() - 1;
+ iColorIndex = colorPalette.size() - 1;
}
- pColor = Color::kPredefinedColorsSet.allColors.at(iColorIndex);
- DEBUG_ASSERT(pColor != nullptr);
+ color = colorPalette.at(iColorIndex);
- pControl->setColor(pColor);
+ pControl->setColor(color);
}
void CueControl::hotcueFocusColorNext(double v) {
@@ -1715,20 +1720,20 @@ void CueControl::hotcueFocusColorNext(double v) {
return;
}
- PredefinedColorPointer pColor = pControl->getColor();
- if (!pColor) {
- return;
- }
+ QColor color = pControl->getColor();
+ DEBUG_ASSERT(color.isValid());
+
+ HotcueColorPaletteSettings colorPaletteSettings(m_pConfig);
+ HotcueColorPalette colorPalette = colorPaletteSettings.getHotcueColorPalette();
- // Get next color in color set
- int iColorIndex = Color::kPredefinedColorsSet.predefinedColorIndex(pColor) + 1;
- if (iColorIndex >= Color::kPredefinedColorsSet.allColors.size()) {
+ // Get previous color in color set
+ int iColorIndex = colorPalette.indexOf(color) + 1;
+ if (iColorIndex >= colorPalette.size()) {
iColorIndex = 0;
}
- pColor = Color::kPredefinedColorsSet.allColors.at(iColorIndex);
- DEBUG_ASSERT(pColor != nullptr);
+ color = colorPalette.at(iColorIndex);
- pControl->setColor(pColor);
+ pControl->setColor(color);
}
@@ -1845,9 +1850,9 @@ void HotcueControl::slotHotcuePositionChanged(double newPosition) {
emit hotcuePositionChanged(this, newPosition);
}
-void HotcueControl::slotHotcueColorChanged(double newColorId) {
- m_pCue->setColor(Color::kPredefinedColorsSet.predefinedColorFromId(newColorId));
- emit hotcueColorChanged(this, newColorId);
+void HotcueControl::slotHotcueColorChanged(double newColor) {
+ m_pCue->setColor(QColor::fromRgba(newColor));
+ emit(hotcueColorChanged(this, newColor));
}
double HotcueControl::getPosition() const {
@@ -1861,12 +1866,12 @@ void HotcueControl::setCue(CuePointer pCue) {
// because we have a null check for valid data else where in the code
m_pCue = pCue;
}
-PredefinedColorPointer HotcueControl::getColor() const {
- return Color::kPredefinedColorsSet.predefinedColorFromId(m_hotcueColor->get());
+QColor HotcueControl::getColor() const {
+ return QColor::fromRgba(m_hotcueColor->get());
}
-void HotcueControl::setColor(PredefinedColorPointer newColor) {
- m_hotcueColor->set(static_cast<double>(newColor->m_iId));
+void HotcueControl::setColor(const QColor& newColor) {
+ m_hotcueColor->set(newColor.rgba());
}
void HotcueControl::resetCue() {
// clear pCue first because we have a null check for valid data else where
diff --git a/src/engine/controls/cuecontrol.h b/src/engine/controls/cuecontrol.h
index be65fd1a33..e90b344f1e 100644
--- a/src/engine/controls/cuecontrol.h
+++ b/src/engine/controls/cuecontrol.h
@@ -50,8 +50,8 @@ class HotcueControl : public QObject {
void setCue(CuePointer pCue);
void resetCue();
void setPosition(double position);
- void setColor(PredefinedColorPointer newColor);
- PredefinedColorPointer getColor() const;
+ void setColor(const QColor& newColor);
+ QColor getColor() const;
// Used for caching the preview state of this hotcue control.
inline bool isPreviewing() {
@@ -76,7 +76,7 @@ class HotcueControl : public QObject {
void slotHotcueActivatePreview(double v);
void slotHotcueClear(double v);
void slotHotcuePositionChanged(double newPosition);
- void slotHotcueColorChanged(double newColorId);
+ void slotHotcueColorChanged(double newColor);
signals:
void hotcueSet(HotcueControl* pHotcue, double v);
@@ -87,7 +87,7 @@ class HotcueControl : public QObject {
void hotcueActivatePreview(HotcueControl* pHotcue, double v);
void hotcueClear(HotcueControl* pHotcue, double v);
void hotcuePositionChanged(HotcueControl* pHotcue, double newPosition);
- void hotcueColorChanged(HotcueControl* pHotcue, double newColorId);
+ void hotcueColorChanged(HotcueControl* pHotcue, double newColor);
void hotcuePlay(double v);
private:
@@ -193,6 +193,7 @@ class CueControl : public EngineControl {
double getQuantizedCurrentPosition();
TrackAt getTrackAt() const;
+ UserSettingsPointer m_pConfig;
bool m_bPreviewing;
ControlObject* m_pPlay;
ControlObject* m_pStopButton;
diff --git a/src/library/dao/cuedao.cpp b/src/library/dao/cuedao.cpp
index 5d81c21561..3b8afb9cbe 100644
--- a/src/library/dao/cuedao.cpp
+++ b/src/library/dao/cuedao.cpp
@@ -11,7 +11,6 @@
#include "library/queryutil.h"
#include "util/assert.h"
#include "util/performancetimer.h"
-#include "util/color/color.h"
#include "util/color/predefinedcolor.h"
int CueDAO::cueCount() {
@@ -53,9 +52,16 @@ CuePointer CueDAO::cueFromRow(const QSqlQuery& query) const {
int length = record.value(record.indexOf("length")).toInt();
int hotcue = record.value(record.indexOf("hotcue")).toInt();
QString label = record.value(record.indexOf("label")).toString();
- int iColorId = record.value(record.indexOf("color")).toInt();
- PredefinedColorPointer color = Color::kPredefinedColorsSet.predefinedColorFromId(iColorId);
- CuePointer pCue(new Cue(id, trackId, (Cue::Type)type, position, length, hotcue, label, color));
+ uint colorValue = record.value(record.indexOf("color")).toUInt();
+ QColor color = QColor::fromRgba(colorValue);
+ CuePointer pCue(new Cue(id,
+ trackId,
+ (Cue::Type)type,
+ position,
+ length,
+ hotcue,
+ label,
+ color));
m_cues[id] = pCue;
return pCue;
}
@@ -147,7 +153,7 @@ bool CueDAO::saveCue(Cue* cue) {
query.bindValue(":length", cue->getLength());
query.bindValue(":hotcue", cue->getHotCue());
query.bindValue(":label", cue->getLabel());
- query.bindValue(":color", cue->getColor()->m_iId);
+ query.bindValue(":color", cue->getColor().rgba());
if (query.exec()) {
int id = query.lastInsertId().toInt();
@@ -175,7 +181,7 @@ bool CueDAO::saveCue(Cue* cue) {
query.bindValue(":length", cue->getLength());
query.bindValue(":hotcue", cue->getHotCue());
query.bindValue(":label", cue->getLabel());
- query.bindValue(":color", cue->getColor()->m_iId);
+ query.bindValue(":color", cue->getColor().rgba());
if (query.exec()) {
cue->setDirty(false);
diff --git a/src/library/dlgtrackinfo.cpp b/src/library/dlgtrackinfo.cpp
index 64ae4c8b29..1df502769f 100644
--- a/src/library/dlgtrackinfo.cpp
+++ b/src/library/dlgtrackinfo.cpp
@@ -1,16 +1,19 @@
+#include <QComboBox>
#include <QDesktopServices>
-#include <QtDebug>
+#include <QStringBuilder>
#include <QComboBox>
+#include <QtDebug>
#include "library/coverartcache.h"
#include "library/coverartutils.h"
#include "library/dlgtrackinfo.h"
+#include "preferences/hotcuecolorpalettesettings.h"
#include "sources/soundsourceproxy.h"
#include "track/beatfactory.h"
#include "track/cue.h"
#include "track/keyfactory.h"
#include "track/keyutils.h"
-#include "util/color/color.h"
+#include "util/color/hotcuecolorpalette.h"
#include "util/compatibility.h"
#include "util/desktophelper.h"
#include "util/duration.h"
@@ -21,11 +24,12 @@ const int kMinBpm = 30;
// Maximum allowed interval between beats (calculated from kMinBpm).
const mixxx::Duration kMaxInterval = mixxx::Duration::fromMillis(1000.0 * (60.0 / kMinBpm));
-DlgTrackInfo::DlgTrackInfo(QWidget* parent)
- : QDialog(parent),
- m_pTapFilter(new TapFilter(this, kFilterLength, kMaxInterval)),
- m_dLastTapedBpm(-1.),
- m_pWCoverArtLabel(new WCoverArtLabel(this)) {
+DlgTrackInfo::DlgTrackInfo(UserSettingsPointer pConfig, QWidget* parent)
+ : QDialog(parent),
+ m_pTapFilter(new TapFilter(this, kFilterLength, kMaxInterval)),
+ m_dLastTapedBpm(-1.),
+ m_pWCoverArtLabel(new WCoverArtLabel(this)),
+ m_pConfig(pConfig) {
init();
}
@@ -408,21 +412,22 @@ void DlgTrackInfo::populateCues(TrackPointer pTrack) {
// Make the type read only
typeItem->setFlags(Qt::NoItemFlags);
+ HotcueColorPaletteSettings colorPaletteSettings(m_pConfig);
+ auto colorPalette = colorPaletteSettings.getHotcueColorPalette();
+ QList<QColor> hotcueColorList =
+ colorPaletteSettings.getHotcueColorPalette().m_colorList;
QComboBox* colorComboBox = new QComboBox();
- const QList<PredefinedColorPointer> predefinedColors = Color::kPredefinedColorsSet.allColors;
- for (int i = 0; i < predefinedColors.count(); i++) {
- PredefinedColorPointer color = predefinedColors.at(i);
- QColor defaultRgba = color->m_defaultRgba;
- colorComboBox->addItem(color->m_sDisplayName, defaultRgba);
- if (*color != *Color::kPredefinedColorsSet.noColor) {
- QPixmap pixmap(80, 80);
- pixmap.fill(defaultRgba);
- QIcon icon(pixmap);
- colorComboBox->setItemIcon(i, icon);
- }
+ for (int i = 0; i < hotcueColorList.count(); i++) {
+ QColor color = hotcueColorList.at(i);
+ colorComboBox->addItem("", color);
+ QPixmap pixmap(80, 80);
+ pixmap.fill(color);
+ QIcon icon(pixmap);
+ colorComboBox->setItemIcon(i, icon);
}
- PredefinedColorPointer cueColor = pCue->getColor();
- colorComboBox->setCurrentIndex(Color::kPredefinedColorsSet.predefinedColorIndex(cueColor));
+ QColor cueColor = pCue->getColor();
+ int colorIndex = hotcueColorList.indexOf(cueColor);
+ colorComboBox->setCurrentIndex(math_min(colorIndex, 0));
m_cueMap[row] = pCue;
cueTable->insertRow(row);
@@ -507,7 +512,14 @@ void DlgTrackInfo::saveTrack() {
if (pCue->getType() == Cue::Type::HotCue) {
auto colorComboBox = qobject_cast<QComboBox*>(colorWidget);
if (colorComboBox) {
- PredefinedColorPointer color = Color::kPredefinedColorsSet.allColors.at(colorComboBox->currentIndex());
+ HotcueColorPaletteSettings colorPaletteSettings(m_pConfig);
+ auto colorPalette =
+ colorPaletteSettings.getHotcueColorPalette();
+ QList<QColor> hotcueColorList =
+ colorPaletteSettings.getHotcueColorPalette()
+ .m_colorList;
+ QColor color =
+ hotcueColorList.at(colorComboBox->currentIndex());
pCue->setColor(color);
}
}
diff --git a/src/library/dlgtrackinfo.h b/src/library/dlgtrackinfo.h
index 677483ead3..341de08ad0 100644
--- a/src/library/dlgtrackinfo.h
+++ b/src/library/dlgtrackinfo.h
@@ -18,7 +18,7 @@
class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {
Q_OBJECT
public:
- DlgTrackInfo(QWidget* parent);
+ DlgTrackInfo(UserSettingsPointer pConfig, QWidget* parent);
virtual ~DlgTrackInfo();
public slots:
@@ -85,6 +85,7 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {
CoverInfo m_loadedCoverInfo;
WCoverArtLabel* m_pWCoverArtLabel;
+ UserSettingsPointer m_pConfig;
};
#endif /* DLGTRACKINFO_H */
diff --git a/src/track/cue.cpp b/src/track/cue.cpp
index d0951a86d9..99ec0f7427 100644
--- a/src/track/cue.cpp
+++ b/src/track/cue.cpp
@@ -28,12 +28,18 @@ Cue::Cue(TrackId trackId)
m_sampleEndPosition(Cue::kNoPosition),
m_iHotCue(-1),
m_label(kDefaultLabel),
- m_color(Color::kPredefinedColorsSet.noColor) {
+ m_color(QColor()) {
DEBUG_ASSERT(!m_label.isNull());
}
-Cue::Cue(int id, TrackId trackId, Cue::Type type, double position, double length,
- int hotCue, QString label, PredefinedColorPointer color)
+Cue::Cue(int id,
+ TrackId trackId,
+ Cue::Type type,
+ double position,
+ double length,
+ int hotCue,
+ QString label,
+ QColor color)
: m_bDirty(false),
m_iId(id),
m_trackId(trackId),
@@ -153,12 +159,12 @@ void Cue::setLabel(const QString label) {
emit updated();
}
-PredefinedColorPointer Cue::getColor() const {
+QColor Cue::getColor() const {
QMutexLocker lock(&m_mutex);
return m_color;
}
-void Cue::setColor(const PredefinedColorPointer color) {
+void Cue::setColor(const QColor& color) {
QMutexLocker lock(&m_mutex);
m_color = color;
m_bDirty = true;
diff --git a/src/track/cue.h b/src/track/cue.h
index ffc1c81469..9b6d133766 100644
--- a/src/track/cue.h
+++ b/src/track/cue.h
@@ -6,7 +6,6 @@
#include <QColor>
#include "track/trackid.h"
-#include "util/color/predefinedcolor.h"
#include "util/memory.h"
class CuePosition;
@@ -54,8 +53,8 @@ class Cue : public QObject {
QString getLabel() const;
void setLabel(QString label);
- PredefinedColorPointer getColor() const;
- void setColor(PredefinedColorPointer color);
+ QColor getColor() const;
+ void setColor(const QColor& color);
double getEndPosition() const;
@@ -64,8 +63,14 @@ class Cue : public QObject {
private:
explicit Cue(TrackId trackId);
- Cue(int id, TrackId trackId, Cue::Type type, double position, double length,
- int hotCue, QString label, PredefinedColorPointer color);
+ Cue(int id,
+ TrackId trackId,
+ Cue::Type type,
+ double position,
+ double length,
+ int hotCue,
+ QString label,
+ QColor color);
void setDirty(bool dirty);
void setId(int id);
void setTrackId(TrackId trackId);
@@ -80,7 +85,7 @@ class Cue : public QObject {
double m_sampleEndPosition;
int m_iHotCue;
QString m_label;
- PredefinedColorPointer m_color;
+ QColor m_color;
friend class Track;
friend class CueDAO;
diff --git a/src/util/color/hotcuecolorpalette.cpp b/src/util/color/hotcuecolorpalette.cpp
index d0b003ef2d..ab51fde7a0 100644
--- a/src/util/color/hotcuecolorpalette.cpp
+++ b/src/util/color/hotcuecolorpalette.cpp
@@ -4,10 +4,6 @@
#include "hotcuecolorpalette.h"
-HotcueColorPalette::HotcueColorPalette(QList<QColor> colorList)
- : m_colorList(colorList) {
-}
-
const HotcueColorPalette HotcueColorPalette::mixxxPalette =
HotcueColorPalette(QList<QColor>{
QColor("#c50a08"),
@@ -17,4 +13,4 @@ const HotcueColorPalette HotcueColorPalette::mixxxPalette =
QColor("#42d4f4"),
QColor("#af00cc"),
QColor("#fca6d7"),
- QColor("#f2f2ff")}); \ No newline at end of file
+ QColor("#f2f2ff")});
diff --git a/src/util/color/hotcuecolorpalette.h b/src/util/color/hotcuecolorpalette.h
index a544599f3e..de9f2c33af 100644
--- a/src/util/color/hotcuecolorpalette.h
+++ b/src/util/color/hotcuecolorpalette.h
@@ -5,11 +5,33 @@
#pragma once
#include <QColor>
-#include "QList"
+#include <QList>
class HotcueColorPalette {
public:
- HotcueColorPalette(QList<QColor>);
+ HotcueColorPalette(QList<QColor> colorList)
+ : m_colorList(colorList) {
+ }
+
+ QColor at(int i) const {
+ return m_colorList.at(i);
+ }
+
+ int size() const {
+ return m_colorList.size();
+ }
+
+ int indexOf(QColor color) const {
+ return m_colorList.indexOf(color);
+ }
+
+ QList<QColor>::const_iterator begin() const {
+ return m_colorList.begin();
+ }
+
+ QList<QColor>::const_iterator end() const {
+ return m_colorList.end();
+ }
static const HotcueColorPalette mixxxPalette;
diff --git a/src/waveform/renderers/waveformrendermark.cpp b/src/waveform/renderers/waveformrendermark.cpp
index 1d338688e0..d22fa1b20e 100644
--- a/src/waveform/renderers/waveformrendermark.cpp
+++ b/src/waveform/renderers/waveformrendermark.cpp
@@ -128,7 +128,7 @@ void WaveformRenderMark::slotCuesUpdated() {
}
QString newLabel = pCue->getLabel();
- QColor newColor = m_predefinedColorsRepresentation.representationFor(pCue->getColor());
+ QColor newColor = pCue->getColor();
if (pMark->m_text.isNull() || newLabel != pMark->m_text ||
!pMark->fillColor().isValid() || newColor != pMark->fillColor()) {
pMark->m_text = newLabel;
diff --git a/src/widget/wcolorpicker.cpp b/src/widget/wcolorpicker.cpp
index c6c9427869..10e2257f76 100644
--- a/src/widget/wcolorpicker.cpp
+++ b/src/widget/wcolorpicker.cpp
@@ -1,6 +1,5 @@
#include "widget/wcolorpicker.h"
-#include <QGridLayout>
#include <QMapIterator>
#include <QPushButton>
#include <QStyle>
@@ -13,7 +12,9 @@ namespace {
}
WColorPicker::WColorPicker(ColorOption colorOption, QWidget* parent)
- : QWidget(parent) {
+ : QWidget(parent),
+ m_colorOption(colorOption),
+ m_palette(HotcueColorPalette::mixxxPalette) {
QGridLayout* pLayout = new QGridLayout();
pLayout->setMargin(0);
pLayout->setContentsMargins(0, 0, 0, 0);
@@ -33,93 +34,130 @@ WColorPicker::WColorPicker(ColorOption colorOption, QWidget* parent)
int row = 0;
int column = 0;
- for (const auto& pColor : Color::kPredefinedColorsSet.allColors) {
- if (colorOption != ColorOption::AllowNoColor &&
- pColor == Color::kPredefinedColorsSet.noColor) {
- continue;
- }
-
- parented_ptr<QPushButton> pColorButton = make_parented<QPushButton>("", this);
- if (m_pStyle) {
- pColorButton->setStyle(m_pStyle);
- }
-
- if (pColor->m_defaultRgba.isValid()) {
- // Set the background color of the button. This can't be overridden in skin stylesheets.
- pColorButton->setStyleSheet(
- QString("QPushButton { background-color: #%1; }").arg(pColor->m_defaultRgba.rgb(), 6, 16, QChar('0'))
- );
- } else {
- pColorButton->setProperty("noColor", true);
- }
- pColorButton->setToolTip(pColor->m_sDisplayName);
- pColorButton->setCheckable(true);
- m_pColorButtons.insert(pColor, pColorButton);
+ if (m_colorOption == ColorOption::AllowNoColor) {
+ addColorButton(QColor(), pLayout, row, column);
+ column++;
+ }
- pLayout->addWidget(pColorButton, row, column);
+ for (const auto& color : m_palette) {
+ addColorButton(color, pLayout, row, column);
column++;
if (column == kNumColumns) {
column = 0;
row++;
}
-
- connect(this,
- &WColorPicker::colorPicked,
- this,
- &WColorPicker::slotColorPicked);
- connect(pColorButton,
- &QPushButton::clicked,
- this,
- [pColor, this]() {
- emit colorPicked(pColor);
- });
}
+}
+
+void WColorPicker::addColorButton(const QColor& color, QGridLayout* pLayout, int row, int column) {
setLayout(pLayout);
+ parented_ptr<QPushButton> pColorButton = make_parented<QPushButton>("", this);
+ if (m_pStyle) {
+ pColorButton->setStyle(m_pStyle);
+ }
+
+ if (color.isValid()) {
+ // Set the background color of the button. This can't be overridden in skin stylesheets.
+ pColorButton->setStyleSheet(
+ QString("QPushButton { background-color: %1; }").arg(color.name()));
+ } else {
+ pColorButton->setProperty("noColor", true);
+ }
+
+ pColorButton->setCheckable(true);
+ m_colorButtons.append(pColorButton);
+
+ pLayout->addWidget(pColorButton, row, column);
+
+ connect(this,
+ &WColorPicker::colorPicked,
+ this,
+ &WColorPicker::slotColorPicked);
+ connect(pColorButton,
+ &QPushButton::clicked,
+ this,
+ [color, this]() {
+ emit colorPicked(color);
+ });
}
-void WColorPicker::setSelectedColor(PredefinedColorPointer pColor) {
- if (m_pSelectedColor) {
- auto it = m_pColorButtons.constFind(m_pSelectedColor);
- if (it != m_pColorButtons.constEnd()) {
- it.value()->setChecked(false);
- // This is needed to re-apply skin styles (e.g. to show/hide a checkmark icon)
- it.value()->style()->unpolish(it.value());
- it.value()->style()->polish(it.value());
+void WColorPicker::resetSelectedColor() {
+ // Unset currently selected color
+ int i;
+ if (m_colorOption == ColorOption::AllowNoColor && !m_selectedColor.isValid()) {
+ i = 0;
+ } else {
+ i = m_palette.indexOf(m_selectedColor);
+ if (i == -1) {
+ return;
}
+ if (m_colorOption == ColorOption::AllowNoColor) {
+ i++;
+ }
+ }
+
+ DEBUG_ASSERT(i < m_colorButtons.size());
+
+ QPushButton* pButton = m_colorButtons.at(i);
+ VERIFY_OR_DEBUG_ASSERT(pButton != nullptr) {
+ return;
}
+ pButton->setChecked(false);
+ // This is needed to re-apply skin styles (e.g. to show/hide a checkmark icon)
+ pButton->style()->unpolish(pButton);
+ pButton->style()->polish(pButton);
+}
+
+void WColorPicker::setSelectedColor(const QColor& color) {
+ resetSelectedColor();
- if (pColor) {
- auto it = m_pColorButtons.constFind(pColor);
- if (it != m_pColorButtons.constEnd()) {
- it.value()->setChecked(true);
- // This is needed to re-apply skin styles (e.g. to show/hide a checkmark icon)
- it.value()->style()->unpolish(it.value());
- it.value()->style()->polish(it.value());
+ m_selectedColor = color;
+
+ int i;
+ if (m_colorOption == ColorOption::AllowNoColor && !color.isValid()) {
+ i = 0;
+ } else {
+ i = m_palette.indexOf(color);
+ if (i == -1) {
+ return;
+ }
+ if (m_colorOption == ColorOption::AllowNoColor) {
+ i++;
}
}
- m_pSelectedColor = pColor;
+ DEBUG_ASSERT(i < m_colorButtons.size());
+
+ QPushButton* pButton = m_colorButtons.at(i);
+ VERIFY_OR_DEBUG_ASSERT(pButton != nullptr) {
+ return;
+ }
+ pButton->setChecked(true);
+ // This is needed to re-apply skin styles (e.g. to show/hide a checkmark icon)
+ pButton->style()->unpolish(pButton);
+ pButton->style()->polish(pButton);
}
-void WColorPicker::useColorSet(PredefinedColorsRepresentation* pColorRepresentation) {
- QMapIterator<PredefinedColorPointer, QPushButton*> i(m_pColorButtons);
- while (i.hasNext()) {
- i.next();
- PredefinedColorPointer pColor = i.key();
- QPushButton* pColorButton = i.value();
- QColor color = (pColorRepresentation == nullptr) ? pColor->m_defaultRgba : pColorRepresentation->representationFor(pColor);
+void WColorPicker::useColorSet(const HotcueColorPalette& palette) {
+ for (int i = 0; i < m_colorButtons.size(); ++i) {
+ int j = i;
+ if (m_colorOption == ColorOption::AllowNoColor) {
+ j++;
+ }
- // Set the background color of the button. This can't be overridden in skin stylesheets.
- pColorButton->setStyleSheet(
- QString("QPushButton { background-color: #%1; }").arg(color.rgb(), 6, 16, QChar('0'))
- );
+ if (i >= palette.size() || j >= m_colorButtons.size()) {
+ return;
+ }
- pColorButton->setToolTip(pColor->m_sDisplayName);
+ // Set the background color of the button. This can't be overridden in skin stylesheets.
+ m_colorButtons.at(j)->setStyleSheet(
+ QString("QPushButton { background-color: %1; }")
+ .arg(palette.at(i).name()));
}
}
-void WColorPicker::slotColorPicked(PredefinedColorPointer pColor) {
- setSelectedColor(pColor);
+void WColorPicker::slotColorPicked(const QColor& color) {
+ setSelectedColor(color);
}
diff --git a/src/widget/wcolorpicker.h b/src/widget/wcolorpicker.h
index e3e10e5709..0e7befac1b 100644
--- a/src/widget/wcolorpicker.h
+++ b/src/widget/wcolorpicker.h
@@ -1,11 +1,13 @@
#pragma once
+#include <QGridLayout>
#include <QPushButton>
#include <QMap>
#include <QWidget>
#include <QStyleFactory>
#include "util/color/color.h"
+#include "util/color/hotcuecolorpalette.h"
class WColorPicker : public QWidget {
Q_OBJECT
@@ -17,17 +19,21 @@ class WColorPicker : public QWidget {
explicit WColorPicker(ColorOption colorOption, QWidget* parent = nullptr);
- void setSelectedColor(PredefinedColorPointer pColor = nullptr);
- void useColorSet(PredefinedColorsRepresentation* pColorRepresentation);
+ void resetSelectedColor();
+ void setSelectedColor(const QColor& color);
+ void useColorSet(const HotcueColorPalette& palette);
signals:
- void colorPicked(PredefinedColorPointer pColor);
+ void colorPicked(QColor color);
private slots:
- void slotColorPicked(PredefinedColorPointer pColor);
+ void slotColorPicked(const QColor& color);
private:
- QMap<PredefinedColorPointer, QPushButton*> m_pColorButtons;
- PredefinedColorPointer m_pSelectedColor;
+ void addColorButton(const QColor& color, QGridLayout* pLayout, int row, int column);
+ ColorOption m_colorOption;
+ QColor m_selectedColor;
+ HotcueColorPalette m_palette;
+ QList<QPushButton*> m_colorButtons;
QStyle* m_pStyle;
};
diff --git a/src/widget/wcolorpickeraction.cpp b/src/widget/wcolorpickeraction.cpp
index db72bc97e9..5270a75a4b 100644
--- a/src/widget/wcolorpickeraction.cpp
+++ b/src/widget/wcolorpickeraction.cpp
@@ -13,6 +13,10 @@ WColorPickerAction::WColorPickerAction(WColorPicker::ColorOption colorOption, QW
setDefaultWidget(pWidget);
}
-void WColorPickerAction::setSelectedColor(PredefinedColorPointer pColor) {
- m_pColorPicker->setSelectedColor(pColor);
+void WColorPickerAction::resetSelectedColor() {
+ m_pColorPicker->resetSelectedColor();
+}
+
+void WColorPickerAction::setSelectedColor(QColor color) {
+ m_pColorPicker->setSelectedColor(color);
}
diff --git a/src/widget/wcolorpickeraction.h b/src/widget/wcolorpickeraction.h
index 48e1012772..9c9ced435b 100644
--- a/src/widget/wcolorpickeraction.h
+++ b/src/widget/wcolorpickeraction.h
@@ -14,10 +14,11 @@ class WColorPickerAction : public QWidgetAction {
WColorPicker::ColorOption colorOption,
QWidget* parent = nullptr);
- void setSelectedColor(PredefinedColorPointer pColor = nullptr);
+ void resetSelectedColor();
+ void setSelectedColor(QColor color = QColor());
signals:
- voi