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 44 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
220 changes: 140 additions & 80 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,64 @@ 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();
QWidget* pExpander = new QWidget(this);
pExpander->setSizePolicy(
QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
pColorButtonLayout->addWidget(pExpander);

QDialogButtonBox* pButtonBox = new QDialogButtonBox();
m_pSaveButton = pButtonBox->addButton(QDialogButtonBox::Save);
m_pResetButton = pButtonBox->addButton(QDialogButtonBox::Reset);
m_pDiscardButton = pButtonBox->addButton(QDialogButtonBox::Discard);
m_pRemoveColorButton = new QPushButton("-", this);
m_pRemoveColorButton->setFixedWidth(32);
m_pRemoveColorButton->setToolTip(tr("Remove Color"));
m_pRemoveColorButton->setDisabled(true);
pColorButtonLayout->addWidget(m_pRemoveColorButton);
connect(m_pRemoveColorButton,
&QPushButton::clicked,
this,
&ColorPaletteEditor::slotRemoveColor);

m_pAddColorButton = new QPushButton("+", this);
m_pAddColorButton->setFixedWidth(32);
m_pAddColorButton->setToolTip(tr("Add Color"));
pColorButtonLayout->addWidget(m_pAddColorButton);
connect(m_pAddColorButton,
&QPushButton::clicked,
this,
&ColorPaletteEditor::slotAddColor);

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

QDialogButtonBox* pPaletteButtonBox = new QDialogButtonBox();
m_pResetButton = pPaletteButtonBox->addButton(QDialogButtonBox::Reset);
m_pRemoveButton = pPaletteButtonBox->addButton(
tr("Remove Palette"),
QDialogButtonBox::ResetRole);
m_pCloseButton = pPaletteButtonBox->addButton(QDialogButtonBox::Discard);
m_pSaveButton = pPaletteButtonBox->addButton(QDialogButtonBox::Ok);

// Add widgets to dialog
QVBoxLayout* pLayout = new QVBoxLayout();
pLayout->addLayout(pTopLayout);
pLayout->addWidget(m_pTableView, 1);
pLayout->addLayout(pColorButtonLayout);
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,86 +94,103 @@ 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,
connect(m_pTableView->selectionModel(),
&QItemSelectionModel::selectionChanged,
this,
&ColorPaletteEditor::slotTableViewContextMenuRequested);
connect(m_pPaletteNameComboBox,
&QComboBox::editTextChanged,
&ColorPaletteEditor::slotSelectionChanged);
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();

if (selection.count() > 0) {
QModelIndex index = selection.at(0);
void ColorPaletteEditor::slotAddColor() {
m_pModel->appendRow(kDefaultPaletteColor);
m_pTableView->scrollToBottom();
m_pTableView->setCurrentIndex(
m_pModel->index(m_pModel->rowCount() - 1, 0));
}

//row selected
int row = index.row();
m_pModel->removeRow(row);
}
void ColorPaletteEditor::slotRemoveColor() {
QModelIndexList selection = m_pTableView->selectionModel()->selectedRows();
for (const auto& index : selection) {
//row selected
int row = index.row();
m_pModel->removeRow(row);
}
m_pRemoveColorButton->setDisabled(
!m_pTableView->selectionModel()->hasSelection());
}

void ColorPaletteEditor::slotPaletteNameChanged(const QString& text) {
Expand Down Expand Up @@ -172,49 +220,61 @@ 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();
ColorPaletteSettings colorPaletteSettings(m_pConfig);
colorPaletteSettings.removePalette(paletteName);
reset();
emit paletteRemoved(paletteName);
void ColorPaletteEditor::slotCloseButtonClicked() {
reject();
}

void ColorPaletteEditor::slotRemoveButtonClicked() {
QString paletteName = m_pSaveAsEdit->text().trimmed();

QMessageBox msgBox;
msgBox.setWindowTitle(tr("Remove Palette"));
msgBox.setText(tr(
"Do you really want to remove the palette permanently?"));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
int ret = msgBox.exec();
if (ret == QMessageBox::Ok) {
ColorPaletteSettings colorPaletteSettings(m_pConfig);
colorPaletteSettings.removePalette(paletteName);
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();
}

void ColorPaletteEditor::slotSelectionChanged(
const QItemSelection& selected,
const QItemSelection& deselected) {
Q_UNUSED(deselected);
m_pRemoveColorButton->setDisabled(!selected.count());
}
Loading