Skip to content

Commit

Permalink
preferences/colorpalettesettings: Read/Write hotcue indices from/to c…
Browse files Browse the repository at this point in the history
…onfig
  • Loading branch information
Holzhaus committed Mar 5, 2020
1 parent 3fc8514 commit b41234d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/preferences/colorpalettesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace {
const mixxx::RgbColor kColorBlack(0x000000);
const QString kColorPaletteConfigGroup = QStringLiteral("[Config]");
const QString kColorPaletteHotcueIndicesConfigItem = QStringLiteral("hotcue_indices");
const QString kColorPaletteHotcueIndicesConfigSeparator = QStringLiteral(" ");
const QString kColorPaletteGroup = QStringLiteral("[ColorPalette %1]");
const QRegExp kColorPaletteGroupNameRegex("^\\[ColorPalette (.+)\\]$");
const ConfigKey kHotcueColorPaletteConfigKey(kColorPaletteConfigGroup, QStringLiteral("HotcueColorPalette"));
Expand All @@ -27,17 +29,29 @@ ColorPalette ColorPaletteSettings::getColorPalette(

// Read colors from configuration
QList<mixxx::RgbColor> colorList;
QList<unsigned int> hotcueIndices;
for (const ConfigKey& key : m_pConfig->getKeysWithGroup(group)) {
mixxx::RgbColor color = mixxx::RgbColor(m_pConfig->getValue<mixxx::RgbColor>(key, kColorBlack));
colorList.append(color);
if (key.item == kColorPaletteHotcueIndicesConfigItem) {
foreach (const QString& stringIndex,
m_pConfig->getValueString(key).split(kColorPaletteHotcueIndicesConfigSeparator, QString::SkipEmptyParts)) {
bool ok;
int index = stringIndex.toInt(&ok);
if (ok && index > 0) {
hotcueIndices << static_cast<unsigned int>(index);
}
}
} else {
mixxx::RgbColor color = mixxx::RgbColor(m_pConfig->getValue<mixxx::RgbColor>(key, kColorBlack));
colorList.append(color);
}
}

// If no palette is defined in the settings, we use the default one.
if (colorList.isEmpty()) {
return defaultPalette;
}

return ColorPalette(name, colorList);
return ColorPalette(name, colorList, hotcueIndices);
}

void ColorPaletteSettings::setColorPalette(const QString& name, const ColorPalette& colorPalette) {
Expand All @@ -54,6 +68,16 @@ void ColorPaletteSettings::setColorPalette(const QString& name, const ColorPalet
mixxx::RgbColor color = colorPalette.at(index);
m_pConfig->setValue<mixxx::RgbColor>(keyForIndex(group, index), color);
}

QStringList stringIndices;
foreach (const unsigned int index, colorPalette.getHotcueIndices()) {
stringIndices << QString::number(index);
}
if (!stringIndices.isEmpty()) {
m_pConfig->setValue(
ConfigKey(group, kColorPaletteHotcueIndicesConfigItem),
stringIndices.join(kColorPaletteHotcueIndicesConfigSeparator));
}
}

void ColorPaletteSettings::removePalette(const QString& name) {
Expand Down
4 changes: 4 additions & 0 deletions src/util/color/colorpalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class ColorPalette final {
return m_colorList;
}

QList<unsigned int> getHotcueIndices() const {
return m_hotcueColorIndices;
}

private:
QString m_name;
QList<mixxx::RgbColor> m_colorList;
Expand Down

0 comments on commit b41234d

Please sign in to comment.