Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Hotcue RGB colors configurable #2530

Merged
merged 31 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
78f79ab
preferences/colorpalettesettings: Prevent built-in palette name colli…
Holzhaus Mar 5, 2020
816732c
util/color/colorpalette: Add additional predefined color palettes
Holzhaus Mar 3, 2020
5d121a5
util/color/predefinedcolorpalettes: Add Serato DJ Pro/Lite Hotcue pal…
Holzhaus Mar 3, 2020
4c333f2
preferences: Add colors dialog to preferences menu
Holzhaus Mar 3, 2020
c2396c8
preferences/dialog/dlgprefcolors: Show custom palettes in comboboxes
Holzhaus Mar 5, 2020
67005e3
preferences/dialog: Move auto_hotcue_colors from deck to colors page
Holzhaus Mar 5, 2020
3b4c892
preferences: Add Color Palette Editor
Holzhaus Mar 5, 2020
21daf6d
preferences/colorpalettesettings: Fix loading predefined color palettes
Holzhaus Mar 5, 2020
848e303
util/color/colorpalette: Add support for special hotcue color indices
Holzhaus Mar 5, 2020
e46441c
util/color/predefinedcolorpalettes: Add Serato DJ Pro hotcue indices
Holzhaus Mar 5, 2020
053ccdf
preferences/colorpalettesettings: Read/Write hotcue indices from/to c…
Holzhaus Mar 5, 2020
314d8d9
preferences/colorpaletteeditor: Add support for hotcue color indices
Holzhaus Mar 6, 2020
968af43
preferences/colorpaletteeditor: Get rid of ColorPaletteEditorTableView
Holzhaus Mar 6, 2020
b58bd11
preferences/colorpaletteeditormodel: Remove unused function
Holzhaus Mar 6, 2020
eaee78e
preferences/colorpaletteeditor: Improve button update code
Holzhaus Mar 6, 2020
d797ebd
preferences/colorpaletteeditor: Use nicer buttons
Holzhaus Mar 6, 2020
db9ec58
util/color/predefinedcolorpalettes: Add comments
Holzhaus Mar 6, 2020
41ea7ca
util/color/predefinedcolorpalettes: Add Serato DJ Intro Hotcue Palette
Holzhaus Mar 6, 2020
1dd2769
add brush icon for Preferences > Colors
ronso0 Mar 13, 2020
99922a6
res/mixxx.qrc: Add ic_preferences_colors.svg to QRC file
Holzhaus Mar 14, 2020
fb16cd6
preferences/colorpaletteeditor: Move lambda functions to private slots
Holzhaus Mar 17, 2020
9cb30ed
preferences/colorpaletteeditor: Replace foreach() with for (x : y)
Holzhaus Mar 17, 2020
b90de93
preferences/colorpaletteeditor(model): Add class comments to headers
Holzhaus Mar 17, 2020
da2d65e
preferences/colorpaletteeditormodel: Make isDirty/isEmpty const
Holzhaus Mar 19, 2020
6955377
preferences/colorpalettesettings: Use range-based for loops
Holzhaus Mar 19, 2020
6c365bf
preferences/dialog/dlgprefcolors: Fixed name and constness of config ptr
Holzhaus Mar 19, 2020
bdfde5e
preferences/colorpaletteeditor: Improve widget initialization
Holzhaus Mar 19, 2020
14b9e4d
preferences/colorpalettesettings: Print debug message when skipping w…
Holzhaus Mar 19, 2020
de013aa
preferences/colorpaletteeditor: Don't use parented_ptr for model
Holzhaus Mar 19, 2020
ce88ef1
Revert "preferences/colorpaletteeditor: Don't use parented_ptr for mo…
Holzhaus Mar 20, 2020
a3b356a
preferences/colorpaletteeditor: Pass m_pTableView to model
Holzhaus Mar 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
preferences/colorpaletteeditor: Add support for hotcue color indices
  • Loading branch information
