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

Color preferences improvements #2589

Merged
merged 47 commits into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a653006
Improve strings in the color preferences pane
daschuer Mar 22, 2020
29158a5
Allow to translate "Name" in the ColorPaletteEditor
daschuer Mar 22, 2020
7e1be9e
Move button row below the palette and optimize column widths
daschuer Mar 22, 2020
30aaea8
Fill table with assigned cue numbers if no cue numbers are set
daschuer Mar 22, 2020
3b66047
Introduce Compbobox for selecting the hotcue default color
daschuer Mar 24, 2020
d990c5e
Respect new hotcue default settings
daschuer Mar 24, 2020
c53f7c1
Added a preview stripe for the selected palette.
daschuer Mar 24, 2020
b4d3fa5
Fix default default hotcue selection
daschuer Mar 24, 2020
04ed468
Revert "Fill table with assigned cue numbers if no cue numbers are set"
daschuer Mar 24, 2020
a171d13
Improve the labels of the colors in the combobox
daschuer Mar 24, 2020
68742d9
introduce getHotcueColorPalette(const QString&) and make use of it.
daschuer Mar 24, 2020
f9714bb
Added Icons to the palette select boxes
daschuer Mar 24, 2020
539d4da
Limit auto color asignment to 8
daschuer Mar 24, 2020
7b15170
DlgPrefColors: use full palette preview for icons in comboboxes
Be-ing Mar 25, 2020
5d4321f
limit default hotcue palette to 8 colors
Be-ing Mar 25, 2020
75b3af5
Merge remote-tracking branch 'upstream/master' into color_preferences
daschuer Mar 26, 2020
edc4af6
Rename Intro Palette to Track Metadata und remove it from the user av…
daschuer Mar 26, 2020
3ab4f63
Inital hide the palette editor
daschuer Mar 26, 2020
5cb7e2f
Split Save as and Template Combobox
daschuer Mar 26, 2020
326008d
Merge remote-tracking branch 'upstream/pr/2589' into color_preferences
Be-ing Mar 27, 2020
b267a44
DlgPrefColors: remove unused slotTrackPaletteChanged
Be-ing Mar 27, 2020
4176013
DlgPrefColors: fix black edge of palette preview pixmaps
Be-ing Mar 27, 2020
9c5cd43
Merge pull request #50 from Be-ing/color_preferences
daschuer Mar 27, 2020
fa3cac9
Use small edit button with elipsis
daschuer Mar 27, 2020
089fc08
Remove superfluid parenthes
daschuer Mar 27, 2020
61ecb24
Added message box when closing Palette Editor wit unsaved changes
daschuer Mar 27, 2020
37a57b7
Keep temoraray selections when updateding custom paletts
daschuer Mar 27, 2020
3d68315
Keep temorary selected default color after chanigng palette
daschuer Mar 27, 2020
73ee264
Improve gray out state of save and reset button
daschuer Mar 27, 2020
8e95102
Improve naming and use int as index like Qt
daschuer Mar 28, 2020
5f601ce
Made the Palette editor a context depending pop up box for the palett…
daschuer Mar 29, 2020
e9c2d34
Seti inital color for QColorDialog
daschuer Mar 29, 2020
74b47c3
Don't translate parentheses
daschuer Mar 29, 2020
441b069
Adjust default index when it is out set the new palette selected
daschuer Mar 29, 2020
f1a7c73
fix typo
daschuer Mar 29, 2020
989d335
ColorPaletteEditor: move Add/Remove Color to buttons
Be-ing Mar 30, 2020
2a8f635
ColorPaletteEditor: hide hotcue number column for track palette
Be-ing Mar 30, 2020
d5e217a
Merge pull request #51 from Be-ing/color_preferences
daschuer Mar 30, 2020
61f5a71
Resort the palette editor buttons. Replace "Save" with "OK"
daschuer Mar 30, 2020
f189fee
Shrink add and remove button to + and - and move it below the table.
daschuer Mar 30, 2020
4030280
Improve selection behaviour during palette edit
daschuer Mar 30, 2020
4b3f9b4
Added a warning dialog when removing the palette.
daschuer Mar 30, 2020
a82bf80
Remove commented code
daschuer Mar 31, 2020
cfce951
Swap "+" and "-" button
daschuer Mar 31, 2020
f29e3b8
Added some comments
daschuer Mar 31, 2020
3126268
Merge pull request #52 from Be-ing/color_preferences_hide_hotcue_number
daschuer Apr 2, 2020
9db6ad2
Use the real hotcue colors when coloring the icon
daschuer Apr 2, 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
12 changes: 8 additions & 4 deletions src/engine/controls/cuecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,16 @@ void CueControl::hotcueSet(HotcueControl* pControl, double v) {
pCue->setLabel();
pCue->setType(mixxx::CueType::HotCue);

ConfigKey autoHotcueColorsKey("[Controls]", "auto_hotcue_colors");
if (getConfig()->getValue(autoHotcueColorsKey, false)) {
auto hotcueColorPalette = m_colorPaletteSettings.getHotcueColorPalette();
const ColorPalette hotcueColorPalette =
m_colorPaletteSettings.getHotcueColorPalette();
if (getConfig()->getValue(ConfigKey("[Controls]", "auto_hotcue_colors"), false)) {
pCue->setColor(hotcueColorPalette.colorForHotcueIndex(hotcue));
} else {
pCue->setColor(mixxx::PredefinedColorPalettes::kDefaultCueColor);
int hotcueDefaultColorIndex = m_pConfig->getValue(ConfigKey("[Controls]", "HotcueDefaultColorIndex"), -1);
if (hotcueDefaultColorIndex < 0 || hotcueDefaultColorIndex >= hotcueColorPalette.size()) {
hotcueDefaultColorIndex = hotcueColorPalette.size() - 1; // default to last color (orange)
}
pCue->setColor(hotcueColorPalette.at(hotcueDefaultColorIndex));
}

// TODO(XXX) deal with spurious signals
Expand Down
179 changes: 102 additions & 77 deletions src/preferences/colorpaletteeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QHeaderView>
#include <QLabel>
#include <QMenu>
#include <QMessageBox>
#include <QStandardItemModel>
#include <QTableView>

Expand All @@ -17,34 +18,53 @@ const QColor kDefaultPaletteColor(0, 0, 0);
}

ColorPaletteEditor::ColorPaletteEditor(QWidget* parent)
: QWidget(parent),
: QDialog(parent),
m_bPaletteExists(false),
m_bPaletteIsReadOnly(false),
m_pPaletteNameComboBox(make_parented<QComboBox>()),
m_pTableView(make_parented<QTableView>()),
m_pSaveAsEdit(make_parented<QLineEdit>(this)),
m_pTableView(make_parented<QTableView>(this)),
m_pModel(make_parented<ColorPaletteEditorModel>(m_pTableView)) {
m_pPaletteNameComboBox->setEditable(true);
// Create widgets
QHBoxLayout* pColorButtonLayout = new QHBoxLayout();
m_pAddColorButton = new QPushButton(tr("Add Color"), this);
pColorButtonLayout->addWidget(m_pAddColorButton);
connect(m_pAddColorButton,
&QPushButton::clicked,
this,
&ColorPaletteEditor::slotAddColor);
m_pRemoveColorButton = new QPushButton(tr("Remove Color"), this);
pColorButtonLayout->addWidget(m_pRemoveColorButton);
connect(m_pRemoveColorButton,
&QPushButton::clicked,
this,
&ColorPaletteEditor::slotRemoveColor);

QDialogButtonBox* pButtonBox = new QDialogButtonBox();
m_pSaveButton = pButtonBox->addButton(QDialogButtonBox::Save);
m_pResetButton = pButtonBox->addButton(QDialogButtonBox::Reset);
m_pDiscardButton = pButtonBox->addButton(QDialogButtonBox::Discard);
QHBoxLayout* pNameLayout = new QHBoxLayout();
pNameLayout->addWidget(new QLabel(tr("Name")));
pNameLayout->addWidget(m_pSaveAsEdit, 1);

QHBoxLayout* pTopLayout = new QHBoxLayout();
pTopLayout->addWidget(new QLabel("Name:"));
pTopLayout->addWidget(m_pPaletteNameComboBox, 1);
pTopLayout->addWidget(pButtonBox);
QDialogButtonBox* pPaletteButtonBox = new QDialogButtonBox();
m_pRemoveButton = pPaletteButtonBox->addButton(
tr("Remove Palette"),
QDialogButtonBox::DestructiveRole);
m_pCloseButton = pPaletteButtonBox->addButton(QDialogButtonBox::Discard);
m_pResetButton = pPaletteButtonBox->addButton(QDialogButtonBox::Reset);
m_pSaveButton = pPaletteButtonBox->addButton(QDialogButtonBox::Save);

// Add widgets to dialog
QVBoxLayout* pLayout = new QVBoxLayout();
pLayout->addLayout(pTopLayout);
pLayout->addLayout(pColorButtonLayout);
pLayout->addWidget(m_pTableView, 1);
pLayout->addLayout(pNameLayout);
pLayout->addWidget(pPaletteButtonBox);
setLayout(pLayout);
setContentsMargins(0, 0, 0, 0);

// Set up model
m_pModel->setColumnCount(2);
m_pModel->setColumnCount(3);
m_pModel->setHeaderData(0, Qt::Horizontal, tr("Color"), Qt::DisplayRole);
m_pModel->setHeaderData(1, Qt::Horizontal, tr("Assign to Hotcue"), Qt::DisplayRole);
m_pModel->setHeaderData(1, Qt::Horizontal, tr("Assign to Hotcue Number"), Qt::DisplayRole);
m_pModel->setHeaderData(2, Qt::Horizontal, QString(), Qt::DisplayRole);
connect(m_pModel,
&ColorPaletteEditorModel::dirtyChanged,
this,
Expand All @@ -63,85 +83,95 @@ ColorPaletteEditor::ColorPaletteEditor(QWidget* parent)
m_pTableView->setContextMenuPolicy(Qt::CustomContextMenu);
m_pTableView->setModel(m_pModel);

m_pTableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
m_pTableView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
m_pTableView->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);

connect(m_pTableView,
&QTableView::doubleClicked,
this,
&ColorPaletteEditor::slotTableViewDoubleClicked);
connect(m_pTableView,
&QTableView::customContextMenuRequested,
this,
&ColorPaletteEditor::slotTableViewContextMenuRequested);
connect(m_pPaletteNameComboBox,
&QComboBox::editTextChanged,
connect(m_pSaveAsEdit,
&QLineEdit::textChanged,
this,
&ColorPaletteEditor::slotPaletteNameChanged);
connect(m_pResetButton,
&QPushButton::clicked,
this,
&ColorPaletteEditor::slotResetButtonClicked);
connect(m_pDiscardButton,
connect(m_pCloseButton,
&QPushButton::clicked,
this,
&ColorPaletteEditor::slotDiscardButtonClicked);
&ColorPaletteEditor::slotCloseButtonClicked);
connect(m_pSaveButton,
&QPushButton::clicked,
this,
&ColorPaletteEditor::slotSaveButtonClicked);
connect(m_pRemoveButton,
&QPushButton::clicked,
this,
&ColorPaletteEditor::slotRemoveButtonClicked);
}

void ColorPaletteEditor::initialize(UserSettingsPointer pConfig) {
void ColorPaletteEditor::initialize(
UserSettingsPointer pConfig,
const QString& paletteName) {
DEBUG_ASSERT(!m_pConfig);
m_pConfig = pConfig;
reset();
}
m_resetPalette = paletteName;
QString saveName = paletteName;

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);
if (paletteName == palette.getName()) {
saveName = paletteName + QStringLiteral(" (") + tr("Edited") + QChar(')');
ColorPaletteSettings colorPaletteSettings(m_pConfig);
if (colorPaletteSettings.getColorPaletteNames().contains(saveName)) {
m_resetPalette = saveName;
}
break;
}
}

m_pSaveAsEdit->setText(saveName);

slotResetButtonClicked();
}

