Skip to content

Commit

Permalink
Merge pull request #2530 from Holzhaus/hotcue-rgb-color-picker
Browse files Browse the repository at this point in the history
Make Hotcue RGB colors configurable
  • Loading branch information
uklotzde authored Mar 20, 2020
2 parents 7f6fd5a + a3b356a commit a189892
Show file tree
Hide file tree
Showing 25 changed files with 1,166 additions and 171 deletions.
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

0 comments on commit a189892

Please sign in to comment.