Drop some settings, add some new ones.

Took 19 minutes
This commit is contained in:
Lukas Brübach 2026-08-24 21:42:03 +02:00
parent c2f80abc15
commit 16f792d071
5 changed files with 157 additions and 127 deletions

View file

@ -1,28 +1,27 @@
#include "preferences_setup_page.h" #include "preferences_setup_page.h"
#include "../../client/settings/cache_settings.h" #include "../../client/settings/cache_settings.h"
#include "libcockatrice/settings/appearance_settings.h" #include "../../client/sound_engine.h"
#include "libcockatrice/settings/download_settings.h" #include "libcockatrice/settings/interface_settings.h"
#include "libcockatrice/settings/network_settings.h" #include "libcockatrice/settings/sound_settings.h"
#include "libcockatrice/settings/tabs_settings.h"
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox>
#include <QFormLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QLabel>
#include <QScrollArea> #include <QScrollArea>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <libcockatrice/settings/cards_display_settings.h>
#include <libcockatrice/settings/interface_settings.h>
#include <libcockatrice/settings/personal_settings.h>
#include <libcockatrice/settings/sound_settings.h>
#include <libcockatrice/settings/updates_settings.h>
namespace namespace
{ {
QGroupBox *makeGroup(QWidget *parent, QVBoxLayout *outerLayout) // The server destinations are omitted: during first run their tabs are not
// open yet, and the wizard offers no way to fill in the server/room details.
QList<StartupTab> wizardStartupTabOrder()
{ {
auto *group = new QGroupBox(parent); return {StartupTabHome, StartupTabVisualDeckStorage, StartupTabDeckStorage,
new QVBoxLayout(group); StartupTabReplays, StartupTabDeckEditor, StartupTabVisualDeckEditor};
outerLayout->addWidget(group);
return group;
} }
} // namespace } // namespace
@ -31,45 +30,34 @@ PreferencesSetupPage::PreferencesSetupPage(QWidget *parent) : FirstRunWizardPage
auto *content = new QWidget; auto *content = new QWidget;
auto *contentLayout = new QVBoxLayout(content); auto *contentLayout = new QVBoxLayout(content);
appearanceGroup = makeGroup(content, contentLayout); gameplayGroup = new QGroupBox(content);
styleUserListCheckBox = new QCheckBox(appearanceGroup); auto *gameplayLayout = new QVBoxLayout(gameplayGroup);
cardScalingCheckBox = new QCheckBox(appearanceGroup); contentLayout->addWidget(gameplayGroup);
roundCardCornersCheckBox = new QCheckBox(appearanceGroup);
displayCardNamesCheckBox = new QCheckBox(appearanceGroup);
autoRotateCardsCheckBox = new QCheckBox(appearanceGroup);
tapAnimationCheckBox = new QCheckBox(appearanceGroup);
appearanceGroup->layout()->addWidget(styleUserListCheckBox);
appearanceGroup->layout()->addWidget(cardScalingCheckBox);
appearanceGroup->layout()->addWidget(roundCardCornersCheckBox);
appearanceGroup->layout()->addWidget(displayCardNamesCheckBox);
appearanceGroup->layout()->addWidget(autoRotateCardsCheckBox);
appearanceGroup->layout()->addWidget(tapAnimationCheckBox);
notificationsGroup = makeGroup(content, contentLayout);
notificationsEnabledCheckBox = new QCheckBox(notificationsGroup);
soundEnabledCheckBox = new QCheckBox(notificationsGroup);
notificationsGroup->layout()->addWidget(notificationsEnabledCheckBox);
notificationsGroup->layout()->addWidget(soundEnabledCheckBox);
gameplayGroup = makeGroup(content, contentLayout);
doubleClickToPlayCheckBox = new QCheckBox(gameplayGroup); doubleClickToPlayCheckBox = new QCheckBox(gameplayGroup);
horizontalHandCheckBox = new QCheckBox(gameplayGroup); horizontalHandCheckBox = new QCheckBox(gameplayGroup);
playToStackCheckBox = new QCheckBox(gameplayGroup); playToStackCheckBox = new QCheckBox(gameplayGroup);
gameplayGroup->layout()->addWidget(doubleClickToPlayCheckBox); gameplayLayout->addWidget(doubleClickToPlayCheckBox);
gameplayGroup->layout()->addWidget(horizontalHandCheckBox); gameplayLayout->addWidget(horizontalHandCheckBox);
gameplayGroup->layout()->addWidget(playToStackCheckBox); gameplayLayout->addWidget(playToStackCheckBox);
menuGroup = makeGroup(content, contentLayout); notificationsGroup = new QGroupBox(content);
showShortcutsCheckBox = new QCheckBox(menuGroup); auto *notificationsLayout = new QVBoxLayout(notificationsGroup);
menuGroup->layout()->addWidget(showShortcutsCheckBox); contentLayout->addWidget(notificationsGroup);
notificationsEnabledCheckBox = new QCheckBox(notificationsGroup);
soundEnabledCheckBox = new QCheckBox(notificationsGroup);
notificationsLayout->addWidget(notificationsEnabledCheckBox);
notificationsLayout->addWidget(soundEnabledCheckBox);
dataGroup = makeGroup(content, contentLayout); startupGroup = new QGroupBox(content);
picDownloadCheckBox = new QCheckBox(dataGroup); auto *startupForm = new QFormLayout(startupGroup);
checkUpdatesOnStartupCheckBox = new QCheckBox(dataGroup); contentLayout->addWidget(startupGroup);
showTipsOnStartupCheckBox = new QCheckBox(dataGroup); startupTabLabel = new QLabel(startupGroup);
dataGroup->layout()->addWidget(picDownloadCheckBox); startupTabSelector = new QComboBox(startupGroup);
dataGroup->layout()->addWidget(checkUpdatesOnStartupCheckBox); startupTabSelector->setSizeAdjustPolicy(QComboBox::AdjustToContents);
dataGroup->layout()->addWidget(showTipsOnStartupCheckBox); for (StartupTab tab : wizardStartupTabOrder()) {
startupTabSelector->addItem(QString(), tab); // texts set in retranslateUi
}
startupForm->addRow(startupTabLabel, startupTabSelector);
contentLayout->addStretch(); contentLayout->addStretch();
@ -83,35 +71,23 @@ PreferencesSetupPage::PreferencesSetupPage(QWidget *parent) : FirstRunWizardPage
SettingsCache &settings = SettingsCache::instance(); SettingsCache &settings = SettingsCache::instance();
connect(styleUserListCheckBox, &QCheckBox::toggled, &settings.appearance(), &AppearanceSettings::setStyleUserList);
connect(cardScalingCheckBox, &QCheckBox::toggled, &settings.cardsDisplay(), &CardsDisplaySettings::setCardScaling);
connect(roundCardCornersCheckBox, &QCheckBox::toggled, &settings.cardsDisplay(),
&CardsDisplaySettings::setRoundCardCorners);
connect(displayCardNamesCheckBox, &QCheckBox::toggled, &settings.cardsDisplay(),
&CardsDisplaySettings::setDisplayCardNames);
connect(autoRotateCardsCheckBox, &QCheckBox::toggled, &settings.cardsDisplay(),
&CardsDisplaySettings::setAutoRotateSidewaysLayoutCards);
connect(tapAnimationCheckBox, &QCheckBox::toggled, &settings.cardsDisplay(),
&CardsDisplaySettings::setTapAnimation);
connect(notificationsEnabledCheckBox, &QCheckBox::toggled, &settings.userInterface(),
&InterfaceSettings::setNotificationsEnabled);
connect(soundEnabledCheckBox, &QCheckBox::toggled, &settings.sound(), &SoundSettings::setSoundEnabled);
connect(doubleClickToPlayCheckBox, &QCheckBox::toggled, &settings.userInterface(), connect(doubleClickToPlayCheckBox, &QCheckBox::toggled, &settings.userInterface(),
&InterfaceSettings::setDoubleClickToPlay); &InterfaceSettings::setDoubleClickToPlay);
connect(horizontalHandCheckBox, &QCheckBox::toggled, &settings.userInterface(), connect(horizontalHandCheckBox, &QCheckBox::toggled, &settings.userInterface(),
&InterfaceSettings::setHorizontalHand); &InterfaceSettings::setHorizontalHand);
connect(playToStackCheckBox, &QCheckBox::toggled, &settings.userInterface(), &InterfaceSettings::setPlayToStack); connect(playToStackCheckBox, &QCheckBox::toggled, &settings.userInterface(), &InterfaceSettings::setPlayToStack);
connect(showShortcutsCheckBox, &QCheckBox::toggled, &settings.userInterface(), connect(notificationsEnabledCheckBox, &QCheckBox::toggled, &settings.userInterface(),
&InterfaceSettings::setShowShortcuts); &InterfaceSettings::setNotificationsEnabled);
connect(soundEnabledCheckBox, &QCheckBox::toggled, &settings.sound(), &SoundSettings::setSoundEnabled);
connect(soundEnabledCheckBox, &QCheckBox::toggled, soundEngine, &SoundEngine::testSound);
connect(picDownloadCheckBox, &QCheckBox::toggled, &settings.downloads(), &DownloadSettings::setPicDownload); connect(startupTabSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index) {
connect(checkUpdatesOnStartupCheckBox, &QCheckBox::toggled, &settings.updates(), if (index < 0) {
&UpdatesSettings::setCheckUpdatesOnStartup); return;
connect(showTipsOnStartupCheckBox, &QCheckBox::toggled, &settings.personal(), }
&PersonalSettings::setShowTipsOnStartup); SettingsCache::instance().tabs().setStartupTabIndex(startupTabSelector->itemData(index).toInt());
});
retranslateUi(); retranslateUi();
} }
@ -120,25 +96,14 @@ void PreferencesSetupPage::initializePage()
{ {
SettingsCache &settings = SettingsCache::instance(); SettingsCache &settings = SettingsCache::instance();
styleUserListCheckBox->setChecked(settings.appearance().getStyleUserList());
cardScalingCheckBox->setChecked(settings.cardsDisplay().getScaleCards());
roundCardCornersCheckBox->setChecked(settings.cardsDisplay().getRoundCardCorners());
displayCardNamesCheckBox->setChecked(settings.cardsDisplay().getDisplayCardNames());
autoRotateCardsCheckBox->setChecked(settings.cardsDisplay().getAutoRotateSidewaysLayoutCards());
tapAnimationCheckBox->setChecked(settings.cardsDisplay().getTapAnimation());
notificationsEnabledCheckBox->setChecked(settings.userInterface().getNotificationsEnabled());
soundEnabledCheckBox->setChecked(settings.sound().getSoundEnabled());
doubleClickToPlayCheckBox->setChecked(settings.userInterface().getDoubleClickToPlay()); doubleClickToPlayCheckBox->setChecked(settings.userInterface().getDoubleClickToPlay());
horizontalHandCheckBox->setChecked(settings.userInterface().getHorizontalHand()); horizontalHandCheckBox->setChecked(settings.userInterface().getHorizontalHand());
playToStackCheckBox->setChecked(settings.userInterface().getPlayToStack()); playToStackCheckBox->setChecked(settings.userInterface().getPlayToStack());
showShortcutsCheckBox->setChecked(settings.userInterface().getShowShortcuts()); notificationsEnabledCheckBox->setChecked(settings.userInterface().getNotificationsEnabled());
soundEnabledCheckBox->setChecked(settings.sound().getSoundEnabled());
picDownloadCheckBox->setChecked(settings.downloads().getPicDownload()); startupTabSelector->setCurrentIndex(startupTabSelector->findData(settings.tabs().getStartupTabIndex()));
checkUpdatesOnStartupCheckBox->setChecked(settings.updates().getCheckUpdatesOnStartup());
showTipsOnStartupCheckBox->setChecked(settings.personal().getShowTipsOnStartup());
} }
bool PreferencesSetupPage::isSkippable() const bool PreferencesSetupPage::isSkippable() const
@ -158,30 +123,51 @@ QString PreferencesSetupPage::stepSubtitle() const
void PreferencesSetupPage::retranslateUi() void PreferencesSetupPage::retranslateUi()
{ {
appearanceGroup->setTitle(tr("Appearance")); gameplayGroup->setTitle(tr("Gameplay"));
styleUserListCheckBox->setText(tr("Use the styled user list (avatars, role colours)")); doubleClickToPlayCheckBox->setText(tr("Double-click cards to play them"));
cardScalingCheckBox->setText(tr("Scale cards to fit the window")); doubleClickToPlayCheckBox->setToolTip(tr("When disabled, a single click plays the selected card onto the table."));
roundCardCornersCheckBox->setText(tr("Round card corners")); horizontalHandCheckBox->setText(tr("Display hand horizontally"));
displayCardNamesCheckBox->setText(tr("Display card names on pictured cards")); horizontalHandCheckBox->setToolTip(
autoRotateCardsCheckBox->setText(tr("Auto-rotate sideways layout cards")); tr("Shows your hand as a row along the bottom of the table instead of a column beside it."));
tapAnimationCheckBox->setText(tr("Animate tapping cards")); playToStackCheckBox->setText(tr("Play all nonlands onto the stack by default"));
playToStackCheckBox->setToolTip(
tr("Cards you play appear on the stack so other players can respond to them, as in a tabletop game."));
notificationsGroup->setTitle(tr("Notifications && Sound")); notificationsGroup->setTitle(tr("Notifications && Sound"));
notificationsEnabledCheckBox->setText(tr("Show desktop notifications")); notificationsEnabledCheckBox->setText(tr("Show desktop notifications"));
soundEnabledCheckBox->setText(tr("Play sound effects")); soundEnabledCheckBox->setText(tr("Play sound effects"));
gameplayGroup->setTitle(tr("Gameplay")); startupGroup->setTitle(tr("Startup"));
doubleClickToPlayCheckBox->setText(tr("Double-click a card to play it")); startupTabLabel->setText(tr("Startup tab:"));
horizontalHandCheckBox->setText(tr("Display hand horizontally")); const QList<StartupTab> tabs = wizardStartupTabOrder();
playToStackCheckBox->setText(tr("Play cards to top of stack")); for (int i = 0; i < tabs.size(); ++i) {
QString name;
menuGroup->setTitle(tr("Menus")); switch (tabs[i]) {
showShortcutsCheckBox->setText(tr("Show keyboard shortcuts in menus")); case StartupTabHome:
name = tr("Home");
dataGroup->setTitle(tr("Updates && Data")); break;
picDownloadCheckBox->setText(tr("Automatically download card images")); case StartupTabVisualDeckStorage:
picDownloadCheckBox->setToolTip(tr("Turn this off if you're on a limited connection — " name = tr("Visual Deck Storage");
"card art just won't load until you turn it back on.")); break;
checkUpdatesOnStartupCheckBox->setText(tr("Check for client updates on startup")); case StartupTabDeckStorage:
showTipsOnStartupCheckBox->setText(tr("Show tip of the day on startup")); name = tr("Deck Storage");
} break;
case StartupTabReplays:
name = tr("Game Replays");
break;
case StartupTabDeckEditor:
name = tr("Deck Editor");
break;
case StartupTabVisualDeckEditor:
name = tr("Visual Deck Editor");
break;
case StartupTabServer:
name = tr("Server");
break;
case StartupTabServerRoom:
name = tr("Server Room");
break;
}
startupTabSelector->setItemText(i, name);
}
}

