mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 08:22:15 -07:00
make menu actions trigger on triggered
This commit is contained in:
parent
5c889524dc
commit
953bb500c5
2 changed files with 39 additions and 17 deletions
|
|
@ -131,31 +131,31 @@ TabSupervisor::TabSupervisor(AbstractClient *_client, QMenu *tabsMenu, QWidget *
|
||||||
|
|
||||||
aTabVisualDeckStorage = new QAction(this);
|
aTabVisualDeckStorage = new QAction(this);
|
||||||
aTabVisualDeckStorage->setCheckable(true);
|
aTabVisualDeckStorage->setCheckable(true);
|
||||||
connect(aTabVisualDeckStorage, &QAction::toggled, this, &TabSupervisor::actTabVisualDeckStorage);
|
connect(aTabVisualDeckStorage, &QAction::triggered, this, &TabSupervisor::actTabVisualDeckStorage);
|
||||||
|
|
||||||
aTabServer = new QAction(this);
|
aTabServer = new QAction(this);
|
||||||
aTabServer->setCheckable(true);
|
aTabServer->setCheckable(true);
|
||||||
connect(aTabServer, &QAction::toggled, this, &TabSupervisor::actTabServer);
|
connect(aTabServer, &QAction::triggered, this, &TabSupervisor::actTabServer);
|
||||||
|
|
||||||
aTabAccount = new QAction(this);
|
aTabAccount = new QAction(this);
|
||||||
aTabAccount->setCheckable(true);
|
aTabAccount->setCheckable(true);
|
||||||
connect(aTabAccount, &QAction::toggled, this, &TabSupervisor::actTabAccount);
|
connect(aTabAccount, &QAction::triggered, this, &TabSupervisor::actTabAccount);
|
||||||
|
|
||||||
aTabDeckStorage = new QAction(this);
|
aTabDeckStorage = new QAction(this);
|
||||||
aTabDeckStorage->setCheckable(true);
|
aTabDeckStorage->setCheckable(true);
|
||||||
connect(aTabDeckStorage, &QAction::toggled, this, &TabSupervisor::actTabDeckStorage);
|
connect(aTabDeckStorage, &QAction::triggered, this, &TabSupervisor::actTabDeckStorage);
|
||||||
|
|
||||||
aTabReplays = new QAction(this);
|
aTabReplays = new QAction(this);
|
||||||
aTabReplays->setCheckable(true);
|
aTabReplays->setCheckable(true);
|
||||||
connect(aTabReplays, &QAction::toggled, this, &TabSupervisor::actTabReplays);
|
connect(aTabReplays, &QAction::triggered, this, &TabSupervisor::actTabReplays);
|
||||||
|
|
||||||
aTabAdmin = new QAction(this);
|
aTabAdmin = new QAction(this);
|
||||||
aTabAdmin->setCheckable(true);
|
aTabAdmin->setCheckable(true);
|
||||||
connect(aTabAdmin, &QAction::toggled, this, &TabSupervisor::actTabAdmin);
|
connect(aTabAdmin, &QAction::triggered, this, &TabSupervisor::actTabAdmin);
|
||||||
|
|
||||||
aTabLog = new QAction(this);
|
aTabLog = new QAction(this);
|
||||||
aTabLog->setCheckable(true);
|
aTabLog->setCheckable(true);
|
||||||
connect(aTabLog, &QAction::toggled, this, &TabSupervisor::actTabLog);
|
connect(aTabLog, &QAction::triggered, this, &TabSupervisor::actTabLog);
|
||||||
|
|
||||||
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
||||||
&TabSupervisor::refreshShortcuts);
|
&TabSupervisor::refreshShortcuts);
|
||||||
|
|
@ -165,10 +165,7 @@ TabSupervisor::TabSupervisor(AbstractClient *_client, QMenu *tabsMenu, QWidget *
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
|
|
||||||
// open always-available tabs on startup
|
initStartupTabs();
|
||||||
addDeckEditorTab(nullptr);
|
|
||||||
|
|
||||||
aTabVisualDeckStorage->setChecked(SettingsCache::instance().getVisualDeckStorageShowOnLoad());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TabSupervisor::~TabSupervisor()
|
TabSupervisor::~TabSupervisor()
|
||||||
|
|
@ -261,6 +258,29 @@ QString TabSupervisor::sanitizeHtml(QString dirty) const
|
||||||
return dirty.replace("&", "&").replace("<", "<").replace(">", ">").replace("\"", """);
|
return dirty.replace("&", "&").replace("<", "<").replace(">", ">").replace("\"", """);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the action is not in the target checked state, then set it to that state by triggering the action.
|
||||||
|
* If the action is already in the target checked state, then do nothing.
|
||||||
|
*
|
||||||
|
* This allows us to programmatically trigger a QAction::triggered signal for a specific checked state.
|
||||||
|
*/
|
||||||
|
static void checkAndTrigger(QAction *checkableAction, bool checked)
|
||||||
|
{
|
||||||
|
if (checkableAction->isChecked() != checked) {
|
||||||
|
checkableAction->trigger();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the always-available tabs, depending on settings.
|
||||||
|
*/
|
||||||
|
void TabSupervisor::initStartupTabs()
|
||||||
|
{
|
||||||
|
addDeckEditorTab(nullptr);
|
||||||
|
|
||||||
|
checkAndTrigger(aTabVisualDeckStorage, SettingsCache::instance().getVisualDeckStorageShowOnLoad());
|
||||||
|
}
|
||||||
|
|
||||||
int TabSupervisor::myAddTab(Tab *tab)
|
int TabSupervisor::myAddTab(Tab *tab)
|
||||||
{
|
{
|
||||||
connect(tab, &TabGame::userEvent, this, &TabSupervisor::tabUserEvent);
|
connect(tab, &TabGame::userEvent, this, &TabSupervisor::tabUserEvent);
|
||||||
|
|
@ -297,8 +317,8 @@ void TabSupervisor::start(const ServerInfo_User &_userInfo)
|
||||||
tabsMenu->addAction(aTabServer);
|
tabsMenu->addAction(aTabServer);
|
||||||
tabsMenu->addAction(aTabAccount);
|
tabsMenu->addAction(aTabAccount);
|
||||||
|
|
||||||
aTabServer->setChecked(true);
|
checkAndTrigger(aTabServer, SettingsCache::instance().getTabServerOpen());
|
||||||
aTabAccount->setChecked(true);
|
checkAndTrigger(aTabAccount, SettingsCache::instance().getTabAccountOpen());
|
||||||
|
|
||||||
updatePingTime(0, -1);
|
updatePingTime(0, -1);
|
||||||
|
|
||||||
|
|
@ -306,8 +326,8 @@ void TabSupervisor::start(const ServerInfo_User &_userInfo)
|
||||||
tabsMenu->addAction(aTabDeckStorage);
|
tabsMenu->addAction(aTabDeckStorage);
|
||||||
tabsMenu->addAction(aTabReplays);
|
tabsMenu->addAction(aTabReplays);
|
||||||
|
|
||||||
aTabDeckStorage->setChecked(true);
|
checkAndTrigger(aTabDeckStorage, SettingsCache::instance().getTabDeckStorageOpen());
|
||||||
aTabReplays->setChecked(true);
|
checkAndTrigger(aTabReplays, SettingsCache::instance().getTabReplaysOpen());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userInfo->user_level() & ServerInfo_User::IsModerator) {
|
if (userInfo->user_level() & ServerInfo_User::IsModerator) {
|
||||||
|
|
@ -315,8 +335,8 @@ void TabSupervisor::start(const ServerInfo_User &_userInfo)
|
||||||
tabsMenu->addAction(aTabAdmin);
|
tabsMenu->addAction(aTabAdmin);
|
||||||
tabsMenu->addAction(aTabLog);
|
tabsMenu->addAction(aTabLog);
|
||||||
|
|
||||||
aTabAdmin->setChecked(true);
|
checkAndTrigger(aTabAdmin, SettingsCache::instance().getTabAdminOpen());
|
||||||
aTabLog->setChecked(true);
|
checkAndTrigger(aTabLog, SettingsCache::instance().getTabLogOpen());
|
||||||
}
|
}
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,8 @@ private:
|
||||||
QAction *aTabDeckEditor, *aTabVisualDeckStorage, *aTabServer, *aTabAccount, *aTabDeckStorage, *aTabReplays,
|
QAction *aTabDeckEditor, *aTabVisualDeckStorage, *aTabServer, *aTabAccount, *aTabDeckStorage, *aTabReplays,
|
||||||
*aTabAdmin, *aTabLog;
|
*aTabAdmin, *aTabLog;
|
||||||
|
|
||||||
|
void initStartupTabs();
|
||||||
|
|
||||||
int myAddTab(Tab *tab);
|
int myAddTab(Tab *tab);
|
||||||
void addCloseButtonToTab(Tab *tab, int tabIndex);
|
void addCloseButtonToTab(Tab *tab, int tabIndex);
|
||||||
QString sanitizeTabName(QString dirty) const;
|
QString sanitizeTabName(QString dirty) const;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue