Skip to content

Commit

Permalink
Merge pull request #11439 from ronso0/colorpicker-button-size-fix
Browse files Browse the repository at this point in the history
some WColorPicker fixes
  • Loading branch information
daschuer authored Apr 5, 2023
2 parents 98aab92 + 5e2078f commit c0f31df
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/dialog/dlgreplacecuecolor.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit c0f31df

Please sign in to comment.