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 all commits
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
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/preferences/dialog/dlgprefautodjdlg.ui
src/preferences/dialog/dlgprefbeats.cpp
src/preferences/dialog/dlgprefbeatsdlg.ui
src/preferences/dialog/dlgprefcolors.cpp
src/preferences/dialog/dlgprefcolorsdlg.ui
src/preferences/dialog/dlgprefcrossfader.cpp
src/preferences/dialog/dlgprefcrossfaderdlg.ui
src/preferences/dialog/dlgprefdeck.cpp
Expand Down Expand Up @@ -498,6 +500,8 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/preferences/dialog/dlgprefwaveformdlg.ui
src/preferences/dlgpreferencepage.cpp
src/preferences/effectsettingsmodel.cpp
src/preferences/colorpaletteeditor.cpp
src/preferences/colorpaletteeditormodel.cpp
src/preferences/colorpalettesettings.cpp
src/preferences/replaygainsettings.cpp
src/preferences/settingsmanager.cpp
Expand Down Expand Up @@ -562,6 +566,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/util/cmdlineargs.cpp
src/util/color/color.cpp
src/util/color/colorpalette.cpp
src/util/color/predefinedcolorpalettes.cpp
src/util/console.cpp
src/util/db/dbconnection.cpp
src/util/db/dbconnectionpool.cpp
Expand Down
5 changes: 5 additions & 0 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ def sources(self, build):
"src/preferences/configobject.cpp",
"src/preferences/dialog/dlgprefautodj.cpp",
"src/preferences/dialog/dlgprefdeck.cpp",
"src/preferences/dialog/dlgprefcolors.cpp",
"src/preferences/dialog/dlgprefcrossfader.cpp",
"src/preferences/dialog/dlgprefeffects.cpp",
"src/preferences/dialog/dlgprefeq.cpp",
Expand All @@ -790,6 +791,8 @@ def sources(self, build):
"src/preferences/effectsettingsmodel.cpp",
"src/preferences/broadcastprofile.cpp",
"src/preferences/upgrade.cpp",
"src/preferences/colorpaletteeditor.cpp",
"src/preferences/colorpaletteeditormodel.cpp",
"src/preferences/colorpalettesettings.cpp",
"src/preferences/dlgpreferencepage.cpp",

Expand Down Expand Up @@ -1286,6 +1289,7 @@ def sources(self, build):
"src/util/console.cpp",
"src/util/color/color.cpp",
"src/util/color/colorpalette.cpp",
"src/util/color/predefinedcolorpalettes.cpp",
"src/util/db/dbconnection.cpp",
"src/util/db/dbconnectionpool.cpp",
"src/util/db/dbconnectionpooler.cpp",
Expand Down Expand Up @@ -1347,6 +1351,7 @@ def sources(self, build):
'src/preferences/dialog/dlgprefautodjdlg.ui',
'src/preferences/dialog/dlgprefbeatsdlg.ui',
'src/preferences/dialog/dlgprefdeckdlg.ui',
'src/preferences/dialog/dlgprefcolorsdlg.ui',
'src/preferences/dialog/dlgprefcrossfaderdlg.ui',
'src/preferences/dialog/dlgpreflv2dlg.ui',
'src/preferences/dialog/dlgprefeffectsdlg.ui',
Expand Down
7 changes: 7 additions & 0 deletions res/images/preferences/ic_preferences_colors.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions res/mixxx.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<file>images/preferences/ic_preferences_autodj.svg</file>
<file>images/preferences/ic_preferences_bpmdetect.svg</file>
<file>images/preferences/ic_preferences_broadcast.svg</file>
<file>images/preferences/ic_preferences_colors.svg</file>
<file>images/preferences/ic_preferences_controllers.svg</file>
<file>images/preferences/ic_preferences_crossfader.svg</file>
<file>images/preferences/ic_preferences_decks.svg</file>
Expand Down
3 changes: 2 additions & 1 deletion src/engine/controls/cuecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "engine/enginebuffer.h"
#include "preferences/colorpalettesettings.h"
#include "util/color/color.h"
#include "util/color/predefinedcolorpalettes.h"
#include "util/sample.h"
#include "vinylcontrol/defs_vinylcontrol.h"

Expand Down Expand Up @@ -622,7 +623,7 @@ void CueControl::hotcueSet(HotcueControl* pControl, double v) {
auto hotcueColorPalette = m_colorPaletteSettings.getHotcueColorPalette();
pCue->setColor(hotcueColorPalette.colorForHotcueIndex(hotcue));
} else {
pCue->setColor(ColorPalette::kDefaultCueColor);
pCue->setColor(mixxx::PredefinedColorPalettes::kDefaultCueColor);
}

// TODO(XXX) deal with spurious signals
Expand Down
216 changes: 216 additions & 0 deletions src/preferences/colorpaletteeditor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
#include "preferences/colorpaletteeditor.h"

