[HomeTab] Introduce button color source setting (#7181)
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 26 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions

This commit is contained in:
RickyRister 2026-08-25 10:27:07 -07:00 committed by GitHub
parent b3e126f904
commit dba7cc73a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 117 additions and 8 deletions

View file

@ -230,6 +230,7 @@ set(cockatrice_SOURCES
src/interface/widgets/general/display/charts/bars/segmented_bar_widget.cpp src/interface/widgets/general/display/charts/bars/segmented_bar_widget.cpp
src/interface/widgets/general/display/charts/pies/color_pie.cpp src/interface/widgets/general/display/charts/pies/color_pie.cpp
src/interface/widgets/general/home_styled_button.cpp src/interface/widgets/general/home_styled_button.cpp
src/interface/widgets/general/home_tab_button_color.h
src/interface/widgets/general/home_widget.cpp src/interface/widgets/general/home_widget.cpp
src/interface/widgets/general/layout_containers/flow_widget.cpp src/interface/widgets/general/layout_containers/flow_widget.cpp
src/interface/widgets/general/layout_containers/overlap_control_widget.cpp src/interface/widgets/general/layout_containers/overlap_control_widget.cpp

View file

@ -0,0 +1,49 @@
#ifndef COCKATRICE_HOME_TAB_BUTTON_COLOR_H
#define COCKATRICE_HOME_TAB_BUTTON_COLOR_H
#include <QList>
namespace HomeTabButtonColor
{
/**
* @brief Where to get the colors for the home tab buttons from
*/
enum Source
{
Automatic, ///< Extract color from background, or use theme color if no background
FromBackground, ///< Always extract color from background
};
struct Entry
{
Source source;
const char *trKey; ///< key for translation
};
inline QList<Entry> all()
{
static QList<Entry> entries = {{Automatic, QT_TR_NOOP("Automatic")},
{FromBackground, QT_TR_NOOP("Extract from background")}};
return entries;
}
/**
* Safely converts an int into the corresponding Source.
*
* @param value The int value
* @return The Source. Returns Source::Automatic if the value is not within range
*/
inline Source intToSource(int value)
{
if (value > FromBackground) {
return Automatic; // default
}
return static_cast<Source>(value);
}
} // namespace HomeTabButtonColor
#endif // COCKATRICE_HOME_TAB_BUTTON_COLOR_H

View file

@ -7,6 +7,7 @@
#include "../cards/art_crop_attribution.h" #include "../cards/art_crop_attribution.h"
#include "background_sources.h" #include "background_sources.h"
#include "home_styled_button.h" #include "home_styled_button.h"
#include "home_tab_button_color.h"
#include <QGroupBox> #include <QGroupBox>
#include <QPainter> #include <QPainter>
@ -25,7 +26,7 @@ HomeWidget::HomeWidget(QWidget *parent, TabSupervisor *_tabSupervisor)
backgroundSourceCard = new CardInfoPictureArtCropWidget(this); backgroundSourceCard = new CardInfoPictureArtCropWidget(this);
gradientColors = extractDominantColors(background); gradientColors = determineButtonColor();
layout->addWidget(createButtons(), 1, 1, Qt::AlignVCenter | Qt::AlignHCenter); layout->addWidget(createButtons(), 1, 1, Qt::AlignVCenter | Qt::AlignHCenter);
@ -55,6 +56,8 @@ HomeWidget::HomeWidget(QWidget *parent, TabSupervisor *_tabSupervisor)
&HomeWidget::initializeBackgroundFromSource); &HomeWidget::initializeBackgroundFromSource);
connect(&SettingsCache::instance(), &SettingsCache::themeChanged, this, connect(&SettingsCache::instance(), &SettingsCache::themeChanged, this,
&HomeWidget::updateButtonsToBackgroundColor); &HomeWidget::updateButtonsToBackgroundColor);
connect(&SettingsCache::instance().appearance(), &AppearanceSettings::homeTabButtonColorChanged, this,
&HomeWidget::updateButtonsToBackgroundColor);
} }
void HomeWidget::initializeBackgroundFromSource() void HomeWidget::initializeBackgroundFromSource()
@ -97,6 +100,34 @@ void HomeWidget::loadBackgroundSourceDeck()
backgroundSourceDeck = deckOpt.has_value() ? deckOpt.value().deckList : DeckList(); backgroundSourceDeck = deckOpt.has_value() ? deckOpt.value().deckList : DeckList();
} }
static bool isDefaultBackgroundAndTheme()
{
QString sourceId = SettingsCache::instance().appearance().getHomeTabBackgroundSource();
return themeManager->isBuiltInTheme() && BackgroundSources::fromId(sourceId) == BackgroundSources::Theme;
}
QPair<QColor, QColor> HomeWidget::determineButtonColor() const
{
static QPair defaultColor = {QColor::fromRgb(20, 140, 60), QColor::fromRgb(120, 200, 80)};
auto colorSource =
HomeTabButtonColor::intToSource(SettingsCache::instance().appearance().getHomeTabButtonColorSourceIndex());
switch (colorSource) {
case HomeTabButtonColor::Automatic: {
if (isDefaultBackgroundAndTheme()) {
return defaultColor;
} else {
return extractDominantColors(background);
}
}
case HomeTabButtonColor::FromBackground:
return extractDominantColors(background);
}
return defaultColor;
}
void HomeWidget::setRandomCard(ExactCard &newCard) void HomeWidget::setRandomCard(ExactCard &newCard)
{ {
static constexpr int ATTEMPTS = 10; static constexpr int ATTEMPTS = 10;
@ -171,7 +202,7 @@ void HomeWidget::updateBackgroundProperties()
void HomeWidget::updateButtonsToBackgroundColor() void HomeWidget::updateButtonsToBackgroundColor()
{ {
gradientColors = extractDominantColors(background); gradientColors = determineButtonColor();
for (HomeStyledButton *button : findChildren<HomeStyledButton *>()) { for (HomeStyledButton *button : findChildren<HomeStyledButton *>()) {
button->updateStylesheet(gradientColors); button->updateStylesheet(gradientColors);
button->update(); button->update();
@ -266,11 +297,6 @@ void HomeWidget::updateConnectButton(const ClientStatus status)
QPair<QColor, QColor> HomeWidget::extractDominantColors(const QPixmap &pixmap) QPair<QColor, QColor> HomeWidget::extractDominantColors(const QPixmap &pixmap)
{ {
QString sourceId = SettingsCache::instance().appearance().getHomeTabBackgroundSource();
if (themeManager->isBuiltInTheme() && BackgroundSources::fromId(sourceId) == BackgroundSources::Theme) {
return QPair<QColor, QColor>(QColor::fromRgb(20, 140, 60), QColor::fromRgb(120, 200, 80));
}
// Step 1: Downscale image for performance // Step 1: Downscale image for performance
QImage image = pixmap.toImage() QImage image = pixmap.toImage()
.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation) .scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation)

View file

@ -23,7 +23,7 @@ class HomeWidget : public QWidget
public: public:
HomeWidget(QWidget *parent, TabSupervisor *tabSupervisor); HomeWidget(QWidget *parent, TabSupervisor *tabSupervisor);
void updateRandomCard(); void updateRandomCard();
QPair<QColor, QColor> extractDominantColors(const QPixmap &pixmap); static QPair<QColor, QColor> extractDominantColors(const QPixmap &pixmap);
public slots: public slots:
void paintEvent(QPaintEvent *event) override; void paintEvent(QPaintEvent *event) override;
@ -47,6 +47,7 @@ private:
void setRandomCard(ExactCard &newCard); void setRandomCard(ExactCard &newCard);
void loadBackgroundSourceDeck(); void loadBackgroundSourceDeck();
QPair<QColor, QColor> determineButtonColor() const;
}; };
#endif // HOME_WIDGET_H #endif // HOME_WIDGET_H

View file

@ -5,6 +5,7 @@
#include "../../client/settings/card_counter_settings.h" #include "../../client/settings/card_counter_settings.h"
#include "../../palette_editor/palette_editor_dialog.h" #include "../../palette_editor/palette_editor_dialog.h"
#include "../dialogs/override_printing_warning.h" #include "../dialogs/override_printing_warning.h"
#include "../general/home_tab_button_color.h"
#include "../interface/theme_manager.h" #include "../interface/theme_manager.h"
#include "../interface/widgets/general/background_sources.h" #include "../interface/widgets/general/background_sources.h"
#include "../playmat/playmat_collection_dialog.h" #include "../playmat/playmat_collection_dialog.h"
@ -131,6 +132,14 @@ AppearanceSettingsPage::AppearanceSettingsPage()
connect(&homeTabDisplayCardNameCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings.appearance(), connect(&homeTabDisplayCardNameCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings.appearance(),
&AppearanceSettings::setHomeTabDisplayCardName); &AppearanceSettings::setHomeTabDisplayCardName);
for (const auto &entry : HomeTabButtonColor::all()) {
homeTabButtonColorSourceBox.addItem(QObject::tr(entry.trKey));
}
homeTabButtonColorSourceBox.setCurrentIndex(settings.appearance().getHomeTabButtonColorSourceIndex());
connect(&homeTabButtonColorSourceBox, QOverload<int>::of(&QComboBox::currentIndexChanged), &settings.appearance(),
&AppearanceSettings::setHomeTabButtonColorSourceIndex);
updateHomeTabSettingsVisibility(); updateHomeTabSettingsVisibility();
auto *homeTabGrid = new QGridLayout; auto *homeTabGrid = new QGridLayout;
@ -139,6 +148,8 @@ AppearanceSettingsPage::AppearanceSettingsPage()
homeTabGrid->addWidget(&homeTabBackgroundShuffleFrequencyLabel, 1, 0); homeTabGrid->addWidget(&homeTabBackgroundShuffleFrequencyLabel, 1, 0);
homeTabGrid->addWidget(&homeTabBackgroundShuffleFrequencySpinBox, 1, 1); homeTabGrid->addWidget(&homeTabBackgroundShuffleFrequencySpinBox, 1, 1);
homeTabGrid->addWidget(&homeTabDisplayCardNameCheckBox, 2, 0, 1, 2); homeTabGrid->addWidget(&homeTabDisplayCardNameCheckBox, 2, 0, 1, 2);
homeTabGrid->addWidget(&homeTabButtonColorSourceLabel, 3, 0);
homeTabGrid->addWidget(&homeTabButtonColorSourceBox, 3, 1);
homeTabGroupBox = new QGroupBox; homeTabGroupBox = new QGroupBox;
homeTabGroupBox->setLayout(homeTabGrid); homeTabGroupBox->setLayout(homeTabGrid);
@ -497,6 +508,9 @@ void AppearanceSettingsPage::retranslateUi()
homeTabBackgroundShuffleFrequencyLabel.setText(tr("Home tab background shuffle frequency:")); homeTabBackgroundShuffleFrequencyLabel.setText(tr("Home tab background shuffle frequency:"));
homeTabBackgroundShuffleFrequencySpinBox.setSpecialValueText(tr("Disabled")); homeTabBackgroundShuffleFrequencySpinBox.setSpecialValueText(tr("Disabled"));
homeTabDisplayCardNameCheckBox.setText(tr("Display card name of background in bottom right")); homeTabDisplayCardNameCheckBox.setText(tr("Display card name of background in bottom right"));
homeTabButtonColorSourceLabel.setText(tr("Home tab button color:"));
homeTabButtonColorSourceBox.setToolTip(
tr("Automatic: extract from background if present, otherwise use theme default"));
stylingGroupBox->setTitle(tr("Styling settings")); stylingGroupBox->setTitle(tr("Styling settings"));
styleUserListCheckBox.setText(tr("Style user list")); styleUserListCheckBox.setText(tr("Style user list"));

View file

@ -35,11 +35,15 @@ private:
QLabel styleComboLabel; QLabel styleComboLabel;
QComboBox styleCombo; QComboBox styleCombo;
QPushButton editPaletteButton; QPushButton editPaletteButton;
QLabel homeTabBackgroundSourceLabel; QLabel homeTabBackgroundSourceLabel;
QComboBox homeTabBackgroundSourceBox; QComboBox homeTabBackgroundSourceBox;
QLabel homeTabBackgroundShuffleFrequencyLabel; QLabel homeTabBackgroundShuffleFrequencyLabel;
QSpinBox homeTabBackgroundShuffleFrequencySpinBox; QSpinBox homeTabBackgroundShuffleFrequencySpinBox;
QCheckBox homeTabDisplayCardNameCheckBox; QCheckBox homeTabDisplayCardNameCheckBox;
QLabel homeTabButtonColorSourceLabel;
QComboBox homeTabButtonColorSourceBox;
QCheckBox styleUserListCheckBox; QCheckBox styleUserListCheckBox;
QCheckBox showShortcutsCheckBox; QCheckBox showShortcutsCheckBox;
QCheckBox showGameSelectorFilterToolbarCheckBox; QCheckBox showGameSelectorFilterToolbarCheckBox;

View file

@ -69,3 +69,14 @@ void AppearanceSettings::setHomeTabDisplayCardName(bool _displayCardName)
setValue(_displayCardName, "homeTabDisplayCardName"); setValue(_displayCardName, "homeTabDisplayCardName");
emit homeTabDisplayCardNameChanged(); emit homeTabDisplayCardNameChanged();
} }
int AppearanceSettings::getHomeTabButtonColorSourceIndex() const
{
return getValue("homeTabButtonColorSource", "", "", 0).toInt();
}
void AppearanceSettings::setHomeTabButtonColorSourceIndex(int index)
{
setValue(index, "homeTabButtonColorSource");
emit homeTabButtonColorChanged();
}

View file

@ -27,6 +27,8 @@ public:
void setHomeTabBackgroundShuffleFrequency(int _frequency); void setHomeTabBackgroundShuffleFrequency(int _frequency);
[[nodiscard]] bool getHomeTabDisplayCardName() const; [[nodiscard]] bool getHomeTabDisplayCardName() const;
void setHomeTabDisplayCardName(bool _displayCardName); void setHomeTabDisplayCardName(bool _displayCardName);
[[nodiscard]] int getHomeTabButtonColorSourceIndex() const;
void setHomeTabButtonColorSourceIndex(int index);
signals: signals:
void themeNameChanged(); void themeNameChanged();
@ -34,6 +36,7 @@ signals:
void homeTabBackgroundSourceChanged(); void homeTabBackgroundSourceChanged();
void homeTabBackgroundShuffleFrequencyChanged(); void homeTabBackgroundShuffleFrequencyChanged();
void homeTabDisplayCardNameChanged(); void homeTabDisplayCardNameChanged();
void homeTabButtonColorChanged();
public: public:
explicit AppearanceSettings(const QString &settingPath, QObject *parent = nullptr); explicit AppearanceSettings(const QString &settingPath, QObject *parent = nullptr);