Holzhaus committed Mar 16, 2020
commit 314d8d9cab2d23afa36ac68afb2ee4b62c0698be
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/preferences/dlgpreferencepage.cpp
src/preferences/effectsettingsmodel.cpp
src/preferences/colorpaletteeditor.cpp
src/preferences/colorpaletteeditormodel.cpp
src/preferences/colorpaletteeditortableview.cpp
src/preferences/colorpalettesettings.cpp
src/preferences/replaygainsettings.cpp
Expand Down
1 change: 1 addition & 0 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ def sources(self, build):
"src/preferences/broadcastprofile.cpp",
"src/preferences/upgrade.cpp",
"src/preferences/colorpaletteeditor.cpp",
"src/preferences/colorpaletteeditormodel.cpp",
"src/preferences/colorpaletteeditortableview.cpp",
"src/preferences/colorpalettesettings.cpp",
"src/preferences/dlgpreferencepage.cpp",
Expand Down
6 changes: 3 additions & 3 deletions src/preferences/colorpaletteeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ ColorPaletteEditor::ColorPaletteEditor(QWidget* parent)
foreach (const ColorPalette& palette, mixxx::PredefinedColorPalettes::kPalettes) {
if (text == palette.getName()) {
bPaletteFound = true;
m_pTableView->setColors(palette.getColorList());
m_pTableView->setColorPalette(palette);
break;
}
}
if (!bPaletteFound) {
m_pTableView->setColors(colorPaletteSettings.getColorPalette(text, mixxx::PredefinedColorPalettes::kDefaultHotcueColorPalette).getColorList());
m_pTableView->setColorPalette(colorPaletteSettings.getColorPalette(text, mixxx::PredefinedColorPalettes::kDefaultHotcueColorPalette));
}
}
} else {
Expand All @@ -84,7 +84,7 @@ ColorPaletteEditor::ColorPaletteEditor(QWidget* parent)
[this] {
QString paletteName = m_pPaletteNameComboBox->currentText();
ColorPaletteSettings colorPaletteSettings(m_pConfig);
colorPaletteSettings.setColorPalette(paletteName, ColorPalette(paletteName, m_pTableView->getColors()));
colorPaletteSettings.setColorPalette(paletteName, m_pTableView->getColorPalette(paletteName));
m_pTableView->setDirty(false);
reset();
m_pPaletteNameComboBox->setCurrentText(paletteName);
Expand Down
112 changes: 112 additions & 0 deletions src/preferences/colorpaletteeditormodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include "preferences/colorpaletteeditormodel.h"

namespace {

QIcon toQIcon(const QColor& color) {
QPixmap pixmap(50, 50);
pixmap.fill(color);
return QIcon(pixmap);
}

} // namespace

bool ColorPaletteEditorModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) {
// Always move the entire row, and don't allow column "shifting"
Q_UNUSED(column);
return QStandardItemModel::dropMimeData(data, action, row, 0, parent);
}

bool ColorPaletteEditorModel::setData(const QModelIndex& modelIndex, const QVariant& value, int role) {
if (modelIndex.isValid() && modelIndex.column() == 1) {
bool ok;
int hotcueIndex = value.toInt(&ok);

// Make sure that the value is valid
if (!ok || hotcueIndex <= 0 || hotcueIndex > rowCount()) {
return QStandardItemModel::setData(modelIndex, QVariant(), role);
}

// Make sure there is no other row with the same hotcue index
for (int i = 0; i < rowCount(); i++) {
QModelIndex otherModelIndex = index(i, 1);
QVariant otherValue = data(otherModelIndex);
int otherHotcueIndex = otherValue.toInt(&ok);
if (ok && otherHotcueIndex == hotcueIndex) {
QStandardItemModel::setData(otherModelIndex, QVariant(), role);
}
}
}

return QStandardItemModel::setData(modelIndex, value, role);
}

void ColorPaletteEditorModel::setColor(int row, const QColor& color) {
QStandardItem* pItem = item(row, 0);
if (pItem) {
pItem->setIcon(toQIcon(color));
pItem->setText(color.name());
}
}

void ColorPaletteEditorModel::setHotcueIndex(int row, int hotcueIndex) {
QStandardItem* pItem = item(row, 1);
if (pItem) {
pItem->setText(QString::number(hotcueIndex));
}
}

void ColorPaletteEditorModel::appendRow(const QColor& color, int hotcueIndex) {
QStandardItem* pColorItem = new QStandardItem(toQIcon(color), color.name());
pColorItem->setEditable(false);
pColorItem->setDropEnabled(false);

QString hotcueIndexStr;
if (hotcueIndex >= 0) {
hotcueIndexStr = QString::number(hotcueIndex + 1);
}

QStandardItem* pHotcueIndexItem = new QStandardItem(hotcueIndexStr);
pHotcueIndexItem->setEditable(true);
pHotcueIndexItem->setDropEnabled(false);

QStandardItemModel::appendRow(QList<QStandardItem*>{pColorItem, pHotcueIndexItem});
}

void ColorPaletteEditorModel::setColorPalette(const ColorPalette& palette) {
// Remove all rows
removeRows(0, rowCount());

// Make a map of hotcue indices
QMap<int, int> hotcueColorIndicesMap;
QList<unsigned int> hotcueColorIndices = palette.getHotcueIndices();
for (int i = 0; i < hotcueColorIndices.size(); i++) {
int colorIndex = hotcueColorIndices.at(i);
hotcueColorIndicesMap.insert(colorIndex, i);
}

for (int i = 0; i < palette.size(); i++) {
QColor color = mixxx::RgbColor::toQColor(palette.at(i));
int colorIndex = hotcueColorIndicesMap.value(i, kNoHotcueIndex);
appendRow(color, colorIndex);
}
}

ColorPalette ColorPaletteEditorModel::getColorPalette(const QString& name) const {
QList<mixxx::RgbColor> colors;
QMap<int, unsigned int> hotcueColorIndices;
for (int i = 0; i < rowCount(); i++) {
QStandardItem* pColorItem = item(i, 0);
QStandardItem* pHotcueIndexItem = item(i, 1);
mixxx::RgbColor::optional_t color = mixxx::RgbColor::fromQString(pColorItem->text());
if (color) {
colors << *color;

bool ok;
int hotcueIndex = pHotcueIndexItem->text().toInt(&ok);
if (ok) {
hotcueColorIndices.insert(hotcueIndex - 1, colors.size() - 1);
}
}
}
return ColorPalette(name, colors, hotcueColorIndices.values());
}
27 changes: 27 additions & 0 deletions src/preferences/colorpaletteeditormodel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include <QStandardItemModel>

#include "util/color/colorpalette.h"

class ColorPaletteEditorModel : public QStandardItemModel {
Holzhaus marked this conversation as resolved.
Show resolved Hide resolved
Q_OBJECT
public:
static constexpr int kNoHotcueIndex = -1;

ColorPaletteEditorModel(int rows, int columns, QObject* parent = nullptr)
: QStandardItemModel(rows, columns, parent) {
}
ColorPaletteEditorModel(QObject* parent = nullptr)
: QStandardItemModel(parent) {
}

bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);

void setColor(int row, const QColor& color);
void setHotcueIndex(int row, int hotcueIndex);
void appendRow(const QColor& color, int hotcueIndex = kNoHotcueIndex);

void setColorPalette(const ColorPalette& palette);
ColorPalette getColorPalette(const QString& name) const;
};
57 changes: 15 additions & 42 deletions src/preferences/colorpaletteeditortableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@

