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

some WColorPicker fixes #11439

Merged
merged 3 commits into from Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/dialog/dlgreplacecuecolor.cpp
Expand Up @@ -90,9 +90,11 @@ DlgReplaceCueColor::DlgReplaceCueColor(
}
setButtonColor(pushButtonNewColor, mixxx::RgbColor::toQColor(firstColor));

// Add menu for new color button
// Add menu for 'New color' button
m_pNewColorPickerAction = make_parented<WColorPickerAction>(
WColorPicker::Option::AllowCustomColor,
WColorPicker::Option::AllowCustomColor |
// TODO(xxx) remove this once the preferences are themed via QSS
WColorPicker::Option::NoExtStyleSheet,
colorPaletteSettings.getHotcueColorPalette(),
this);
m_pNewColorPickerAction->setObjectName("HotcueColorPickerAction");
Expand All @@ -110,7 +112,7 @@ DlgReplaceCueColor::DlgReplaceCueColor(
m_pNewColorMenu->addAction(m_pNewColorPickerAction);
pushButtonNewColor->setMenu(m_pNewColorMenu);

// Set up current color button
// Set up 'Current color' button
setButtonColor(pushButtonCurrentColor,
mixxx::RgbColor::toQColor(
mixxx::PredefinedColorPalettes::kDefaultCueColor));
Expand All @@ -122,13 +124,15 @@ DlgReplaceCueColor::DlgReplaceCueColor(
this,
&DlgReplaceCueColor::slotUpdateWidgets);

// Add menu for current color button
// Add menu for 'Current color' button
m_pCurrentColorPickerAction = make_parented<WColorPickerAction>(
WColorPicker::Option::AllowCustomColor,
WColorPicker::Option::AllowCustomColor |
// TODO(xxx) remove this once the preferences are themed via QSS
WColorPicker::Option::NoExtStyleSheet,
colorPaletteSettings.getHotcueColorPalette(),
this);
m_pCurrentColorPickerAction->setObjectName("HotcueColorPickerAction");
m_pNewColorPickerAction->setSelectedColor(
m_pCurrentColorPickerAction->setSelectedColor(
mixxx::PredefinedColorPalettes::kDefaultCueColor);
connect(m_pCurrentColorPickerAction,
&WColorPickerAction::colorPicked,
Expand Down
7 changes: 7 additions & 0 deletions src/widget/wcolorpicker.cpp
Expand Up @@ -152,6 +152,9 @@ void WColorPicker::addColorButton(mixxx::RgbColor color, QGridLayout* pLayout, i
QString("QPushButton { background-color: %1; }").arg(mixxx::RgbColor::toQString(color)));
pButton->setToolTip(mixxx::RgbColor::toQString(color));
pButton->setCheckable(true);
// Without this the button might shrink when setting the checkmark icon,
// both here or via external stylesheets.
pButton->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
m_colorButtons.append(pButton);

connect(pButton,
Expand All @@ -174,6 +177,7 @@ void WColorPicker::addNoColorButton(QGridLayout* pLayout, int row, int column) {
pButton->setProperty("noColor", true);
pButton->setToolTip(tr("No color"));
pButton->setCheckable(true);
pButton->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
connect(pButton,
&QPushButton::clicked,
this,
Expand Down Expand Up @@ -227,6 +231,9 @@ void WColorPicker::setColorButtonChecked(mixxx::RgbColor::optional_t color, bool
}

pButton->setChecked(checked);
if (m_options.testFlag(Option::NoExtStyleSheet)) {
pButton->setIcon(QIcon(checked ? ":/images/ic_checkmark.svg" : ""));
}
// This is needed to re-apply skin styles (e.g. to show/hide a checkmark icon)
pButton->style()->unpolish(pButton);
pButton->style()->polish(pButton);
Expand Down
6 changes: 6 additions & 0 deletions src/widget/wcolorpicker.h
Expand Up @@ -18,6 +18,12 @@ class WColorPicker : public QWidget {
NoOptions = 0,
AllowNoColor = 1,
AllowCustomColor = 1 << 1,
// Some color pickers can be styled with the skin stylesheets,
// for example in WCueMenuPopup or WTrackMenu.
// If that's not possible (or just not done yet), for example in
// DlgReplaceCueColor and DlgTrackInfo, use this option to un/set
// the checkmark icon on de/selected color buttons in c++.
NoExtStyleSheet = 1 << 2,
};
Q_DECLARE_FLAGS(Options, Option);

Expand Down