#include <QColorDialog>
#include <QDialogButtonBox>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QMenu>
#include <QStandardItemModel>
#include <QTableView>

#include "preferences/colorpalettesettings.h"
#include "util/color/predefinedcolorpalettes.h"

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

ColorPaletteEditor::ColorPaletteEditor(QWidget* parent)
: QWidget(parent),
m_bPaletteExists(false),
m_bPaletteIsReadOnly(false),
m_pPaletteNameComboBox(make_parented<QComboBox>()),
m_pTableView(make_parented<QTableView>()),
m_pModel(make_parented<ColorPaletteEditorModel>(m_pTableView)) {
m_pPaletteNameComboBox->setEditable(true);

QDialogButtonBox* pButtonBox = new QDialogButtonBox();
m_pSaveButton = pButtonBox->addButton(QDialogButtonBox::Save);
m_pResetButton = pButtonBox->addButton(QDialogButtonBox::Reset);
m_pDiscardButton = pButtonBox->addButton(QDialogButtonBox::Discard);

QHBoxLayout* pTopLayout = new QHBoxLayout();
pTopLayout->addWidget(new QLabel("Name:"));
pTopLayout->addWidget(m_pPaletteNameComboBox, 1);
pTopLayout->addWidget(pButtonBox);

QVBoxLayout* pLayout = new QVBoxLayout();
pLayout->addLayout(pTopLayout);
pLayout->addWidget(m_pTableView, 1);
setLayout(pLayout);
setContentsMargins(0, 0, 0, 0);

// Set up model
m_pModel->setColumnCount(2);
m_pModel->setHeaderData(0, Qt::Horizontal, tr("Color"), Qt::DisplayRole);
m_pModel->setHeaderData(1, Qt::Horizontal, tr("Assign to Hotcue"), Qt::DisplayRole);
connect(m_pModel,
&ColorPaletteEditorModel::dirtyChanged,
this,
&ColorPaletteEditor::slotUpdateButtons);
connect(m_pModel,
&ColorPaletteEditorModel::emptyChanged,
this,
&ColorPaletteEditor::slotUpdateButtons);

// Setup up table view
m_pTableView->setShowGrid(false);
m_pTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
m_pTableView->setSelectionMode(QAbstractItemView::SingleSelection);
m_pTableView->setDragDropMode(QAbstractItemView::InternalMove);
m_pTableView->setDragDropOverwriteMode(false);
m_pTableView->setContextMenuPolicy(Qt::CustomContextMenu);
m_pTableView->setModel(m_pModel);

connect(m_pTableView,
&QTableView::doubleClicked,
this,
&ColorPaletteEditor::slotTableViewDoubleClicked);
connect(m_pTableView,
&QTableView::customContextMenuRequested,
this,
&ColorPaletteEditor::slotTableViewContextMenuRequested);
connect(m_pPaletteNameComboBox,
&QComboBox::editTextChanged,
this,
&ColorPaletteEditor::slotPaletteNameChanged);
connect(m_pDiscardButton,
&QPushButton::clicked,
this,
&ColorPaletteEditor::slotDiscardButtonClicked);
connect(m_pSaveButton,
&QPushButton::clicked,
this,
&ColorPaletteEditor::slotSaveButtonClicked);
}

void ColorPaletteEditor::initialize(UserSettingsPointer pConfig) {
DEBUG_ASSERT(!m_pConfig);
m_pConfig = pConfig;
reset();
}

void ColorPaletteEditor::reset() {
m_pPaletteNameComboBox->clear();
for (const ColorPalette& palette : mixxx::PredefinedColorPalettes::kPalettes) {
m_pPaletteNameComboBox->addItem(palette.getName());
}
m_pPaletteNameComboBox->insertSeparator(mixxx::PredefinedColorPalettes::kPalettes.size());
ColorPaletteSettings colorPaletteSettings(m_pConfig);
for (const QString& paletteName : colorPaletteSettings.getColorPaletteNames()) {
m_pPaletteNameComboBox->addItem(paletteName);
}
}

void ColorPaletteEditor::slotUpdateButtons() {
bool bDirty = m_pModel->isDirty();
bool bEmpty = m_pModel->isEmpty();
m_pResetButton->setEnabled(bDirty);
m_pSaveButton->setEnabled(!m_bPaletteExists || (!m_bPaletteIsReadOnly && bDirty && !bEmpty));
m_pDiscardButton->setEnabled(m_bPaletteExists && !m_bPaletteIsReadOnly);
}

void ColorPaletteEditor::slotTableViewDoubleClicked(const QModelIndex& index) {
if (index.isValid() && index.column() == 0) {
QColor color = QColorDialog::getColor();
if (color.isValid()) {
m_pModel->setColor(index.row(), color);
}
}
}

