diff options
author | Ferran Pujol Camins <ferranpujolcamins@gmail.com> | 2019-11-02 18:57:42 +0100 |
---|---|---|
committer | Ferran Pujol Camins <ferranpujolcamins@gmail.com> | 2019-11-02 18:57:42 +0100 |
commit | f4c29b2152e2b9a8511d3d6e18f389f00ff30d07 (patch) | |
tree | 69b2cf561bfd19b38a6106e3f35c1d17a6c16cb8 /src | |
parent | 547a1f762f13826a261a3c7e0d50041eb0289d68 (diff) |
Make Cue related code use QColor
.. instead of PredefinedColorPointer.
COs and the database now hold the color hex int representation instead of a color id.
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/controls/cuecontrol.cpp | 30 | ||||
-rw-r--r-- | src/engine/controls/cuecontrol.h | 8 | ||||
-rw-r--r-- | src/library/dao/cuedao.cpp | 19 | ||||
-rw-r--r-- | src/library/dlgtrackinfo.cpp | 54 | ||||
-rw-r--r-- | src/library/dlgtrackinfo.h | 3 | ||||
-rw-r--r-- | src/track/cue.cpp | 17 | ||||
-rw-r--r-- | src/track/cue.h | 18 | ||||
-rw-r--r-- | src/waveform/renderers/waveformrendermark.cpp | 2 | ||||
-rw-r--r-- | src/widget/colormenu.cpp | 29 | ||||
-rw-r--r-- | src/widget/colormenu.h | 8 | ||||
-rw-r--r-- | src/widget/cuemenu.cpp | 10 | ||||
-rw-r--r-- | src/widget/cuemenu.h | 6 | ||||
-rw-r--r-- | src/widget/woverview.cpp | 7 | ||||
-rw-r--r-- | src/widget/wtracktableview.cpp | 2 |
14 files changed, 116 insertions, 97 deletions
diff --git a/src/engine/controls/cuecontrol.cpp b/src/engine/controls/cuecontrol.cpp index 1e1fd43a5f..e0d00676bc 100644 --- a/src/engine/controls/cuecontrol.cpp +++ b/src/engine/controls/cuecontrol.cpp @@ -7,12 +7,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 @@ -579,9 +580,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 @@ -1790,9 +1794,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 { @@ -1806,12 +1810,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 6d9b735cc1..0fcbe048ed 100644 --- a/src/engine/controls/cuecontrol.h +++ b/src/engine/controls/cuecontrol.h @@ -47,8 +47,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() { @@ -73,7 +73,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); @@ -84,7 +84,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: diff --git a/src/library/dao/cuedao.cpp b/src/library/dao/cuedao.cpp index 0b080810a9..bf095943d7 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() { @@ -54,9 +53,17 @@ 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::CueSource)source, (Cue::CueType)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::CueSource)source, + (Cue::CueType)type, + position, + length, + hotcue, + label, + color)); m_cues[id] = pCue; return pCue; } @@ -149,7 +156,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(); @@ -179,7 +186,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 62cd8d5d9c..9f37dc0399 100644 --- a/src/library/dlgtrackinfo.cpp +++ b/src/library/dlgtrackinfo.cpp @@ -1,17 +1,18 @@ +#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" @@ -22,11 +23,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(); } @@ -400,21 +402,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); @@ -499,7 +502,14 @@ void DlgTrackInfo::saveTrack() { if (pCue->getType() == Cue::CUE) { 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 0ca2a44a29..c343d88a48 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 1d27df21c6..828c0958ab 100644 --- a/src/track/cue.cpp +++ b/src/track/cue.cpp @@ -29,12 +29,19 @@ Cue::Cue(TrackId trackId) m_length(0.0), 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::CueSource source, Cue::CueType type, double position, double length, - int hotCue, QString label, PredefinedColorPointer color) +Cue::Cue(int id, + TrackId trackId, + Cue::CueSource source, + Cue::CueType type, + double position, + double length, + int hotCue, + QString label, + QColor color) : m_bDirty(false), m_iId(id), m_trackId(trackId), @@ -155,12 +162,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 d4b3c343a4..8ea3891de9 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; @@ -60,8 +59,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; @@ -70,8 +69,15 @@ class Cue : public QObject { private: explicit Cue(TrackId trackId); - Cue(int id, TrackId trackId, CueSource source, CueType type, double position, double length, - int hotCue, QString label, PredefinedColorPointer color); + Cue(int id, + TrackId trackId, + CueSource source, + CueType type, + double position, + double length, + int hotCue, + QString label, + QColor color); void setDirty(bool dirty); void setId(int id); void setTrackId(TrackId trackId); @@ -87,7 +93,7 @@ class Cue : public QObject { double m_length; int m_iHotCue; QString m_label; - PredefinedColorPointer m_color; + QColor m_color; friend class Track; friend class CueDAO; diff --git a/src/waveform/renderers/waveformrendermark.cpp b/src/waveform/renderers/waveformrendermark.cpp index a5d4926318..d7ef8c90bd 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/colormenu.cpp b/src/widget/colormenu.cpp index 543b271084..0a0c6748ca 100644 --- a/src/widget/colormenu.cpp +++ b/src/widget/colormenu.cpp @@ -6,34 +6,21 @@ ColorMenu::ColorMenu(QWidget *parent) // If another title would be more appropriate in some context, setTitle // can be called again after construction. setTitle(tr("Set color")); - for (const auto& pColor : Color::kPredefinedColorsSet.allColors) { - if (*pColor == *Color::kPredefinedColorsSet.noColor) { - continue; - } + useColorPalette(HotcueColorPalette::mixxxPalette); +} - QAction* pColorAction = new QAction(pColor->m_sDisplayName, this); +void ColorMenu::useColorPalette(const HotcueColorPalette& colorPalette) { + clear(); + for (const auto& pColor : colorPalette.m_colorList) { + QAction* pColorAction = new QAction(this); QPixmap pixmap(80, 80); - pixmap.fill(pColor->m_defaultRgba); + pixmap.fill(pColor); pColorAction->setIcon(QIcon(pixmap)); - m_pColorActions.insert(pColor, pColorAction); + m_pColorActions.append(pColorAction); addAction(pColorAction); connect(pColorAction, &QAction::triggered, this, [pColor, this]() { emit(colorPicked(pColor)); }); } } - -void ColorMenu::useColorSet(PredefinedColorsRepresentation* pColorRepresentation) { - QMapIterator<PredefinedColorPointer, QAction*> i(m_pColorActions); - while (i.hasNext()) { - i.next(); - QPixmap pixmap(80, 80); - if (pColorRepresentation == nullptr) { - pixmap.fill(i.key()->m_defaultRgba); - } else { - pixmap.fill(pColorRepresentation->representationFor(i.key())); - } - i.value()->setIcon(QIcon(pixmap)); - } -} diff --git a/src/widget/colormenu.h b/src/widget/colormenu.h index 4c82943cbb..3577cce7fd 100644 --- a/src/widget/colormenu.h +++ b/src/widget/colormenu.h @@ -2,18 +2,18 @@ #include <QMenu> -#include "util/color/color.h" +#include "util/color/hotcuecolorpalette.h" class ColorMenu : public QMenu { Q_OBJECT public: ColorMenu(QWidget *parent = nullptr); - void useColorSet(PredefinedColorsRepresentation* pColorRepresentation); + void useColorPalette(const HotcueColorPalette& colorPalette); signals: - void colorPicked(PredefinedColorPointer pColor); + void colorPicked(QColor pColor); private: - QMap<PredefinedColorPointer, QAction*> m_pColorActions; + QList<QAction*> m_pColorActions; }; diff --git a/src/widget/cuemenu.cpp b/src/widget/cuemenu.cpp index b9d62a3091..53d88736e8 100644 --- a/src/widget/cuemenu.cpp +++ b/src/widget/cuemenu.cpp @@ -37,14 +37,8 @@ void CueMenu::slotEditLabel() { } } -void CueMenu::slotChangeCueColor(PredefinedColorPointer pColor) { - VERIFY_OR_DEBUG_ASSERT(m_pCue != nullptr) { - return; - } - VERIFY_OR_DEBUG_ASSERT(pColor != nullptr) { - return; - } - m_pCue->setColor(pColor); +void CueMenu::slotChangeCueColor(QColor color) { + m_pCue->setColor(color); } void CueMenu::slotRemoveCue() { diff --git a/src/widget/cuemenu.h b/src/widget/cuemenu.h index 3802292e44..b8f2f2c49a 100644 --- a/src/widget/cuemenu.h +++ b/src/widget/cuemenu.h @@ -20,16 +20,16 @@ class CueMenu : public QMenu { m_pTrack = pTrack; } - void useColorSet(PredefinedColorsRepresentation* pColorRepresentation) { + void useColorSet(const HotcueColorPalette& colorPalette) { if (m_pColorMenu != nullptr) { - m_pColorMenu->useColorSet(pColorRepresentation); + m_pColorMenu->useColorPalette(colorPalette); } } private slots: void slotEditLabel(); void slotRemoveCue(); - void slotChangeCueColor(PredefinedColorPointer pColor); + void slotChangeCueColor(QColor color); private: CuePointer m_pCue; diff --git a/src/widget/woverview.cpp b/src/widget/woverview.cpp index fdf6030e65..996fce3069 100644 --- a/src/widget/woverview.cpp +++ b/src/widget/woverview.cpp @@ -25,6 +25,7 @@ #include "control/controlproxy.h" #include "engine/engine.h" #include "mixer/playermanager.h" +#include "preferences/hotcuecolorpalettesettings.h" #include "track/track.h" #include "util/color/color.h" #include "util/compatibility.h" @@ -137,7 +138,9 @@ void WOverview::setup(const QDomNode& node, const SkinContext& context) { ? defaultMark->fillColor() : m_signalColors.getAxesColor(); m_predefinedColorsRepresentation = context.getCueColorRepresentation(node, defaultColor); - m_pCueMenu->useColorSet(&m_predefinedColorsRepresentation); + HotcueColorPaletteSettings colorPaletteSettings(m_pConfig); + auto colorPalette = colorPaletteSettings.getHotcueColorPalette(); + m_pCueMenu->useColorSet(colorPalette); for (const auto& pMark: m_marks) { if (pMark->isValid()) { @@ -341,7 +344,7 @@ void WOverview::updateCues(const QList<CuePointer> &loadedCues) { if (pMark != nullptr && pMark->isValid() && pMark->isVisible() && pMark->getSamplePosition() != Cue::kPositionNotDefined) { - QColor newColor = m_predefinedColorsRepresentation.representationFor(currentCue->getColor()); + QColor newColor = currentCue->getColor(); if (newColor != pMark->fillColor() || newColor != pMark->m_textColor) { pMark->setBaseColor(newColor); } diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp index 5a39c4dc02..aa916ce322 100644 --- a/src/widget/wtracktableview.cpp +++ b/src/widget/wtracktableview.cpp @@ -754,7 +754,7 @@ void WTrackTableView::showTrackInfo(QModelIndex index) { if (m_pTrackInfo.isNull()) { // Give a NULL parent because otherwise it inherits our style which can // make it unreadable. Bug #673411 - m_pTrackInfo.reset(new DlgTrackInfo(nullptr)); + m_pTrackInfo.reset(new DlgTrackInfo(m_pConfig, nullptr)); connect(m_pTrackInfo.data(), SIGNAL(next()), this, SLOT(slotNextTrackInfo())); |