void ColorPaletteEditor::slotUpdateButtons() {
bool bDirty = m_pModel->isDirty();
bool bEmpty = m_pModel->isEmpty();
m_pSaveButton->setEnabled(
!m_pSaveAsEdit->text().trimmed().isEmpty() &&
(!m_bPaletteExists || (!m_bPaletteIsReadOnly && bDirty && !bEmpty)));
m_pRemoveButton->setEnabled(
m_bPaletteExists &&
!m_bPaletteIsReadOnly);
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);
QStandardItem* pColorItem = m_pModel->item(index.row(), 0);
QColor oldColor = QColor(pColorItem->text());
QColor newColor = QColorDialog::getColor(oldColor);
if (newColor.isValid() && oldColor != newColor) {
m_pModel->setColor(index.row(), newColor);
}
}
}

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();
void ColorPaletteEditor::slotAddColor() {
m_pModel->appendRow(kDefaultPaletteColor);
}

if (selection.count() > 0) {
QModelIndex index = selection.at(0);
void ColorPaletteEditor::slotRemoveColor() {
QModelIndexList selection = m_pTableView->selectionModel()->selectedRows();

//row selected
int row = index.row();
m_pModel->removeRow(row);
}
if (selection.count() > 0) {
QModelIndex index = selection.at(0);
//row selected
int row = index.row();
m_pModel->removeRow(row);
}
}

