mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 16:32:16 -07:00
add manager param to add tab methods
This commit is contained in:
parent
68ffa1f7f8
commit
8408ae5052
2 changed files with 34 additions and 13 deletions
|
|
@ -281,7 +281,15 @@ void TabSupervisor::initStartupTabs()
|
||||||
checkAndTrigger(aTabVisualDeckStorage, SettingsCache::instance().getVisualDeckStorageShowOnLoad());
|
checkAndTrigger(aTabVisualDeckStorage, SettingsCache::instance().getVisualDeckStorageShowOnLoad());
|
||||||
}
|
}
|
||||||
|
|
||||||
int TabSupervisor::myAddTab(Tab *tab)
|
/**
|
||||||
|
* Adds the tab to the TabSupervisor's tab bar.
|
||||||
|
*
|
||||||
|
* @param tab The Tab to add
|
||||||
|
* @param manager The menu action that corresponds to this tab, if this is a single-instance managed tab. Pass in
|
||||||
|
* nullptr if this is not a managed tab.
|
||||||
|
* @return The index of the added tab in the tab widget's tab menu
|
||||||
|
*/
|
||||||
|
int TabSupervisor::myAddTab(Tab *tab, QAction *manager)
|
||||||
{
|
{
|
||||||
connect(tab, &TabGame::userEvent, this, &TabSupervisor::tabUserEvent);
|
connect(tab, &TabGame::userEvent, this, &TabSupervisor::tabUserEvent);
|
||||||
connect(tab, &TabGame::tabTextChanged, this, &TabSupervisor::updateTabText);
|
connect(tab, &TabGame::tabTextChanged, this, &TabSupervisor::updateTabText);
|
||||||
|
|
@ -290,17 +298,30 @@ int TabSupervisor::myAddTab(Tab *tab)
|
||||||
int idx = addTab(tab, sanitizeTabName(tabText));
|
int idx = addTab(tab, sanitizeTabName(tabText));
|
||||||
setTabToolTip(idx, sanitizeHtml(tabText));
|
setTabToolTip(idx, sanitizeHtml(tabText));
|
||||||
|
|
||||||
addCloseButtonToTab(tab, idx);
|
addCloseButtonToTab(tab, idx, manager);
|
||||||
|
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabSupervisor::addCloseButtonToTab(Tab *tab, int tabIndex)
|
/**
|
||||||
|
* Adds a usable close button to the tab.
|
||||||
|
*
|
||||||
|
* @param tab The Tab
|
||||||
|
* @param tabIndex The tab bar index of the tab
|
||||||
|
* @param manager The menu action that corresponds to this tab, if this is a single-instance managed tab. Pass in
|
||||||
|
* nullptr if this is not a managed tab.
|
||||||
|
*/
|
||||||
|
void TabSupervisor::addCloseButtonToTab(Tab *tab, int tabIndex, QAction *manager)
|
||||||
{
|
{
|
||||||
auto closeSide = static_cast<QTabBar::ButtonPosition>(
|
auto closeSide = static_cast<QTabBar::ButtonPosition>(
|
||||||
tabBar()->style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, nullptr, tabBar()));
|
tabBar()->style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, nullptr, tabBar()));
|
||||||
auto *closeButton = new CloseButton(tab);
|
auto *closeButton = new CloseButton(tab);
|
||||||
connect(closeButton, &CloseButton::clicked, tab, [tab] { tab->closeRequest(); });
|
if (manager) {
|
||||||
|
// If managed, all close requests should go through the menu action
|
||||||
|
connect(closeButton, &CloseButton::clicked, this, [manager] { checkAndTrigger(manager, false); });
|
||||||
|
} else {
|
||||||
|
connect(closeButton, &CloseButton::clicked, tab, [tab] { tab->closeRequest(); });
|
||||||
|
}
|
||||||
tabBar()->setTabButton(tabIndex, closeSide, closeButton);
|
tabBar()->setTabButton(tabIndex, closeSide, closeButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -432,7 +453,7 @@ void TabSupervisor::actTabVisualDeckStorage(bool checked)
|
||||||
{
|
{
|
||||||
if (checked && !tabVisualDeckStorage) {
|
if (checked && !tabVisualDeckStorage) {
|
||||||
tabVisualDeckStorage = new TabDeckStorageVisual(this, client);
|
tabVisualDeckStorage = new TabDeckStorageVisual(this, client);
|
||||||
myAddTab(tabVisualDeckStorage);
|
myAddTab(tabVisualDeckStorage, aTabVisualDeckStorage);
|
||||||
setCurrentWidget(tabVisualDeckStorage);
|
setCurrentWidget(tabVisualDeckStorage);
|
||||||
connect(tabVisualDeckStorage, &Tab::closed, this, [this] {
|
connect(tabVisualDeckStorage, &Tab::closed, this, [this] {
|
||||||
tabVisualDeckStorage = nullptr;
|
tabVisualDeckStorage = nullptr;
|
||||||
|
|
@ -448,7 +469,7 @@ void TabSupervisor::actTabServer(bool checked)
|
||||||
if (checked && !tabServer) {
|
if (checked && !tabServer) {
|
||||||
tabServer = new TabServer(this, client);
|
tabServer = new TabServer(this, client);
|
||||||
connect(tabServer, &TabServer::roomJoined, this, &TabSupervisor::addRoomTab);
|
connect(tabServer, &TabServer::roomJoined, this, &TabSupervisor::addRoomTab);
|
||||||
myAddTab(tabServer);
|
myAddTab(tabServer, aTabServer);
|
||||||
connect(tabServer, &Tab::closed, this, [this] {
|
connect(tabServer, &Tab::closed, this, [this] {
|
||||||
tabServer = nullptr;
|
tabServer = nullptr;
|
||||||
aTabServer->setChecked(false);
|
aTabServer->setChecked(false);
|
||||||
|
|
@ -465,7 +486,7 @@ void TabSupervisor::actTabAccount(bool checked)
|
||||||
connect(tabAccount, &TabAccount::openMessageDialog, this, &TabSupervisor::addMessageTab);
|
connect(tabAccount, &TabAccount::openMessageDialog, this, &TabSupervisor::addMessageTab);
|
||||||
connect(tabAccount, &TabAccount::userJoined, this, &TabSupervisor::processUserJoined);
|
connect(tabAccount, &TabAccount::userJoined, this, &TabSupervisor::processUserJoined);
|
||||||
connect(tabAccount, &TabAccount::userLeft, this, &TabSupervisor::processUserLeft);
|
connect(tabAccount, &TabAccount::userLeft, this, &TabSupervisor::processUserLeft);
|
||||||
myAddTab(tabAccount);
|
myAddTab(tabAccount, aTabAccount);
|
||||||
connect(tabAccount, &Tab::closed, this, [this] {
|
connect(tabAccount, &Tab::closed, this, [this] {
|
||||||
tabAccount = nullptr;
|
tabAccount = nullptr;
|
||||||
aTabAccount->setChecked(false);
|
aTabAccount->setChecked(false);
|
||||||
|
|
@ -480,7 +501,7 @@ void TabSupervisor::actTabDeckStorage(bool checked)
|
||||||
if (checked && !tabDeckStorage) {
|
if (checked && !tabDeckStorage) {
|
||||||
tabDeckStorage = new TabDeckStorage(this, client);
|
tabDeckStorage = new TabDeckStorage(this, client);
|
||||||
connect(tabDeckStorage, &TabDeckStorage::openDeckEditor, this, &TabSupervisor::addDeckEditorTab);
|
connect(tabDeckStorage, &TabDeckStorage::openDeckEditor, this, &TabSupervisor::addDeckEditorTab);
|
||||||
myAddTab(tabDeckStorage);
|
myAddTab(tabDeckStorage, aTabDeckStorage);
|
||||||
connect(tabDeckStorage, &Tab::closed, this, [this] {
|
connect(tabDeckStorage, &Tab::closed, this, [this] {
|
||||||
tabDeckStorage = nullptr;
|
tabDeckStorage = nullptr;
|
||||||
aTabDeckStorage->setChecked(false);
|
aTabDeckStorage->setChecked(false);
|
||||||
|
|
@ -495,7 +516,7 @@ void TabSupervisor::actTabReplays(bool checked)
|
||||||
if (checked && !tabReplays) {
|
if (checked && !tabReplays) {
|
||||||
tabReplays = new TabReplays(this, client);
|
tabReplays = new TabReplays(this, client);
|
||||||
connect(tabReplays, &TabReplays::openReplay, this, &TabSupervisor::openReplay);
|
connect(tabReplays, &TabReplays::openReplay, this, &TabSupervisor::openReplay);
|
||||||
myAddTab(tabReplays);
|
myAddTab(tabReplays, aTabReplays);
|
||||||
connect(tabReplays, &Tab::closed, this, [this] {
|
connect(tabReplays, &Tab::closed, this, [this] {
|
||||||
tabReplays = nullptr;
|
tabReplays = nullptr;
|
||||||
aTabReplays->setChecked(false);
|
aTabReplays->setChecked(false);
|
||||||
|
|
@ -510,7 +531,7 @@ void TabSupervisor::actTabAdmin(bool checked)
|
||||||
if (checked && !tabAdmin) {
|
if (checked && !tabAdmin) {
|
||||||
tabAdmin = new TabAdmin(this, client, (userInfo->user_level() & ServerInfo_User::IsAdmin));
|
tabAdmin = new TabAdmin(this, client, (userInfo->user_level() & ServerInfo_User::IsAdmin));
|
||||||
connect(tabAdmin, &TabAdmin::adminLockChanged, this, &TabSupervisor::adminLockChanged);
|
connect(tabAdmin, &TabAdmin::adminLockChanged, this, &TabSupervisor::adminLockChanged);
|
||||||
myAddTab(tabAdmin);
|
myAddTab(tabAdmin, aTabAdmin);
|
||||||
connect(tabAdmin, &Tab::closed, this, [this] {
|
connect(tabAdmin, &Tab::closed, this, [this] {
|
||||||
tabAdmin = nullptr;
|
tabAdmin = nullptr;
|
||||||
aTabAdmin->setChecked(false);
|
aTabAdmin->setChecked(false);
|
||||||
|
|
@ -524,7 +545,7 @@ void TabSupervisor::actTabLog(bool checked)
|
||||||
{
|
{
|
||||||
if (checked && !tabLog) {
|
if (checked && !tabLog) {
|
||||||
tabLog = new TabLog(this, client);
|
tabLog = new TabLog(this, client);
|
||||||
myAddTab(tabLog);
|
myAddTab(tabLog, aTabLog);
|
||||||
connect(tabLog, &Tab::closed, this, [this] {
|
connect(tabLog, &Tab::closed, this, [this] {
|
||||||
tabLog = nullptr;
|
tabLog = nullptr;
|
||||||
aTabAdmin->setChecked(false);
|
aTabAdmin->setChecked(false);
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,8 @@ private:
|
||||||
|
|
||||||
void initStartupTabs();
|
void initStartupTabs();
|
||||||
|
|
||||||
int myAddTab(Tab *tab);
|
int myAddTab(Tab *tab, QAction *manager = nullptr);
|
||||||
void addCloseButtonToTab(Tab *tab, int tabIndex);
|
void addCloseButtonToTab(Tab *tab, int tabIndex, QAction *manager);
|
||||||
QString sanitizeTabName(QString dirty) const;
|
QString sanitizeTabName(QString dirty) const;
|
||||||
QString sanitizeHtml(QString dirty) const;
|
QString sanitizeHtml(QString dirty) const;
|
||||||
void resetTabsMenu();
|
void resetTabsMenu();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue