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
This commit is contained in:
RickyRister 2024-11-10 15:16:50 -08:00 committed by GitHub
parent c54f47efbf
commit c2fe3cda35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 64 additions and 6 deletions

View file

@ -765,6 +765,11 @@ void TabDeckEditor::closeRequest()
void TabDeckEditor::actNewDeck() void TabDeckEditor::actNewDeck()
{ {
if (SettingsCache::instance().getOpenDeckInNewTab()) {
emit openDeckEditor(nullptr);
return;
}
if (!confirmClose()) if (!confirmClose())
return; return;
@ -778,7 +783,9 @@ void TabDeckEditor::actNewDeck()
void TabDeckEditor::actLoadDeck() void TabDeckEditor::actLoadDeck()
{ {
if (!confirmClose()) bool openInNewTab = SettingsCache::instance().getOpenDeckInNewTab();
if (!openInNewTab && !confirmClose())
return; return;
QFileDialog dialog(this, tr("Load deck")); QFileDialog dialog(this, tr("Load deck"));
@ -792,8 +799,12 @@ void TabDeckEditor::actLoadDeck()
auto *l = new DeckLoader; auto *l = new DeckLoader;
if (l->loadFromFile(fileName, fmt)) { if (l->loadFromFile(fileName, fmt)) {
setSaveStatus(false); if (openInNewTab) {
setDeck(l); emit openDeckEditor(l);
} else {
setSaveStatus(false);
setDeck(l);
}
} else } else
delete l; delete l;
setSaveStatus(true); setSaveStatus(true);
@ -865,15 +876,22 @@ bool TabDeckEditor::actSaveDeckAs()
void TabDeckEditor::actLoadDeckFromClipboard() void TabDeckEditor::actLoadDeckFromClipboard()
{ {
if (!confirmClose()) bool openInNewTab = SettingsCache::instance().getOpenDeckInNewTab();
if (!openInNewTab && !confirmClose())
return; return;
DlgLoadDeckFromClipboard dlg(this); DlgLoadDeckFromClipboard dlg(this);
if (!dlg.exec()) if (!dlg.exec())
return; return;
setDeck(dlg.getDeckList()); if (openInNewTab) {
setModified(true); emit openDeckEditor(dlg.getDeckList());
} else {
setDeck(dlg.getDeckList());
setModified(true);
}
setSaveStatus(true); setSaveStatus(true);
} }

View file

@ -164,6 +164,7 @@ public:
public slots: public slots:
void closeRequest() override; void closeRequest() override;
signals: signals:
void openDeckEditor(const DeckLoader *deckLoader);
void deckEditorClosing(TabDeckEditor *tab); void deckEditorClosing(TabDeckEditor *tab);
}; };

View file

@ -496,6 +496,7 @@ TabDeckEditor *TabSupervisor::addDeckEditorTab(const DeckLoader *deckToOpen)
if (deckToOpen) if (deckToOpen)
tab->setDeck(new DeckLoader(*deckToOpen)); tab->setDeck(new DeckLoader(*deckToOpen));
connect(tab, SIGNAL(deckEditorClosing(TabDeckEditor *)), this, SLOT(deckEditorClosed(TabDeckEditor *))); connect(tab, SIGNAL(deckEditorClosing(TabDeckEditor *)), this, SLOT(deckEditorClosed(TabDeckEditor *)));
connect(tab, SIGNAL(openDeckEditor(const DeckLoader *)), this, SLOT(addDeckEditorTab(const DeckLoader *)));
int tabIndex = myAddTab(tab); int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex); addCloseButtonToTab(tab, tabIndex);
deckEditorTabs.append(tab); deckEditorTabs.append(tab);

View file

@ -440,6 +440,7 @@ void AppearanceSettingsPage::retranslateUi()
UserInterfaceSettingsPage::UserInterfaceSettingsPage() UserInterfaceSettingsPage::UserInterfaceSettingsPage()
{ {
// general settings and notification settings
notificationsEnabledCheckBox.setChecked(SettingsCache::instance().getNotificationsEnabled()); notificationsEnabledCheckBox.setChecked(SettingsCache::instance().getNotificationsEnabled());
connect(&notificationsEnabledCheckBox, SIGNAL(QT_STATE_CHANGED(QT_STATE_CHANGED_T)), &SettingsCache::instance(), connect(&notificationsEnabledCheckBox, SIGNAL(QT_STATE_CHANGED(QT_STATE_CHANGED_T)), &SettingsCache::instance(),
SLOT(setNotificationsEnabled(QT_STATE_CHANGED_T))); SLOT(setNotificationsEnabled(QT_STATE_CHANGED_T)));
@ -490,6 +491,7 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage()
notificationsGroupBox = new QGroupBox; notificationsGroupBox = new QGroupBox;
notificationsGroupBox->setLayout(notificationsGrid); notificationsGroupBox->setLayout(notificationsGrid);
// animation settings
tapAnimationCheckBox.setChecked(SettingsCache::instance().getTapAnimation()); tapAnimationCheckBox.setChecked(SettingsCache::instance().getTapAnimation());
connect(&tapAnimationCheckBox, SIGNAL(QT_STATE_CHANGED(QT_STATE_CHANGED_T)), &SettingsCache::instance(), connect(&tapAnimationCheckBox, SIGNAL(QT_STATE_CHANGED(QT_STATE_CHANGED_T)), &SettingsCache::instance(),
SLOT(setTapAnimation(QT_STATE_CHANGED_T))); SLOT(setTapAnimation(QT_STATE_CHANGED_T)));
@ -500,10 +502,23 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage()
animationGroupBox = new QGroupBox; animationGroupBox = new QGroupBox;
animationGroupBox->setLayout(animationGrid); 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; auto *mainLayout = new QVBoxLayout;
mainLayout->addWidget(generalGroupBox); mainLayout->addWidget(generalGroupBox);
mainLayout->addWidget(notificationsGroupBox); mainLayout->addWidget(notificationsGroupBox);
mainLayout->addWidget(animationGroupBox); mainLayout->addWidget(animationGroupBox);
mainLayout->addWidget(deckEditorGroupBox);
mainLayout->addStretch(); mainLayout->addStretch();
setLayout(mainLayout); setLayout(mainLayout);
@ -532,6 +547,8 @@ void UserInterfaceSettingsPage::retranslateUi()
buddyConnectNotificationsEnabledCheckBox.setText(tr("Notify in the taskbar when users in your buddy list connect")); buddyConnectNotificationsEnabledCheckBox.setText(tr("Notify in the taskbar when users in your buddy list connect"));
animationGroupBox->setTitle(tr("Animation settings")); animationGroupBox->setTitle(tr("Animation settings"));
tapAnimationCheckBox.setText(tr("&Tap/untap animation")); tapAnimationCheckBox.setText(tr("&Tap/untap animation"));
deckEditorGroupBox->setTitle(tr("Deck editor settings"));
openDeckInNewTabCheckBox.setText(tr("Always open deck in new tab"));
} }
DeckEditorSettingsPage::DeckEditorSettingsPage() DeckEditorSettingsPage::DeckEditorSettingsPage()

View file

@ -124,9 +124,11 @@ private:
QCheckBox annotateTokensCheckBox; QCheckBox annotateTokensCheckBox;
QCheckBox useTearOffMenusCheckBox; QCheckBox useTearOffMenusCheckBox;
QCheckBox tapAnimationCheckBox; QCheckBox tapAnimationCheckBox;
QCheckBox openDeckInNewTabCheckBox;
QGroupBox *generalGroupBox; QGroupBox *generalGroupBox;
QGroupBox *notificationsGroupBox; QGroupBox *notificationsGroupBox;
QGroupBox *animationGroupBox; QGroupBox *animationGroupBox;
QGroupBox *deckEditorGroupBox;
public: public:
UserInterfaceSettingsPage(); UserInterfaceSettingsPage();

View file

@ -243,6 +243,7 @@ SettingsCache::SettingsCache()
invertVerticalCoordinate = settings->value("table/invert_vertical", false).toBool(); invertVerticalCoordinate = settings->value("table/invert_vertical", false).toBool();
minPlayersForMultiColumnLayout = settings->value("interface/min_players_multicolumn", 4).toInt(); minPlayersForMultiColumnLayout = settings->value("interface/min_players_multicolumn", 4).toInt();
tapAnimation = settings->value("cards/tapanimation", true).toBool(); tapAnimation = settings->value("cards/tapanimation", true).toBool();
openDeckInNewTab = settings->value("editor/openDeckInNewTab", false).toBool();
chatMention = settings->value("chat/mention", true).toBool(); chatMention = settings->value("chat/mention", true).toBool();
chatMentionCompleter = settings->value("chat/mentioncompleter", true).toBool(); chatMentionCompleter = settings->value("chat/mentioncompleter", true).toBool();
chatMentionForeground = settings->value("chat/mentionforeground", 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); settings->setValue("cards/tapanimation", tapAnimation);
} }
void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T _openDeckInNewTab)
{
openDeckInNewTab = static_cast<bool>(_openDeckInNewTab);
settings->setValue("editor/openDeckInNewTab", openDeckInNewTab);
}
void SettingsCache::setChatMention(QT_STATE_CHANGED_T _chatMention) void SettingsCache::setChatMention(QT_STATE_CHANGED_T _chatMention)
{ {
chatMention = static_cast<bool>(_chatMention); chatMention = static_cast<bool>(_chatMention);

View file

@ -96,6 +96,7 @@ private:
bool invertVerticalCoordinate; bool invertVerticalCoordinate;
int minPlayersForMultiColumnLayout; int minPlayersForMultiColumnLayout;
bool tapAnimation; bool tapAnimation;
bool openDeckInNewTab;
bool chatMention; bool chatMention;
bool chatMentionCompleter; bool chatMentionCompleter;
QString chatMentionColor; QString chatMentionColor;
@ -295,6 +296,10 @@ public:
{ {
return tapAnimation; return tapAnimation;
} }
bool getOpenDeckInNewTab() const
{
return openDeckInNewTab;
}
bool getChatMention() const bool getChatMention() const
{ {
return chatMention; return chatMention;
@ -538,6 +543,7 @@ public slots:
void setInvertVerticalCoordinate(QT_STATE_CHANGED_T _invertVerticalCoordinate); void setInvertVerticalCoordinate(QT_STATE_CHANGED_T _invertVerticalCoordinate);
void setMinPlayersForMultiColumnLayout(int _minPlayersForMultiColumnLayout); void setMinPlayersForMultiColumnLayout(int _minPlayersForMultiColumnLayout);
void setTapAnimation(QT_STATE_CHANGED_T _tapAnimation); void setTapAnimation(QT_STATE_CHANGED_T _tapAnimation);
void setOpenDeckInNewTab(QT_STATE_CHANGED_T _openDeckInNewTab);
void setChatMention(QT_STATE_CHANGED_T _chatMention); void setChatMention(QT_STATE_CHANGED_T _chatMention);
void setChatMentionCompleter(QT_STATE_CHANGED_T _chatMentionCompleter); void setChatMentionCompleter(QT_STATE_CHANGED_T _chatMentionCompleter);
void setChatMentionForeground(QT_STATE_CHANGED_T _chatMentionForeground); void setChatMentionForeground(QT_STATE_CHANGED_T _chatMentionForeground);

View file

@ -163,6 +163,9 @@ void SettingsCache::setMinPlayersForMultiColumnLayout(int /* _minPlayersForMulti
void SettingsCache::setTapAnimation(QT_STATE_CHANGED_T /* _tapAnimation */) void SettingsCache::setTapAnimation(QT_STATE_CHANGED_T /* _tapAnimation */)
{ {
} }
void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T /* _openDeckInNewTab */)
{
}
void SettingsCache::setChatMention(QT_STATE_CHANGED_T /* _chatMention */) void SettingsCache::setChatMention(QT_STATE_CHANGED_T /* _chatMention */)
{ {
} }

View file

@ -167,6 +167,9 @@ void SettingsCache::setMinPlayersForMultiColumnLayout(int /* _minPlayersForMulti
void SettingsCache::setTapAnimation(QT_STATE_CHANGED_T /* _tapAnimation */) void SettingsCache::setTapAnimation(QT_STATE_CHANGED_T /* _tapAnimation */)
{ {
} }
void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T /* _openDeckInNewTab */)
{
}
void SettingsCache::setChatMention(QT_STATE_CHANGED_T /* _chatMention */) void SettingsCache::setChatMention(QT_STATE_CHANGED_T /* _chatMention */)
{ {
} }