From c2fe3cda35f421d42d68b039c3767a0290d65c41 Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Sun, 10 Nov 2024 15:16:50 -0800 Subject: [PATCH] Add option to open deck in new tab by default (#5143) * add comments * add new setting for openDeckInNewTab * implement open deck in new tab * rename setting * fix typo * set default to false --- .../src/client/tabs/tab_deck_editor.cpp | 30 +++++++++++++++---- cockatrice/src/client/tabs/tab_deck_editor.h | 1 + cockatrice/src/client/tabs/tab_supervisor.cpp | 1 + cockatrice/src/dialogs/dlg_settings.cpp | 17 +++++++++++ cockatrice/src/dialogs/dlg_settings.h | 2 ++ cockatrice/src/settings/cache_settings.cpp | 7 +++++ cockatrice/src/settings/cache_settings.h | 6 ++++ dbconverter/src/mocks.cpp | 3 ++ tests/carddatabase/mocks.cpp | 3 ++ 9 files changed, 64 insertions(+), 6 deletions(-) diff --git a/cockatrice/src/client/tabs/tab_deck_editor.cpp b/cockatrice/src/client/tabs/tab_deck_editor.cpp index c6e4ff758..f2f1b726d 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.cpp +++ b/cockatrice/src/client/tabs/tab_deck_editor.cpp @@ -765,6 +765,11 @@ void TabDeckEditor::closeRequest() void TabDeckEditor::actNewDeck() { + if (SettingsCache::instance().getOpenDeckInNewTab()) { + emit openDeckEditor(nullptr); + return; + } + if (!confirmClose()) return; @@ -778,7 +783,9 @@ void TabDeckEditor::actNewDeck() void TabDeckEditor::actLoadDeck() { - if (!confirmClose()) + bool openInNewTab = SettingsCache::instance().getOpenDeckInNewTab(); + + if (!openInNewTab && !confirmClose()) return; QFileDialog dialog(this, tr("Load deck")); @@ -792,8 +799,12 @@ void TabDeckEditor::actLoadDeck() auto *l = new DeckLoader; if (l->loadFromFile(fileName, fmt)) { - setSaveStatus(false); - setDeck(l); + if (openInNewTab) { + emit openDeckEditor(l); + } else { + setSaveStatus(false); + setDeck(l); + } } else delete l; setSaveStatus(true); @@ -865,15 +876,22 @@ bool TabDeckEditor::actSaveDeckAs() void TabDeckEditor::actLoadDeckFromClipboard() { - if (!confirmClose()) + bool openInNewTab = SettingsCache::instance().getOpenDeckInNewTab(); + + if (!openInNewTab && !confirmClose()) return; DlgLoadDeckFromClipboard dlg(this); if (!dlg.exec()) return; - setDeck(dlg.getDeckList()); - setModified(true); + if (openInNewTab) { + emit openDeckEditor(dlg.getDeckList()); + } else { + setDeck(dlg.getDeckList()); + setModified(true); + } + setSaveStatus(true); } diff --git a/cockatrice/src/client/tabs/tab_deck_editor.h b/cockatrice/src/client/tabs/tab_deck_editor.h index 1b7a795a9..97d01fd92 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.h +++ b/cockatrice/src/client/tabs/tab_deck_editor.h @@ -164,6 +164,7 @@ public: public slots: void closeRequest() override; signals: + void openDeckEditor(const DeckLoader *deckLoader); void deckEditorClosing(TabDeckEditor *tab); }; diff --git a/cockatrice/src/client/tabs/tab_supervisor.cpp b/cockatrice/src/client/tabs/tab_supervisor.cpp index fc6c46728..9ef7ee385 100644 --- a/cockatrice/src/client/tabs/tab_supervisor.cpp +++ b/cockatrice/src/client/tabs/tab_supervisor.cpp @@ -496,6 +496,7 @@ TabDeckEditor *TabSupervisor::addDeckEditorTab(const DeckLoader *deckToOpen) if (deckToOpen) tab->setDeck(new DeckLoader(*deckToOpen)); connect(tab, SIGNAL(deckEditorClosing(TabDeckEditor *)), this, SLOT(deckEditorClosed(TabDeckEditor *))); + connect(tab, SIGNAL(openDeckEditor(const DeckLoader *)), this, SLOT(addDeckEditorTab(const DeckLoader *))); int tabIndex = myAddTab(tab); addCloseButtonToTab(tab, tabIndex); deckEditorTabs.append(tab); diff --git a/cockatrice/src/dialogs/dlg_settings.cpp b/cockatrice/src/dialogs/dlg_settings.cpp index 3467f9404..efdff930a 100644 --- a/cockatrice/src/dialogs/dlg_settings.cpp +++ b/cockatrice/src/dialogs/dlg_settings.cpp @@ -440,6 +440,7 @@ void AppearanceSettingsPage::retranslateUi() UserInterfaceSettingsPage::UserInterfaceSettingsPage() { + // general settings and notification settings notificationsEnabledCheckBox.setChecked(SettingsCache::instance().getNotificationsEnabled()); connect(¬ificationsEnabledCheckBox, SIGNAL(QT_STATE_CHANGED(QT_STATE_CHANGED_T)), &SettingsCache::instance(), SLOT(setNotificationsEnabled(QT_STATE_CHANGED_T))); @@ -490,6 +491,7 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() notificationsGroupBox = new QGroupBox; notificationsGroupBox->setLayout(notificationsGrid); + // animation settings tapAnimationCheckBox.setChecked(SettingsCache::instance().getTapAnimation()); connect(&tapAnimationCheckBox, SIGNAL(QT_STATE_CHANGED(QT_STATE_CHANGED_T)), &SettingsCache::instance(), SLOT(setTapAnimation(QT_STATE_CHANGED_T))); @@ -500,10 +502,23 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() animationGroupBox = new QGroupBox; animationGroupBox->setLayout(animationGrid); + // deck editor settings + openDeckInNewTabCheckBox.setChecked(SettingsCache::instance().getOpenDeckInNewTab()); + connect(&openDeckInNewTabCheckBox, SIGNAL(QT_STATE_CHANGED(QT_STATE_CHANGED_T)), &SettingsCache::instance(), + SLOT(setOpenDeckInNewTab(QT_STATE_CHANGED_T))); + + auto *deckEditorGrid = new QGridLayout; + deckEditorGrid->addWidget(&openDeckInNewTabCheckBox, 0, 0); + + deckEditorGroupBox = new QGroupBox; + deckEditorGroupBox->setLayout(deckEditorGrid); + + // putting it all together auto *mainLayout = new QVBoxLayout; mainLayout->addWidget(generalGroupBox); mainLayout->addWidget(notificationsGroupBox); mainLayout->addWidget(animationGroupBox); + mainLayout->addWidget(deckEditorGroupBox); mainLayout->addStretch(); setLayout(mainLayout); @@ -532,6 +547,8 @@ void UserInterfaceSettingsPage::retranslateUi() buddyConnectNotificationsEnabledCheckBox.setText(tr("Notify in the taskbar when users in your buddy list connect")); animationGroupBox->setTitle(tr("Animation settings")); tapAnimationCheckBox.setText(tr("&Tap/untap animation")); + deckEditorGroupBox->setTitle(tr("Deck editor settings")); + openDeckInNewTabCheckBox.setText(tr("Always open deck in new tab")); } DeckEditorSettingsPage::DeckEditorSettingsPage() diff --git a/cockatrice/src/dialogs/dlg_settings.h b/cockatrice/src/dialogs/dlg_settings.h index 1ab65f9e4..70915cc0e 100644 --- a/cockatrice/src/dialogs/dlg_settings.h +++ b/cockatrice/src/dialogs/dlg_settings.h @@ -124,9 +124,11 @@ private: QCheckBox annotateTokensCheckBox; QCheckBox useTearOffMenusCheckBox; QCheckBox tapAnimationCheckBox; + QCheckBox openDeckInNewTabCheckBox; QGroupBox *generalGroupBox; QGroupBox *notificationsGroupBox; QGroupBox *animationGroupBox; + QGroupBox *deckEditorGroupBox; public: UserInterfaceSettingsPage(); diff --git a/cockatrice/src/settings/cache_settings.cpp b/cockatrice/src/settings/cache_settings.cpp index 3d89286d2..05de9fd48 100644 --- a/cockatrice/src/settings/cache_settings.cpp +++ b/cockatrice/src/settings/cache_settings.cpp @@ -243,6 +243,7 @@ SettingsCache::SettingsCache() invertVerticalCoordinate = settings->value("table/invert_vertical", false).toBool(); minPlayersForMultiColumnLayout = settings->value("interface/min_players_multicolumn", 4).toInt(); tapAnimation = settings->value("cards/tapanimation", true).toBool(); + openDeckInNewTab = settings->value("editor/openDeckInNewTab", false).toBool(); chatMention = settings->value("chat/mention", true).toBool(); chatMentionCompleter = settings->value("chat/mentioncompleter", true).toBool(); chatMentionForeground = settings->value("chat/mentionforeground", true).toBool(); @@ -537,6 +538,12 @@ void SettingsCache::setTapAnimation(QT_STATE_CHANGED_T _tapAnimation) settings->setValue("cards/tapanimation", tapAnimation); } +void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T _openDeckInNewTab) +{ + openDeckInNewTab = static_cast(_openDeckInNewTab); + settings->setValue("editor/openDeckInNewTab", openDeckInNewTab); +} + void SettingsCache::setChatMention(QT_STATE_CHANGED_T _chatMention) { chatMention = static_cast(_chatMention); diff --git a/cockatrice/src/settings/cache_settings.h b/cockatrice/src/settings/cache_settings.h index 7742de3e8..e0bf8b9ed 100644 --- a/cockatrice/src/settings/cache_settings.h +++ b/cockatrice/src/settings/cache_settings.h @@ -96,6 +96,7 @@ private: bool invertVerticalCoordinate; int minPlayersForMultiColumnLayout; bool tapAnimation; + bool openDeckInNewTab; bool chatMention; bool chatMentionCompleter; QString chatMentionColor; @@ -295,6 +296,10 @@ public: { return tapAnimation; } + bool getOpenDeckInNewTab() const + { + return openDeckInNewTab; + } bool getChatMention() const { return chatMention; @@ -538,6 +543,7 @@ public slots: void setInvertVerticalCoordinate(QT_STATE_CHANGED_T _invertVerticalCoordinate); void setMinPlayersForMultiColumnLayout(int _minPlayersForMultiColumnLayout); void setTapAnimation(QT_STATE_CHANGED_T _tapAnimation); + void setOpenDeckInNewTab(QT_STATE_CHANGED_T _openDeckInNewTab); void setChatMention(QT_STATE_CHANGED_T _chatMention); void setChatMentionCompleter(QT_STATE_CHANGED_T _chatMentionCompleter); void setChatMentionForeground(QT_STATE_CHANGED_T _chatMentionForeground); diff --git a/dbconverter/src/mocks.cpp b/dbconverter/src/mocks.cpp index 16c47f0a1..37c1424dc 100644 --- a/dbconverter/src/mocks.cpp +++ b/dbconverter/src/mocks.cpp @@ -163,6 +163,9 @@ void SettingsCache::setMinPlayersForMultiColumnLayout(int /* _minPlayersForMulti void SettingsCache::setTapAnimation(QT_STATE_CHANGED_T /* _tapAnimation */) { } +void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T /* _openDeckInNewTab */) +{ +} void SettingsCache::setChatMention(QT_STATE_CHANGED_T /* _chatMention */) { } diff --git a/tests/carddatabase/mocks.cpp b/tests/carddatabase/mocks.cpp index c3b41037d..112fc9416 100644 --- a/tests/carddatabase/mocks.cpp +++ b/tests/carddatabase/mocks.cpp @@ -167,6 +167,9 @@ void SettingsCache::setMinPlayersForMultiColumnLayout(int /* _minPlayersForMulti void SettingsCache::setTapAnimation(QT_STATE_CHANGED_T /* _tapAnimation */) { } +void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T /* _openDeckInNewTab */) +{ +} void SettingsCache::setChatMention(QT_STATE_CHANGED_T /* _chatMention */) { }