View file

@ -4,7 +4,9 @@
#include "../first_run_wizard_page.h" #include "../first_run_wizard_page.h"
class QCheckBox; class QCheckBox;
class QComboBox;
class QGroupBox; class QGroupBox;
class QLabel;
/** @brief A curated subset of settings for the user to adjust. /** @brief A curated subset of settings for the user to adjust.
**/ **/
@ -22,30 +24,18 @@ public:
void retranslateUi() override; void retranslateUi() override;
private: private:
QGroupBox *appearanceGroup;
QCheckBox *styleUserListCheckBox;
QCheckBox *cardScalingCheckBox;
QCheckBox *roundCardCornersCheckBox;
QCheckBox *displayCardNamesCheckBox;
QCheckBox *autoRotateCardsCheckBox;
QCheckBox *tapAnimationCheckBox;
QGroupBox *notificationsGroup;
QCheckBox *notificationsEnabledCheckBox;
QCheckBox *soundEnabledCheckBox;
QGroupBox *gameplayGroup; QGroupBox *gameplayGroup;
QCheckBox *doubleClickToPlayCheckBox; QCheckBox *doubleClickToPlayCheckBox;
QCheckBox *horizontalHandCheckBox; QCheckBox *horizontalHandCheckBox;
QCheckBox *playToStackCheckBox; QCheckBox *playToStackCheckBox;
QGroupBox *menuGroup; QGroupBox *notificationsGroup;
QCheckBox *showShortcutsCheckBox; QCheckBox *notificationsEnabledCheckBox;
QCheckBox *soundEnabledCheckBox;
QGroupBox *dataGroup; QGroupBox *startupGroup;
QCheckBox *picDownloadCheckBox; QLabel *startupTabLabel;
QCheckBox *checkUpdatesOnStartupCheckBox; QComboBox *startupTabSelector;
QCheckBox *showTipsOnStartupCheckBox;
}; };
#endif // PREFERENCES_SETUP_PAGE_H #endif // PREFERENCES_SETUP_PAGE_H

