-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2530 from Holzhaus/hotcue-rgb-color-picker
Make Hotcue RGB colors configurable
- Loading branch information
Showing
25 changed files
with
1,166 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
Oops, something went wrong.