From 62a01a6ee84ee6e7bc77370c48f5be4e4b52fc9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Wed, 10 Sep 2025 23:48:02 +0200 Subject: [PATCH] Home tab. Took 2 hours 41 minutes --- cockatrice/CMakeLists.txt | 1 + cockatrice/src/client/tabs/tab_supervisor.cpp | 9 + cockatrice/src/client/tabs/tab_supervisor.h | 1 + .../ui/widgets/general/background_sources.cpp | 3 + .../ui/widgets/general/background_sources.h | 62 +++++ .../client/ui/widgets/general/home_widget.cpp | 218 ++++++++---------- .../client/ui/widgets/general/home_widget.h | 13 +- cockatrice/src/client/ui/window_main.h | 2 +- cockatrice/src/dialogs/dlg_settings.cpp | 29 +++ cockatrice/src/dialogs/dlg_settings.h | 4 + cockatrice/src/settings/cache_settings.cpp | 17 ++ cockatrice/src/settings/cache_settings.h | 15 +- dbconverter/src/mocks.cpp | 6 + tests/carddatabase/mocks.cpp | 6 + 14 files changed, 254 insertions(+), 132 deletions(-) create mode 100644 cockatrice/src/client/ui/widgets/general/background_sources.cpp create mode 100644 cockatrice/src/client/ui/widgets/general/background_sources.h diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index f34cac6cd..dfe40b03d 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -102,6 +102,7 @@ set(cockatrice_SOURCES src/client/ui/widgets/deck_editor/deck_editor_deck_dock_widget.cpp src/client/ui/widgets/deck_editor/deck_editor_filter_dock_widget.cpp src/client/ui/widgets/deck_editor/deck_editor_printing_selector_dock_widget.cpp + src/client/ui/widgets/general/background_sources.cpp src/client/ui/widgets/general/home_styled_button.cpp src/client/ui/widgets/general/home_widget.cpp src/client/ui/widgets/general/display/banner_widget.cpp diff --git a/cockatrice/src/client/tabs/tab_supervisor.cpp b/cockatrice/src/client/tabs/tab_supervisor.cpp index 0843c9f30..edade906e 100644 --- a/cockatrice/src/client/tabs/tab_supervisor.cpp +++ b/cockatrice/src/client/tabs/tab_supervisor.cpp @@ -740,6 +740,15 @@ void TabSupervisor::roomLeft(TabRoom *tab) removeTab(indexOf(tab)); } +void TabSupervisor::switchToFirstAvailableNetworkTab() +{ + if (!roomTabs.isEmpty()) { + setCurrentWidget(roomTabs.first()); + } else if (tabServer) { + setCurrentWidget(tabServer); + } +} + void TabSupervisor::openReplay(GameReplay *replay) { auto *replayTab = new TabGame(this, replay); diff --git a/cockatrice/src/client/tabs/tab_supervisor.h b/cockatrice/src/client/tabs/tab_supervisor.h index 24cd2c012..14c79bdca 100644 --- a/cockatrice/src/client/tabs/tab_supervisor.h +++ b/cockatrice/src/client/tabs/tab_supervisor.h @@ -168,6 +168,7 @@ public slots: TabEdhRecMain *addEdhrecMainTab(); TabEdhRec *addEdhrecTab(const CardInfoPtr &cardToQuery, bool isCommander = false); void openReplay(GameReplay *replay); + void switchToFirstAvailableNetworkTab(); void maximizeMainWindow(); void actTabVisualDeckStorage(bool checked); void actTabReplays(bool checked); diff --git a/cockatrice/src/client/ui/widgets/general/background_sources.cpp b/cockatrice/src/client/ui/widgets/general/background_sources.cpp new file mode 100644 index 000000000..0d3efa330 --- /dev/null +++ b/cockatrice/src/client/ui/widgets/general/background_sources.cpp @@ -0,0 +1,3 @@ +#include "background_sources.h" + +// Required so moc generates Q_OBJECT macros \ No newline at end of file diff --git a/cockatrice/src/client/ui/widgets/general/background_sources.h b/cockatrice/src/client/ui/widgets/general/background_sources.h new file mode 100644 index 000000000..2b4cb64cc --- /dev/null +++ b/cockatrice/src/client/ui/widgets/general/background_sources.h @@ -0,0 +1,62 @@ +#ifndef COCKATRICE_BACKGROUND_SOURCES_H +#define COCKATRICE_BACKGROUND_SOURCES_H + +#include +#include +#include + +class BackgroundSources +{ + Q_GADGET +public: + enum Type + { + Theme, + RandomCardArt, + DeckFileArt + }; + Q_ENUM(Type) + + struct Entry + { + Type type; + const char *id; // stable ID for settings + const char *trKey; // key for translation + }; + + static QList all() + { + return {{Theme, "theme", QT_TR_NOOP("Theme")}, + {RandomCardArt, "random_card_art", QT_TR_NOOP("Art crop of random card")}, + {DeckFileArt, "deck_file_art", QT_TR_NOOP("Art crop of background.cod deck file")}}; + } + + static QString toId(Type type) + { + for (const auto &e : all()) { + if (e.type == type) + return e.id; + } + return {}; + } + + static Type fromId(const QString &id) + { + for (const auto &e : all()) { + if (id == e.id) + return e.type; + } + return Theme; // default + } + + static QString toDisplay(Type type) + { + for (const auto &e : all()) { + if (e.type == type) + return QObject::tr(e.trKey); + } + return {}; + } +}; + +#endif // COCKATRICE_BACKGROUND_SOURCES_H diff --git a/cockatrice/src/client/ui/widgets/general/home_widget.cpp b/cockatrice/src/client/ui/widgets/general/home_widget.cpp index 804ad6bd4..bb33c2de8 100644 --- a/cockatrice/src/client/ui/widgets/general/home_widget.cpp +++ b/cockatrice/src/client/ui/widgets/general/home_widget.cpp @@ -1,7 +1,11 @@ #include "home_widget.h" #include "../../../../game/cards/card_database_manager.h" +#include "../../../../server/remote/remote_client.h" +#include "../../../../settings/cache_settings.h" #include "../../../tabs/tab_supervisor.h" +#include "../../window_main.h" +#include "background_sources.h" #include "home_styled_button.h" #include @@ -15,18 +19,11 @@ HomeWidget::HomeWidget(QWidget *parent, TabSupervisor *_tabSupervisor) setAttribute(Qt::WA_OpaquePaintEvent); layout = new QGridLayout(this); - backgroundSource = new CardInfoPictureArtCropWidget(this); - - backgroundSource->setCard(CardDatabaseManager::getInstance()->getRandomCard()); - - background = backgroundSource->getProcessedBackground(size()); + backgroundSourceCard = new CardInfoPictureArtCropWidget(this); gradientColors = extractDominantColors(background); - layout->addWidget(createSettingsButtonGroup("Settings"), 0, 0, Qt::AlignTop | Qt::AlignLeft); - layout->addWidget(createUpdatesButtonGroup("Updates"), 0, 2, Qt::AlignTop | Qt::AlignRight); - layout->addWidget(createNavigationButtonGroup("Navigation"), 2, 0, Qt::AlignBottom | Qt::AlignLeft); - layout->addWidget(createPlayButtonGroup("Play"), 2, 2, Qt::AlignBottom | Qt::AlignRight); + layout->addWidget(createButtons(), 1, 1, Qt::AlignVCenter | Qt::AlignHCenter); layout->setRowStretch(0, 1); layout->setRowStretch(2, 1); @@ -35,19 +32,39 @@ HomeWidget::HomeWidget(QWidget *parent, TabSupervisor *_tabSupervisor) setLayout(layout); - connect(CardDatabaseManager::getInstance(), &CardDatabase::cardDatabaseLoadingFinished, this, - &HomeWidget::startCardShuffleTimer); - - if (CardDatabaseManager::getInstance()->getLoadStatus() == LoadStatus::Ok) { - startCardShuffleTimer(); - } -} - -void HomeWidget::startCardShuffleTimer() -{ cardChangeTimer = new QTimer(this); connect(cardChangeTimer, &QTimer::timeout, this, &HomeWidget::updateRandomCard); - cardChangeTimer->start(5000); // 20 seconds + + connect(CardDatabaseManager::getInstance(), &CardDatabase::cardDatabaseLoadingFinished, this, + &HomeWidget::initializeBackgroundFromSource); + + if (CardDatabaseManager::getInstance()->getLoadStatus() == LoadStatus::Ok) { + initializeBackgroundFromSource(); + } + + connect(tabSupervisor->getClient(), &RemoteClient::statusChanged, this, &HomeWidget::updateConnectButton); + connect(&SettingsCache::instance(), &SettingsCache::homeTabBackgroundSourceChanged, this, + &HomeWidget::initializeBackgroundFromSource); +} + +void HomeWidget::initializeBackgroundFromSource() +{ + auto type = BackgroundSources::fromId(SettingsCache::instance().getHomeTabBackgroundSource()); + + cardChangeTimer->stop(); + + switch (type) { + case BackgroundSources::Theme: + background = QPixmap("theme:backgrounds/home"); + update(); + break; + case BackgroundSources::RandomCardArt: + cardChangeTimer->start(SettingsCache::instance().getHomeTabBackgroundShuffleFrequency() * 1000); + break; + case BackgroundSources::DeckFileArt: + // do deck file stuff if and when we implement it + break; + } } void HomeWidget::updateRandomCard() @@ -57,13 +74,13 @@ void HomeWidget::updateRandomCard() return; connect(newCard.getCardPtr().data(), &CardInfo::pixmapUpdated, this, &HomeWidget::updateBackgroundProperties); - backgroundSource->setCard(newCard); + backgroundSourceCard->setCard(newCard); + background = backgroundSourceCard->getProcessedBackground(size()); } void HomeWidget::updateBackgroundProperties() { - background = backgroundSource->getProcessedBackground(size()); - + background = backgroundSourceCard->getProcessedBackground(size()); gradientColors = extractDominantColors(background); for (HomeStyledButton *button : findChildren()) { button->updateStylesheet(gradientColors); @@ -72,55 +89,9 @@ void HomeWidget::updateBackgroundProperties() update(); // Triggers repaint } -QGroupBox *HomeWidget::createSettingsButtonGroup(const QString &title) +QGroupBox *HomeWidget::createButtons() { - QGroupBox *box = new QGroupBox(title); - box->setStyleSheet(R"( - QGroupBox { - font-size: 20px; - color: white; /* Title text color */ - background: transparent; - } - - QGroupBox::title { - color: white; - subcontrol-origin: margin; - subcontrol-position: top center; /* or top left / right */ - } -)"); - QVBoxLayout *layout = new QVBoxLayout; - layout->setAlignment(Qt::AlignHCenter); // Center widgets horizontally - layout->addWidget(new HomeStyledButton("Settings", gradientColors)); - box->setLayout(layout); - return box; -} - -QGroupBox *HomeWidget::createUpdatesButtonGroup(const QString &title) -{ - QGroupBox *box = new QGroupBox(title); - box->setStyleSheet(R"( - QGroupBox { - font-size: 20px; - color: white; /* Title text color */ - background: transparent; - } - - QGroupBox::title { - color: white; - subcontrol-origin: margin; - subcontrol-position: top center; /* or top left / right */ - } -)"); - QVBoxLayout *layout = new QVBoxLayout; - layout->setAlignment(Qt::AlignHCenter); // Center widgets horizontally - layout->addWidget(new HomeStyledButton("Updates", gradientColors)); - box->setLayout(layout); - return box; -} - -QGroupBox *HomeWidget::createNavigationButtonGroup(const QString &title) -{ - QGroupBox *box = new QGroupBox(title); + QGroupBox *box = new QGroupBox(this); box->setStyleSheet(R"( QGroupBox { font-size: 20px; @@ -135,58 +106,65 @@ QGroupBox *HomeWidget::createNavigationButtonGroup(const QString &title) } )"); box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - QVBoxLayout *layout = new QVBoxLayout; - layout->setAlignment(Qt::AlignHCenter); // Center widgets horizontally - auto replaybutton = new HomeStyledButton("View Replays", gradientColors); - connect(replaybutton, &QPushButton::clicked, tabSupervisor, [this] { tabSupervisor->actTabReplays(true); }); - layout->addWidget(replaybutton); - auto edhrecButton = new HomeStyledButton("Browse EDHRec", gradientColors); - connect(edhrecButton, &QPushButton::clicked, tabSupervisor, &TabSupervisor::addEdhrecMainTab); - layout->addWidget(edhrecButton); - auto visualDatabaseDisplayButton = new HomeStyledButton("Browse Card Database", gradientColors); - connect(visualDatabaseDisplayButton, &QPushButton::clicked, tabSupervisor, - &TabSupervisor::addVisualDatabaseDisplayTab); - layout->addWidget(visualDatabaseDisplayButton); - auto visualDeckStorageButton = new HomeStyledButton("Browse Decks", gradientColors); - connect(visualDeckStorageButton, &QPushButton::clicked, tabSupervisor, - [this] { tabSupervisor->actTabVisualDeckStorage(true); }); - layout->addWidget(visualDeckStorageButton); + QVBoxLayout *boxLayout = new QVBoxLayout; + boxLayout->setAlignment(Qt::AlignHCenter); + + QLabel *logoLabel = new QLabel; + logoLabel->setPixmap(overlay.scaledToWidth(200, Qt::SmoothTransformation)); + logoLabel->setAlignment(Qt::AlignCenter); + boxLayout->addWidget(logoLabel); + boxLayout->addSpacing(25); + + connectButton = new HomeStyledButton("Connect/Play", gradientColors); + boxLayout->addWidget(connectButton, 1); + auto visualDeckEditorButton = new HomeStyledButton("Create New Deck", gradientColors); connect(visualDeckEditorButton, &QPushButton::clicked, tabSupervisor, [this] { tabSupervisor->addVisualDeckEditorTab(nullptr); }); - layout->addWidget(visualDeckEditorButton); - box->setLayout(layout); + boxLayout->addWidget(visualDeckEditorButton); + auto visualDeckStorageButton = new HomeStyledButton("Browse Decks", gradientColors); + connect(visualDeckStorageButton, &QPushButton::clicked, tabSupervisor, + [this] { tabSupervisor->actTabVisualDeckStorage(true); }); + boxLayout->addWidget(visualDeckStorageButton); + auto visualDatabaseDisplayButton = new HomeStyledButton("Browse Card Database", gradientColors); + connect(visualDatabaseDisplayButton, &QPushButton::clicked, tabSupervisor, + &TabSupervisor::addVisualDatabaseDisplayTab); + boxLayout->addWidget(visualDatabaseDisplayButton); + auto edhrecButton = new HomeStyledButton("Browse EDHRec", gradientColors); + connect(edhrecButton, &QPushButton::clicked, tabSupervisor, &TabSupervisor::addEdhrecMainTab); + boxLayout->addWidget(edhrecButton); + auto replaybutton = new HomeStyledButton("View Replays", gradientColors); + connect(replaybutton, &QPushButton::clicked, tabSupervisor, [this] { tabSupervisor->actTabReplays(true); }); + boxLayout->addWidget(replaybutton); + + box->setLayout(boxLayout); + return box; } -QGroupBox *HomeWidget::createPlayButtonGroup(const QString &title) +void HomeWidget::updateConnectButton(const ClientStatus status) { - QGroupBox *box = new QGroupBox(title); - box->setStyleSheet(R"( - QGroupBox { - font-size: 20px; - color: white; /* Title text color */ - background: transparent; + disconnect(connectButton); + switch (status) { + case StatusConnecting: + connectButton->setText("Connecting..."); + connectButton->setEnabled(false); + break; + case StatusDisconnected: + connectButton->setText("Connect"); + connectButton->setEnabled(true); + connect(connectButton, &QPushButton::clicked, qobject_cast(tabSupervisor->parentWidget()), + &MainWindow::actConnect); + break; + case StatusLoggedIn: + connectButton->setText("Play"); + connectButton->setEnabled(true); + connect(connectButton, &QPushButton::clicked, tabSupervisor, + &TabSupervisor::switchToFirstAvailableNetworkTab); + break; + default: + break; } - - QGroupBox::title { - color: white; - subcontrol-origin: margin; - subcontrol-position: top center; /* or top left / right */ - } -)"); - box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - QVBoxLayout *layout = new QVBoxLayout; - layout->setAlignment(Qt::AlignHCenter); // Center widgets horizontally - - auto connectButton = new HomeStyledButton("Connect", gradientColors); - layout->addWidget(connectButton, 1); // stretch factor 1 - - auto playButton = new HomeStyledButton("Play", gradientColors); - layout->addWidget(playButton, 1); - - box->setLayout(layout); - return box; } QPair HomeWidget::extractDominantColors(const QPixmap &pixmap) @@ -241,10 +219,7 @@ void HomeWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); - // Update background if we have a source - if (backgroundSource) { - background = backgroundSource->getProcessedBackground(size()); - } + background = background.scaled(size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); // Draw already-scaled background centered QSize widgetSize = size(); @@ -262,10 +237,5 @@ void HomeWidget::paintEvent(QPaintEvent *event) painter.setRenderHint(QPainter::Antialiasing); painter.fillPath(roundedRectPath, semiTransparentBlack); - // Draw centered overlay image - QSize overlaySize = overlay.size(); - QPoint center((width() - overlaySize.width()) / 2, (height() - overlaySize.height()) / 2); - painter.drawPixmap(center, overlay); - QWidget::paintEvent(event); } diff --git a/cockatrice/src/client/ui/widgets/general/home_widget.h b/cockatrice/src/client/ui/widgets/general/home_widget.h index b3a5c8ee6..29b95fd67 100644 --- a/cockatrice/src/client/ui/widgets/general/home_widget.h +++ b/cockatrice/src/client/ui/widgets/general/home_widget.h @@ -1,7 +1,9 @@ #ifndef HOME_WIDGET_H #define HOME_WIDGET_H +#include "../../../../server/abstract_client.h" #include "../../../tabs/tab_supervisor.h" #include "../cards/card_info_picture_art_crop_widget.h" +#include "home_styled_button.h" #include #include @@ -14,26 +16,25 @@ class HomeWidget : public QWidget public: HomeWidget(QWidget *parent, TabSupervisor *tabSupervisor); - void startCardShuffleTimer(); void updateRandomCard(); - QGroupBox *createSettingsButtonGroup(const QString &title); - QGroupBox *createUpdatesButtonGroup(const QString &title); - QGroupBox *createNavigationButtonGroup(const QString &title); - QGroupBox *createPlayButtonGroup(const QString &title); QPair extractDominantColors(const QPixmap &pixmap); public slots: void paintEvent(QPaintEvent *event) override; + void initializeBackgroundFromSource(); void updateBackgroundProperties(); + QGroupBox *createButtons(); + void updateConnectButton(const ClientStatus status); private: QGridLayout *layout; QTimer *cardChangeTimer; TabSupervisor *tabSupervisor; QPixmap background; - CardInfoPictureArtCropWidget *backgroundSource = nullptr; + CardInfoPictureArtCropWidget *backgroundSourceCard = nullptr; QPixmap overlay; QPair gradientColors; + HomeStyledButton *connectButton; }; #endif // HOME_WIDGET_H diff --git a/cockatrice/src/client/ui/window_main.h b/cockatrice/src/client/ui/window_main.h index 76901c9d4..cf492e8a3 100644 --- a/cockatrice/src/client/ui/window_main.h +++ b/cockatrice/src/client/ui/window_main.h @@ -59,6 +59,7 @@ public slots: void actCheckCardUpdatesBackground(); void actCheckServerUpdates(); void actCheckClientUpdates(); + void actConnect(); private slots: void updateTabMenu(const QList &newMenuList); void statusChanged(ClientStatus _status); @@ -77,7 +78,6 @@ private slots: void localGameEnded(); void pixmapCacheSizeChanged(int newSizeInMBs); void notifyUserAboutUpdate(); - void actConnect(); void actDisconnect(); void actSinglePlayer(); void actWatchReplay(); diff --git a/cockatrice/src/dialogs/dlg_settings.cpp b/cockatrice/src/dialogs/dlg_settings.cpp index 0de11aa48..9f44477cd 100644 --- a/cockatrice/src/dialogs/dlg_settings.cpp +++ b/cockatrice/src/dialogs/dlg_settings.cpp @@ -7,6 +7,7 @@ #include "../client/tabs/tab_supervisor.h" #include "../client/ui/picture_loader/picture_loader.h" #include "../client/ui/theme_manager.h" +#include "../client/ui/widgets/general/background_sources.h" #include "../deck/custom_line_edit.h" #include "../game/cards/card_database.h" #include "../game/cards/card_database_manager.h" @@ -424,10 +425,36 @@ AppearanceSettingsPage::AppearanceSettingsPage() connect(&themeBox, qOverload(&QComboBox::currentIndexChanged), this, &AppearanceSettingsPage::themeBoxChanged); connect(&openThemeButton, &QPushButton::clicked, this, &AppearanceSettingsPage::openThemeLocation); + for (const auto &entry : BackgroundSources::all()) { + homeTabBackgroundSourceBox.addItem(QObject::tr(entry.trKey), QVariant::fromValue(entry.type)); + } + + QString homeTabBackgroundSource = SettingsCache::instance().getHomeTabBackgroundSource(); + int homeTabBackgroundSourceId = + homeTabBackgroundSourceBox.findData(BackgroundSources::fromId(homeTabBackgroundSource)); + if (homeTabBackgroundSourceId != -1) { + homeTabBackgroundSourceBox.setCurrentIndex(homeTabBackgroundSourceId); + } + + connect(&homeTabBackgroundSourceBox, QOverload::of(&QComboBox::currentIndexChanged), this, [this]() { + auto type = homeTabBackgroundSourceBox.currentData().value(); + SettingsCache::instance().setHomeTabBackground(BackgroundSources::toId(type)); + }); + + homeTabBackgroundShuffleFrequencySpinBox.setRange(0, 3600); + homeTabBackgroundShuffleFrequencySpinBox.setSuffix(tr(" seconds")); + homeTabBackgroundShuffleFrequencySpinBox.setValue(SettingsCache::instance().getHomeTabBackgroundShuffleFrequency()); + connect(&homeTabBackgroundShuffleFrequencySpinBox, qOverload(&QSpinBox::valueChanged), + &SettingsCache::instance(), &SettingsCache::setHomeTabBackgroundShuffleFrequency); + auto *themeGrid = new QGridLayout; themeGrid->addWidget(&themeLabel, 0, 0); themeGrid->addWidget(&themeBox, 0, 1); themeGrid->addWidget(&openThemeButton, 1, 1); + themeGrid->addWidget(&homeTabBackgroundSourceLabel, 2, 0); + themeGrid->addWidget(&homeTabBackgroundSourceBox, 2, 1); + themeGrid->addWidget(&homeTabBackgroundShuffleFrequencyLabel, 3, 0); + themeGrid->addWidget(&homeTabBackgroundShuffleFrequencySpinBox, 3, 1); themeGroupBox = new QGroupBox; themeGroupBox->setLayout(themeGrid); @@ -656,6 +683,8 @@ void AppearanceSettingsPage::retranslateUi() themeGroupBox->setTitle(tr("Theme settings")); themeLabel.setText(tr("Current theme:")); openThemeButton.setText(tr("Open themes folder")); + homeTabBackgroundSourceLabel.setText(tr("Home tab background source:")); + homeTabBackgroundShuffleFrequencyLabel.setText(tr("Home tab background shuffle frequency:")); menuGroupBox->setTitle(tr("Menu settings")); showShortcutsCheckBox.setText(tr("Show keyboard shortcuts in right-click menus")); diff --git a/cockatrice/src/dialogs/dlg_settings.h b/cockatrice/src/dialogs/dlg_settings.h index 19677c790..d21bf69a9 100644 --- a/cockatrice/src/dialogs/dlg_settings.h +++ b/cockatrice/src/dialogs/dlg_settings.h @@ -107,6 +107,10 @@ private: QLabel themeLabel; QComboBox themeBox; QPushButton openThemeButton; + QLabel homeTabBackgroundSourceLabel; + QComboBox homeTabBackgroundSourceBox; + QLabel homeTabBackgroundShuffleFrequencyLabel; + QSpinBox homeTabBackgroundShuffleFrequencySpinBox; QLabel minPlayersForMultiColumnLayoutLabel; QLabel maxFontSizeForCardsLabel; QCheckBox showShortcutsCheckBox; diff --git a/cockatrice/src/settings/cache_settings.cpp b/cockatrice/src/settings/cache_settings.cpp index 6bfe04e2f..22f809ddc 100644 --- a/cockatrice/src/settings/cache_settings.cpp +++ b/cockatrice/src/settings/cache_settings.cpp @@ -217,6 +217,9 @@ SettingsCache::SettingsCache() themeName = settings->value("theme/name").toString(); + homeTabBackgroundSource = settings->value("home/background", "themed").toString(); + homeTabBackgroundShuffleFrequency = settings->value("home/background/shuffleTimer", 0).toInt(); + tabVisualDeckStorageOpen = settings->value("tabs/visualDeckStorage", true).toBool(); tabServerOpen = settings->value("tabs/server", true).toBool(); tabAccountOpen = settings->value("tabs/account", true).toBool(); @@ -550,6 +553,20 @@ void SettingsCache::setThemeName(const QString &_themeName) emit themeChanged(); } +void SettingsCache::setHomeTabBackground(const QString &_backgroundSource) +{ + homeTabBackgroundSource = _backgroundSource; + settings->setValue("home/background", homeTabBackgroundSource); + emit homeTabBackgroundSourceChanged(); +} + +void SettingsCache::setHomeTabBackgroundShuffleFrequency(int _frequency) +{ + homeTabBackgroundShuffleFrequency = _frequency; + settings->setValue("home/background/shuffleTimer", homeTabBackgroundShuffleFrequency); + emit homeTabBackgroundShuffleFrequencyChanged(); +} + void SettingsCache::setTabVisualDeckStorageOpen(bool value) { tabVisualDeckStorageOpen = value; diff --git a/cockatrice/src/settings/cache_settings.h b/cockatrice/src/settings/cache_settings.h index ec8b506c5..15d4f33a5 100644 --- a/cockatrice/src/settings/cache_settings.h +++ b/cockatrice/src/settings/cache_settings.h @@ -135,6 +135,8 @@ signals: void picsPathChanged(); void cardDatabasePathChanged(); void themeChanged(); + void homeTabBackgroundSourceChanged(); + void homeTabBackgroundShuffleFrequencyChanged(); void picDownloadChanged(); void showStatusBarChanged(bool state); void displayCardNamesChanged(); @@ -195,7 +197,7 @@ private: QByteArray setsDialogGeometry; QString lang; QString deckPath, filtersPath, replaysPath, picsPath, redirectCachePath, customPicsPath, cardDatabasePath, - customCardDatabasePath, themesPath, spoilerDatabasePath, tokenDatabasePath, themeName; + customCardDatabasePath, themesPath, spoilerDatabasePath, tokenDatabasePath, themeName, homeTabBackgroundSource; bool tabVisualDeckStorageOpen, tabServerOpen, tabAccountOpen, tabDeckStorageOpen, tabReplaysOpen, tabAdminOpen, tabLogOpen; bool checkUpdatesOnStartup; @@ -208,6 +210,7 @@ private: bool notifyAboutNewVersion; bool showTipsOnStartup; QList seenTips; + int homeTabBackgroundShuffleFrequency; bool mbDownloadSpoilers; int updateReleaseChannel; int maxFontSize; @@ -385,6 +388,14 @@ public: { return themeName; } + QString getHomeTabBackgroundSource() const + { + return homeTabBackgroundSource; + } + int getHomeTabBackgroundShuffleFrequency() const + { + return homeTabBackgroundShuffleFrequency; + } bool getTabVisualDeckStorageOpen() const { return tabVisualDeckStorageOpen; @@ -947,6 +958,8 @@ public slots: void setSpoilerDatabasePath(const QString &_spoilerDatabasePath); void setTokenDatabasePath(const QString &_tokenDatabasePath); void setThemeName(const QString &_themeName); + void setHomeTabBackground(const QString &_backgroundSource); + void setHomeTabBackgroundShuffleFrequency(int _frequency); void setTabVisualDeckStorageOpen(bool value); void setTabServerOpen(bool value); void setTabAccountOpen(bool value); diff --git a/dbconverter/src/mocks.cpp b/dbconverter/src/mocks.cpp index ade0922e4..213b42f02 100644 --- a/dbconverter/src/mocks.cpp +++ b/dbconverter/src/mocks.cpp @@ -136,6 +136,12 @@ void SettingsCache::setTokenDatabasePath(const QString & /* _tokenDatabasePath * void SettingsCache::setThemeName(const QString & /* _themeName */) { } +void SettingsCache::setHomeTabBackgroundSource(const QString & /* _backgroundSource */) +{ +} +void SettingsCache::setHomeTabBackgroundShuffleFrequency(int /* frequency */) +{ +} void SettingsCache::setTabVisualDeckStorageOpen(bool /*value*/) { } diff --git a/tests/carddatabase/mocks.cpp b/tests/carddatabase/mocks.cpp index 4c3a81322..08d82d765 100644 --- a/tests/carddatabase/mocks.cpp +++ b/tests/carddatabase/mocks.cpp @@ -140,6 +140,12 @@ void SettingsCache::setTokenDatabasePath(const QString & /* _tokenDatabasePath * void SettingsCache::setThemeName(const QString & /* _themeName */) { } +void SettingsCache::setHomeTabBackgroundSource(const QString & /* _backgroundSource */) +{ +} +void SettingsCache::setHomeTabBackgroundShuffleFrequency(int /* frequency */) +{ +} void SettingsCache::setTabVisualDeckStorageOpen(bool /*value*/) { }