Expand Down Expand Up @@ -172,49 +202,44 @@ void ColorPaletteEditor::slotPaletteNameChanged(const QString& text) {
}
}
if (!bPaletteFound) {
m_pModel->setColorPalette(colorPaletteSettings.getColorPalette(text, mixxx::PredefinedColorPalettes::kDefaultHotcueColorPalette));
m_pModel->setColorPalette(colorPaletteSettings.getColorPalette(
text, mixxx::PredefinedColorPalettes::kDefaultHotcueColorPalette));
}
}
}

m_bPaletteExists = bPaletteExists;
m_bPaletteIsReadOnly = bPaletteIsReadOnly;

slotUpdateButtons();
}

void ColorPaletteEditor::slotDiscardButtonClicked() {
QString paletteName = m_pPaletteNameComboBox->currentText();
void ColorPaletteEditor::slotCloseButtonClicked() {
reject();
}

void ColorPaletteEditor::slotRemoveButtonClicked() {
QString paletteName = m_pSaveAsEdit->text().trimmed();
ColorPaletteSettings colorPaletteSettings(m_pConfig);
colorPaletteSettings.removePalette(paletteName);
reset();
emit paletteRemoved(paletteName);
accept();
}

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

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);
}
ColorPalette palette = colorPaletteSettings.getColorPalette(
m_resetPalette,
mixxx::PredefinedColorPalettes::kDefaultHotcueColorPalette);
m_pModel->setColorPalette(palette);
slotUpdateButtons();
}
29 changes: 17 additions & 12 deletions src/preferences/colorpaletteeditor.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@
#pragma once

