diff --git a/cockatrice/src/client/settings/cache_settings.cpp b/cockatrice/src/client/settings/cache_settings.cpp index 2ad1f1ece..2f0eb98dc 100644 --- a/cockatrice/src/client/settings/cache_settings.cpp +++ b/cockatrice/src/client/settings/cache_settings.cpp @@ -239,6 +239,7 @@ SettingsCache::SettingsCache() homeTabBackgroundSource = settings->value("home/background", "themed").toString(); homeTabBackgroundShuffleFrequency = settings->value("home/background/shuffleTimer", 0).toInt(); + homeTabDisplayCardName = settings->value("home/background/displayCardName", true).toBool(); tabVisualDeckStorageOpen = settings->value("tabs/visualDeckStorage", true).toBool(); tabServerOpen = settings->value("tabs/server", true).toBool(); @@ -594,6 +595,13 @@ void SettingsCache::setHomeTabBackgroundShuffleFrequency(int _frequency) emit homeTabBackgroundShuffleFrequencyChanged(); } +void SettingsCache::setHomeTabDisplayCardName(QT_STATE_CHANGED_T _displayCardName) +{ + homeTabDisplayCardName = static_cast(_displayCardName); + settings->setValue("home/background/displayCardName", homeTabDisplayCardName); + emit homeTabDisplayCardNameChanged(); +} + void SettingsCache::setTabVisualDeckStorageOpen(bool value) { tabVisualDeckStorageOpen = value; diff --git a/cockatrice/src/client/settings/cache_settings.h b/cockatrice/src/client/settings/cache_settings.h index ca9a2a39b..f4e1000be 100644 --- a/cockatrice/src/client/settings/cache_settings.h +++ b/cockatrice/src/client/settings/cache_settings.h @@ -143,6 +143,7 @@ signals: void themeChanged(); void homeTabBackgroundSourceChanged(); void homeTabBackgroundShuffleFrequencyChanged(); + void homeTabDisplayCardNameChanged(); void picDownloadChanged(); void showStatusBarChanged(bool state); void showGameSelectorFilterToolbarChanged(bool state); @@ -222,6 +223,7 @@ private: bool showTipsOnStartup; QList seenTips; int homeTabBackgroundShuffleFrequency; + bool homeTabDisplayCardName; bool mbDownloadSpoilers; int updateReleaseChannel; int maxFontSize; @@ -413,6 +415,10 @@ public: { return homeTabBackgroundShuffleFrequency; } + [[nodiscard]] bool getHomeTabDisplayCardName() const + { + return homeTabDisplayCardName; + } [[nodiscard]] bool getTabVisualDeckStorageOpen() const { return tabVisualDeckStorageOpen; @@ -1001,6 +1007,7 @@ public slots: void setThemeName(const QString &_themeName); void setHomeTabBackgroundSource(const QString &_backgroundSource); void setHomeTabBackgroundShuffleFrequency(int _frequency); + void setHomeTabDisplayCardName(QT_STATE_CHANGED_T _displayCardName); void setTabVisualDeckStorageOpen(bool value); void setTabServerOpen(bool value); void setTabAccountOpen(bool value); diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp b/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp index fe8840a41..e97ca8921 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp +++ b/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp @@ -438,6 +438,7 @@ AppearanceSettingsPage::AppearanceSettingsPage() connect(&homeTabBackgroundSourceBox, QOverload::of(&QComboBox::currentIndexChanged), this, [this]() { auto type = homeTabBackgroundSourceBox.currentData().value(); SettingsCache::instance().setHomeTabBackgroundSource(BackgroundSources::toId(type)); + updateHomeTabSettingsVisibility(); }); homeTabBackgroundShuffleFrequencySpinBox.setRange(0, 3600); @@ -446,6 +447,12 @@ AppearanceSettingsPage::AppearanceSettingsPage() connect(&homeTabBackgroundShuffleFrequencySpinBox, qOverload(&QSpinBox::valueChanged), &SettingsCache::instance(), &SettingsCache::setHomeTabBackgroundShuffleFrequency); + homeTabDisplayCardNameCheckBox.setChecked(settings.getHomeTabDisplayCardName()); + connect(&homeTabDisplayCardNameCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings, + &SettingsCache::setHomeTabDisplayCardName); + + updateHomeTabSettingsVisibility(); + auto *themeGrid = new QGridLayout; themeGrid->addWidget(&themeLabel, 0, 0); themeGrid->addWidget(&themeBox, 0, 1); @@ -454,6 +461,8 @@ AppearanceSettingsPage::AppearanceSettingsPage() themeGrid->addWidget(&homeTabBackgroundSourceBox, 2, 1); themeGrid->addWidget(&homeTabBackgroundShuffleFrequencyLabel, 3, 0); themeGrid->addWidget(&homeTabBackgroundShuffleFrequencySpinBox, 3, 1); + themeGrid->addWidget(&homeTabDisplayCardNameLabel, 4, 0); + themeGrid->addWidget(&homeTabDisplayCardNameCheckBox, 4, 1); themeGroupBox = new QGroupBox; themeGroupBox->setLayout(themeGrid); @@ -650,6 +659,17 @@ void AppearanceSettingsPage::openThemeLocation() } } +void AppearanceSettingsPage::updateHomeTabSettingsVisibility() +{ + bool visible = + SettingsCache::instance().getHomeTabBackgroundSource() != BackgroundSources::toId(BackgroundSources::Theme); + + homeTabBackgroundShuffleFrequencyLabel.setVisible(visible); + homeTabBackgroundShuffleFrequencySpinBox.setVisible(visible); + homeTabDisplayCardNameLabel.setVisible(visible); + homeTabDisplayCardNameCheckBox.setVisible(visible); +} + void AppearanceSettingsPage::showShortcutsChanged(QT_STATE_CHANGED_T value) { SettingsCache::instance().setShowShortcuts(value); @@ -729,6 +749,7 @@ void AppearanceSettingsPage::retranslateUi() homeTabBackgroundSourceLabel.setText(tr("Home tab background source:")); homeTabBackgroundShuffleFrequencyLabel.setText(tr("Home tab background shuffle frequency:")); homeTabBackgroundShuffleFrequencySpinBox.setSpecialValueText(tr("Disabled")); + homeTabDisplayCardNameLabel.setText(tr("Display card name of background in bottom right:")); menuGroupBox->setTitle(tr("Menu settings")); showShortcutsCheckBox.setText(tr("Show keyboard shortcuts in right-click menus")); diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_settings.h b/cockatrice/src/interface/widgets/dialogs/dlg_settings.h index 06ad3601c..db107c6e2 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_settings.h +++ b/cockatrice/src/interface/widgets/dialogs/dlg_settings.h @@ -103,6 +103,7 @@ class AppearanceSettingsPage : public AbstractSettingsPage private slots: void themeBoxChanged(int index); void openThemeLocation(); + void updateHomeTabSettingsVisibility(); void showShortcutsChanged(QT_STATE_CHANGED_T enabled); void overrideAllCardArtWithPersonalPreferenceToggled(QT_STATE_CHANGED_T enabled); @@ -117,6 +118,8 @@ private: QComboBox homeTabBackgroundSourceBox; QLabel homeTabBackgroundShuffleFrequencyLabel; QSpinBox homeTabBackgroundShuffleFrequencySpinBox; + QLabel homeTabDisplayCardNameLabel; + QCheckBox homeTabDisplayCardNameCheckBox; QLabel minPlayersForMultiColumnLayoutLabel; QLabel maxFontSizeForCardsLabel; QCheckBox showShortcutsCheckBox; diff --git a/cockatrice/src/interface/widgets/general/home_widget.cpp b/cockatrice/src/interface/widgets/general/home_widget.cpp index f35f90256..803a93108 100644 --- a/cockatrice/src/interface/widgets/general/home_widget.cpp +++ b/cockatrice/src/interface/widgets/general/home_widget.cpp @@ -44,6 +44,8 @@ HomeWidget::HomeWidget(QWidget *parent, TabSupervisor *_tabSupervisor) &HomeWidget::initializeBackgroundFromSource); connect(&SettingsCache::instance(), &SettingsCache::homeTabBackgroundShuffleFrequencyChanged, this, &HomeWidget::onBackgroundShuffleFrequencyChanged); + // Lambda is cleaner to read than overloading this + connect(&SettingsCache::instance(), &SettingsCache::homeTabDisplayCardNameChanged, this, [this] { repaint(); }); } void HomeWidget::initializeBackgroundFromSource() @@ -297,6 +299,7 @@ QPair HomeWidget::extractDominantColors(const QPixmap &pixmap) void HomeWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); background = background.scaled(size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); @@ -308,13 +311,47 @@ void HomeWidget::paintEvent(QPaintEvent *event) painter.drawPixmap(topLeft, background); // Draw translucent black overlay with rounded corners - QRectF overlayRect(5, 5, width() - 10, height() - 10); // 5px inset + QRectF overlayRect(5, 5, width() - 10, height() - 10); QPainterPath roundedRectPath; - roundedRectPath.addRoundedRect(overlayRect, 20, 20); // 20px corner radius + roundedRectPath.addRoundedRect(overlayRect, 20, 20); - QColor semiTransparentBlack(0, 0, 0, static_cast(255 * 0.33)); // 33% opacity - painter.setRenderHint(QPainter::Antialiasing); + QColor semiTransparentBlack(0, 0, 0, static_cast(255 * 0.33)); painter.fillPath(roundedRectPath, semiTransparentBlack); + // Card name overlay (bottom-right) + QString cardName; + ExactCard card = backgroundSourceCard->getCard(); + if (card) { + cardName = card.getCardPtr()->getName() + " (" + card.getPrinting().getSet()->getCorrectedShortName() + ") " + + card.getPrinting().getProperty("num"); + } + + if (!cardName.isEmpty() && SettingsCache::instance().getHomeTabDisplayCardName()) { + QFont font = painter.font(); + font.setPointSize(14); + font.setBold(true); + painter.setFont(font); + + QFontMetrics fm(font); + constexpr int padding = 10; + constexpr int margin = 15; + + QRect textRect = fm.boundingRect(cardName); + + QRect bgRect(width() - textRect.width() - padding * 2 - margin, + height() - textRect.height() - padding * 2 - margin, textRect.width() + padding * 2, + textRect.height() + padding * 2); + + // Background bubble + painter.setPen(Qt::NoPen); + painter.setBrush(QColor(0, 0, 0, 160)); + painter.drawRoundedRect(bgRect, 8, 8); + + // Text + painter.setPen(Qt::white); + painter.drawText(bgRect.adjusted(padding, padding, -padding, -padding), Qt::AlignRight | Qt::AlignVCenter, + cardName); + } + QWidget::paintEvent(event); }