void ColorPaletteEditor::slotTableViewContextMenuRequested(const QPoint& pos) {
QMenu menu(this);

QAction* pAddAction = menu.addAction("Add");
QAction* pRemoveAction = menu.addAction("Remove");
QAction* pAction = menu.exec(m_pTableView->viewport()->mapToGlobal(pos));
if (pAction == pAddAction) {
m_pModel->appendRow(kDefaultPaletteColor);
} else if (pAction == pRemoveAction) {
QModelIndexList selection = m_pTableView->selectionModel()->selectedRows();

if (selection.count() > 0) {
QModelIndex index = selection.at(0);

//row selected
int row = index.row();
m_pModel->removeRow(row);
}
}
}

void ColorPaletteEditor::slotPaletteNameChanged(const QString& text) {
bool bPaletteIsReadOnly = false;
bool bPaletteExists = false;
for (const ColorPalette& palette : mixxx::PredefinedColorPalettes::kPalettes) {
if (text == palette.getName()) {
bPaletteExists = true;
bPaletteIsReadOnly = true;
break;
}
}

ColorPaletteSettings colorPaletteSettings(m_pConfig);
if (!bPaletteIsReadOnly) {
bPaletteExists = colorPaletteSettings.getColorPaletteNames().contains(text);
}

if (bPaletteExists) {
if (!m_pModel->isDirty()) {
bool bPaletteFound = false;
for (const ColorPalette& palette : mixxx::PredefinedColorPalettes::kPalettes) {
if (text == palette.getName()) {
bPaletteFound = true;
m_pModel->setColorPalette(palette);
break;
}
}
if (!bPaletteFound) {
m_pModel->setColorPalette(colorPaletteSettings.getColorPalette(text, mixxx::PredefinedColorPalettes::kDefaultHotcueColorPalette));
}
}
}

m_bPaletteExists = bPaletteExists;
m_bPaletteIsReadOnly = bPaletteIsReadOnly;
slotUpdateButtons();
}

void ColorPaletteEditor::slotDiscardButtonClicked() {
QString paletteName = m_pPaletteNameComboBox->currentText();
ColorPaletteSettings colorPaletteSettings(m_pConfig);
colorPaletteSettings.removePalette(paletteName);
reset();
emit paletteRemoved(paletteName);
}

void ColorPaletteEditor::slotSaveButtonClicked() {
QString paletteName = m_pPaletteNameComboBox->currentText();
ColorPaletteSettings colorPaletteSettings(m_pConfig);
colorPaletteSettings.setColorPalette(paletteName, m_pModel->getColorPalette(paletteName));
m_pModel->setDirty(false);
reset();
m_pPaletteNameComboBox->setCurrentText(paletteName);
emit paletteChanged(paletteName);
}

void ColorPaletteEditor::slotResetButtonClicked() {
QString paletteName = m_pPaletteNameComboBox->currentText();
ColorPaletteSettings colorPaletteSettings(m_pConfig);
bool bPaletteExists = colorPaletteSettings.getColorPaletteNames().contains(paletteName);
if (!bPaletteExists) {
for (const ColorPalette& palette : mixxx::PredefinedColorPalettes::kPalettes) {
if (paletteName == palette.getName()) {
bPaletteExists = true;
break;
}
}
}
m_pModel->setDirty(false);
reset();
if (bPaletteExists) {
m_pPaletteNameComboBox->setCurrentText(paletteName);
}
}
45 changes: 45 additions & 0 deletions src/preferences/colorpaletteeditor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <QComboBox>
#include <QPushButton>
#include <QTableView>
#include <QWidget>

#include "preferences/colorpaletteeditormodel.h"
#include "preferences/usersettings.h"
#include "util/parented_ptr.h"

// Widget for viewing, adding, editing and removing color palettes that can be
// used for track/hotcue colors.
class ColorPaletteEditor : public QWidget {
Q_OBJECT
public:
ColorPaletteEditor(QWidget* parent = nullptr);
void initialize(UserSettingsPointer pConfig);
void reset();

signals:
void paletteChanged(QString name);
void paletteRemoved(QString name);

private slots:
void slotUpdateButtons();
void slotTableViewDoubleClicked(const QModelIndex& index);
void slotTableViewContextMenuRequested(const QPoint& pos);
void slotPaletteNameChanged(const QString& text);
void slotDiscardButtonClicked();
void slotSaveButtonClicked();
void slotResetButtonClicked();

private:
bool m_bPaletteExists;
bool m_bPaletteIsReadOnly;

UserSettingsPointer m_pConfig;
parented_ptr<QComboBox> m_pPaletteNameComboBox;
parented_ptr<QTableView> m_pTableView;
parented_ptr<ColorPaletteEditorModel> m_pModel;
QPushButton* m_pSaveButton;
QPushButton* m_pDiscardButton;
QPushButton* m_pResetButton;
};
Loading