View file

@ -1,6 +1,16 @@
#include "welcome_page.h" #include "welcome_page.h"
#include "../../../../main.h"
#include "../../client/settings/cache_settings.h"
#include "../../settings_page/general_settings_page.h"
#include "libcockatrice/settings/personal_settings.h"
#include <QApplication>
#include <QComboBox>
#include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <QLocale>
#include <QTranslator>
#include <QVBoxLayout> #include <QVBoxLayout>
WelcomePage::WelcomePage(QWidget *parent) : FirstRunWizardPage(parent) WelcomePage::WelcomePage(QWidget *parent) : FirstRunWizardPage(parent)
@ -9,14 +19,51 @@ WelcomePage::WelcomePage(QWidget *parent) : FirstRunWizardPage(parent)
bodyLabel->setWordWrap(true); bodyLabel->setWordWrap(true);
bodyLabel->setAlignment(Qt::AlignCenter); bodyLabel->setAlignment(Qt::AlignCenter);
languageLabel = new QLabel(this);
langCombo = new QComboBox(this);
for (const QString &code : GeneralSettingsPage::findQmFiles()) {
langCombo->addItem(GeneralSettingsPage::languageName(code), code);
}
QString current = SettingsCache::instance().personal().getLang();
if (current.isEmpty()) {
current = QLocale::system().name();
}
int index = langCombo->findData(current);
if (index < 0) {
index = langCombo->findData(current.section('_', 0, 0));
}
if (index >= 0) {
langCombo->setCurrentIndex(index);
}
connect(langCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &WelcomePage::languageChanged);
auto *languageRow = new QHBoxLayout;
languageRow->addStretch();
languageRow->addWidget(languageLabel);
languageRow->addWidget(langCombo);
languageRow->addStretch();
auto *layout = new QVBoxLayout(this); auto *layout = new QVBoxLayout(this);
layout->addStretch(); layout->addStretch();
layout->addWidget(bodyLabel); layout->addWidget(bodyLabel);
layout->addStretch(); layout->addStretch();
layout->addLayout(languageRow);
retranslateUi(); retranslateUi();
} }
void WelcomePage::languageChanged(int index)
{
if (index < 0) {
return;
}
SettingsCache::instance().personal().setLang(langCombo->itemData(index).toString());
qApp->removeTranslator(translator); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
installNewTranslator();
}
QString WelcomePage::stepTitle() const QString WelcomePage::stepTitle() const
{ {
return tr("Welcome!"); return tr("Welcome!");
@ -28,4 +75,5 @@ void WelcomePage::retranslateUi()
"we'll grab the card database, pick a look you like, " "we'll grab the card database, pick a look you like, "
"and get you ready to connect to a server.\n\n" "and get you ready to connect to a server.\n\n"
"You can change any of this later from Settings.")); "You can change any of this later from Settings."));
} languageLabel->setText(tr("Language:"));
}