#include <QComboBox>
#include <QDialog>
#include <QLineEdit>
#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.
daschuer marked this conversation as resolved.
Show resolved Hide resolved
class ColorPaletteEditor : public QWidget {
class ColorPaletteEditor : public QDialog {
Q_OBJECT
public:
ColorPaletteEditor(QWidget* parent = nullptr);
void initialize(UserSettingsPointer pConfig);
void reset();
void initialize(UserSettingsPointer pConfig, const QString& paletteName);

signals:
void paletteChanged(QString name);
void paletteRemoved(QString name);
void paletteChanged(const QString& name);
void paletteRemoved(const QString& name);
void closeButtonClicked();

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

private:
bool m_bPaletteExists;
bool m_bPaletteIsReadOnly;

UserSettingsPointer m_pConfig;
parented_ptr<QComboBox> m_pPaletteNameComboBox;
parented_ptr<QLineEdit> m_pSaveAsEdit;
parented_ptr<QTableView> m_pTableView;
parented_ptr<ColorPaletteEditorModel> m_pModel;
QPushButton* m_pAddColorButton;
QPushButton* m_pRemoveColorButton;
QPushButton* m_pSaveButton;
QPushButton* m_pDiscardButton;
QPushButton* m_pCloseButton;
QPushButton* m_pRemoveButton;
QPushButton* m_pResetButton;
QString m_resetPalette;
};
10 changes: 6 additions & 4 deletions src/preferences/colorpaletteeditormodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ void ColorPaletteEditorModel::setColorPalette(const ColorPalette& palette) {

// 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);
QList<int> colorIndicesByHotcue = palette.getIndicesByHotcue();
for (int i = 0; i < colorIndicesByHotcue.size(); i++) {
int colorIndex = colorIndicesByHotcue.at(i);
hotcueColorIndicesMap.insert(colorIndex, i);
}

Be-ing marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -119,7 +119,7 @@ void ColorPaletteEditorModel::setColorPalette(const ColorPalette& palette) {

ColorPalette ColorPaletteEditorModel::getColorPalette(const QString& name) const {
QList<mixxx::RgbColor> colors;
QMap<int, unsigned int> hotcueColorIndices;
QMap<int, int> hotcueColorIndices;
for (int i = 0; i < rowCount(); i++) {
QStandardItem* pColorItem = item(i, 0);
QStandardItem* pHotcueIndexItem = item(i, 1);
Expand All @@ -134,5 +134,7 @@ ColorPalette ColorPaletteEditorModel::getColorPalette(const QString& name) const
}
}
}
// If we have a non consequitive list of hotcue indexes, indexes are shifted down
// due to the sorting nature of QMap. This is intended, this way we have a color for every hotcue.
return ColorPalette(name, colors, hotcueColorIndices.values());
}
Loading