namespace {
const QColor kDefaultPaletteColor(0, 0, 0);

QIcon toQIcon(const QColor& color) {
QPixmap pixmap(50, 50);
pixmap.fill(color);
return QIcon(pixmap);
}
} // namespace

ColorPaletteEditorTableView::ColorPaletteEditorTableView(QWidget* parent)
: QTableView(parent),
Expand All @@ -24,9 +18,12 @@ ColorPaletteEditorTableView::ColorPaletteEditorTableView(QWidget* parent)
setDragDropMode(QAbstractItemView::InternalMove);
setDragDropOverwriteMode(false);
setContextMenuPolicy(Qt::CustomContextMenu);
horizontalHeader()->setVisible(false);

// Set our custom model - this prevents row "shifting"
setModel(m_model);
m_model->setColumnCount(2);
m_model->setHeaderData(0, Qt::Horizontal, tr("Color"), Qt::DisplayRole);
m_model->setHeaderData(1, Qt::Horizontal, tr("Assign to Hotcue"), Qt::DisplayRole);

connect(m_model,
&ColorPaletteEditorModel::rowsMoved,
Expand All @@ -46,14 +43,13 @@ ColorPaletteEditorTableView::ColorPaletteEditorTableView(QWidget* parent)
connect(this,
&ColorPaletteEditorTableView::doubleClicked,
[this](const QModelIndex& index) {
QStandardItem* item = m_model->itemFromIndex(index);
if (!item) {
return;
if (index.isValid() && index.column() == 0) {
QColor color = QColorDialog::getColor();
if (color.isValid()) {
m_model->setColor(index.row(), color);
setDirty(true);
}
}
QColor color = QColorDialog::getColor();
item->setIcon(toQIcon(color));
item->setText(color.name());
setDirty(true);
});
connect(this, &ColorPaletteEditorTableView::customContextMenuRequested, [this](const QPoint& pos) {
QMenu menu(this);
Expand All @@ -62,11 +58,7 @@ ColorPaletteEditorTableView::ColorPaletteEditorTableView(QWidget* parent)
QAction* pRemoveAction = menu.addAction("Remove");
QAction* pAction = menu.exec(viewport()->mapToGlobal(pos));
if (pAction == pAddAction) {
QStandardItem* item = new QStandardItem(
toQIcon(kDefaultPaletteColor), kDefaultPaletteColor.name());
item->setEditable(false);
item->setDropEnabled(false);
m_model->appendRow(item);
m_model->appendRow(kDefaultPaletteColor);
} else if (pAction == pRemoveAction) {
QModelIndexList selection = selectionModel()->selectedRows();

Expand All @@ -80,30 +72,11 @@ ColorPaletteEditorTableView::ColorPaletteEditorTableView(QWidget* parent)
}
});
}

void ColorPaletteEditorTableView::setColors(const QList<mixxx::RgbColor>& colors) {
m_model->clear();
foreach (const mixxx::RgbColor rgbColor, colors) {
QColor color = mixxx::RgbColor::toQColor(rgbColor);
QIcon icon = toQIcon(color);
QString colorName = color.name();

QStandardItem* item = new QStandardItem(icon, colorName);
item->setEditable(false);
item->setDropEnabled(false);
m_model->appendRow(item);
}
void ColorPaletteEditorTableView::setColorPalette(const ColorPalette& palette) {
m_model->setColorPalette(palette);
setDirty(false);
}

QList<mixxx::RgbColor> ColorPaletteEditorTableView::getColors() const {
QList<mixxx::RgbColor> colors;
for (int i = 0; i < m_model->rowCount(); i++) {
QStandardItem* item = m_model->item(i, 0);
mixxx::RgbColor::optional_t color = mixxx::RgbColor::fromQString(item->text());
if (color) {
colors << *color;
}
}
return colors;
ColorPalette ColorPaletteEditorTableView::getColorPalette(const QString& name) const {
return m_model->getColorPalette(name);
}
25 changes: 4 additions & 21 deletions src/preferences/colorpaletteeditortableview.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
#pragma once
#include <QStandardItemModel>
#include <QTableView>

#include "util/color/rgbcolor.h"

class ColorPaletteEditorModel : public QStandardItemModel {
Q_OBJECT
public:
ColorPaletteEditorModel(int rows, int columns, QObject* parent = nullptr)
: QStandardItemModel(rows, columns, parent) {
}
ColorPaletteEditorModel(QObject* parent = nullptr)
: QStandardItemModel(parent) {
}

bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override {
// Always move the entire row, and don't allow column "shifting"
Q_UNUSED(column);
return QStandardItemModel::dropMimeData(data, action, row, 0, parent);
}
};
#include "preferences/colorpaletteeditormodel.h"
#include "util/color/colorpalette.h"

class ColorPaletteEditorTableView : public QTableView {
Q_OBJECT
Expand All @@ -42,8 +25,8 @@ class ColorPaletteEditorTableView : public QTableView {
return m_bDirty;
}

QList<mixxx::RgbColor> getColors() const;
void setColors(const QList<mixxx::RgbColor>& colors);
ColorPalette getColorPalette(const QString& name) const;
void setColorPalette(const ColorPalette& palette);

signals:
void dirtyChanged(bool bDirty);
Expand Down