View file

@ -3,6 +3,7 @@
#include "../first_run_wizard_page.h" #include "../first_run_wizard_page.h"
class QComboBox;
class QLabel; class QLabel;
class WelcomePage : public FirstRunWizardPage class WelcomePage : public FirstRunWizardPage
@ -15,8 +16,13 @@ public:
QString stepTitle() const override; QString stepTitle() const override;
void retranslateUi() override; void retranslateUi() override;
private slots:
void languageChanged(int index);
private: private:
QLabel *bodyLabel; QLabel *bodyLabel;
QLabel *languageLabel;
QComboBox *langCombo;
}; };
#endif // WELCOME_PAGE_H #endif // WELCOME_PAGE_H

View file

@ -20,6 +20,9 @@ public:
GeneralSettingsPage(); GeneralSettingsPage();
void retranslateUi() override; void retranslateUi() override;
static QStringList findQmFiles();
static QString languageName(const QString &lang);
private slots: private slots:
void deckPathButtonClicked(); void deckPathButtonClicked();
void filtersPathButtonClicked(); void filtersPathButtonClicked();
@ -33,9 +36,6 @@ private slots:
void updateStartupServerControlsVisibility(); void updateStartupServerControlsVisibility();
private: private:
QStringList findQmFiles();
QString languageName(const QString &lang);
QGroupBox *languageGroupBox; QGroupBox *languageGroupBox;
QGroupBox *versionGroupBox; QGroupBox *versionGroupBox;
QGroupBox *cardDatabaseGroupBox; QGroupBox *cardDatabaseGroupBox;