mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 08:22:15 -07:00
implement tabs menu
This commit is contained in:
parent
1d614f8548
commit
8218939c30
2 changed files with 186 additions and 32 deletions
|
|
@ -114,8 +114,10 @@ TabSupervisor::TabSupervisor(AbstractClient *_client, QMenu *tabsMenu, QWidget *
|
|||
tabBar()->setStyle(new MacOSTabFixStyle);
|
||||
#endif
|
||||
|
||||
// connect tab changes
|
||||
connect(this, &TabSupervisor::currentChanged, this, &TabSupervisor::updateCurrent);
|
||||
|
||||
// connect client
|
||||
connect(client, &AbstractClient::roomEventReceived, this, &TabSupervisor::processRoomEvent);
|
||||
connect(client, &AbstractClient::gameEventContainerReceived, this, &TabSupervisor::processGameEventContainer);
|
||||
connect(client, &AbstractClient::gameJoinedEventReceived, this, &TabSupervisor::gameJoined);
|
||||
|
|
@ -123,6 +125,40 @@ TabSupervisor::TabSupervisor(AbstractClient *_client, QMenu *tabsMenu, QWidget *
|
|||
connect(client, &AbstractClient::maxPingTime, this, &TabSupervisor::updatePingTime);
|
||||
connect(client, &AbstractClient::notifyUserEventReceived, this, &TabSupervisor::processNotifyUserEvent);
|
||||
|
||||
// create tabs menu actions
|
||||
aTabDeckEditor = new QAction(this);
|
||||
connect(aTabDeckEditor, &QAction::triggered, this, [this] { addDeckEditorTab(nullptr); });
|
||||
|
||||
aTabServer = new QAction(this);
|
||||
aTabServer->setCheckable(true);
|
||||
connect(aTabServer, &QAction::toggled, this, &TabSupervisor::actTabServer);
|
||||
|
||||
aTabUserLists = new QAction(this);
|
||||
aTabUserLists->setCheckable(true);
|
||||
connect(aTabUserLists, &QAction::toggled, this, &TabSupervisor::actTabUserLists);
|
||||
|
||||
aTabDeckStorage = new QAction(this);
|
||||
aTabDeckStorage->setCheckable(true);
|
||||
connect(aTabDeckStorage, &QAction::toggled, this, &TabSupervisor::actTabDeckStorage);
|
||||
|
||||
aTabReplays = new QAction(this);
|
||||
aTabReplays->setCheckable(true);
|
||||
connect(aTabReplays, &QAction::toggled, this, &TabSupervisor::actTabReplays);
|
||||
|
||||
aTabAdmin = new QAction(this);
|
||||
aTabAdmin->setCheckable(true);
|
||||
connect(aTabAdmin, &QAction::toggled, this, &TabSupervisor::actTabAdmin);
|
||||
|
||||
aTabLog = new QAction(this);
|
||||
aTabLog->setCheckable(true);
|
||||
connect(aTabLog, &QAction::toggled, this, &TabSupervisor::actTabLog);
|
||||
|
||||
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
||||
&TabSupervisor::refreshShortcuts);
|
||||
refreshShortcuts();
|
||||
|
||||
resetTabsMenu();
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
|
|
@ -133,6 +169,16 @@ TabSupervisor::~TabSupervisor()
|
|||
|
||||
void TabSupervisor::retranslateUi()
|
||||
{
|
||||
// tab menu actions
|
||||
aTabDeckEditor->setText(tr("Deck Editor"));
|
||||
aTabServer->setText(tr("Server"));
|
||||
aTabUserLists->setText(tr("Account"));
|
||||
aTabDeckStorage->setText(tr("Deck storage"));
|
||||
aTabReplays->setText(tr("Game replays"));
|
||||
aTabAdmin->setText(tr("Administration"));
|
||||
aTabLog->setText(tr("Logs"));
|
||||
|
||||
// tabs
|
||||
QList<Tab *> tabs;
|
||||
tabs.append(tabServer);
|
||||
tabs.append(tabReplays);
|
||||
|
|
@ -166,6 +212,12 @@ void TabSupervisor::retranslateUi()
|
|||
}
|
||||
}
|
||||
|
||||
void TabSupervisor::refreshShortcuts()
|
||||
{
|
||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||
aTabDeckEditor->setShortcuts(shortcuts.getShortcut("MainWindow/aDeckEditor"));
|
||||
}
|
||||
|
||||
bool TabSupervisor::closeRequest()
|
||||
{
|
||||
if (getGameCount()) {
|
||||
|
|
@ -213,52 +265,46 @@ int TabSupervisor::myAddTab(Tab *tab)
|
|||
return idx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the tabs menu to the tabs that are always available
|
||||
*/
|
||||
void TabSupervisor::resetTabsMenu()
|
||||
{
|
||||
tabsMenu->clear();
|
||||
tabsMenu->addAction(aTabDeckEditor);
|
||||
}
|
||||
|
||||
void TabSupervisor::start(const ServerInfo_User &_userInfo)
|
||||
{
|
||||
isLocalGame = false;
|
||||
userInfo = new ServerInfo_User(_userInfo);
|
||||
|
||||
tabServer = new TabServer(this, client);
|
||||
connect(tabServer, &TabServer::roomJoined, this, &TabSupervisor::addRoomTab);
|
||||
myAddTab(tabServer);
|
||||
connect(tabServer, &Tab::destroyed, this, [this] { tabServer = nullptr; });
|
||||
resetTabsMenu();
|
||||
|
||||
tabUserLists = new TabUserLists(this, client, *userInfo);
|
||||
connect(tabUserLists, &TabUserLists::openMessageDialog, this, &TabSupervisor::addMessageTab);
|
||||
connect(tabUserLists, &TabUserLists::userJoined, this, &TabSupervisor::processUserJoined);
|
||||
connect(tabUserLists, &TabUserLists::userLeft, this, &TabSupervisor::processUserLeft);
|
||||
myAddTab(tabUserLists);
|
||||
connect(tabUserLists, &Tab::destroyed, this, [this] { tabUserLists = nullptr; });
|
||||
tabsMenu->addSeparator();
|
||||
tabsMenu->addAction(aTabServer);
|
||||
tabsMenu->addAction(aTabUserLists);
|
||||
|
||||
aTabServer->setChecked(true);
|
||||
aTabUserLists->setChecked(true);
|
||||
|
||||
updatePingTime(0, -1);
|
||||
|
||||
if (userInfo->user_level() & ServerInfo_User::IsRegistered) {
|
||||
tabDeckStorage = new TabDeckStorage(this, client);
|
||||
connect(tabDeckStorage, &TabDeckStorage::openDeckEditor, this, &TabSupervisor::addDeckEditorTab);
|
||||
myAddTab(tabDeckStorage);
|
||||
connect(tabDeckStorage, &Tab::destroyed, this, [this] { tabDeckStorage = nullptr; });
|
||||
tabsMenu->addAction(aTabDeckStorage);
|
||||
tabsMenu->addAction(aTabReplays);
|
||||
|
||||
tabReplays = new TabReplays(this, client);
|
||||
connect(tabReplays, &TabReplays::openReplay, this, &TabSupervisor::openReplay);
|
||||
myAddTab(tabReplays);
|
||||
connect(tabReplays, &Tab::destroyed, this, [this] { tabReplays = nullptr; });
|
||||
} else {
|
||||
tabDeckStorage = 0;
|
||||
tabReplays = 0;
|
||||
aTabDeckStorage->setChecked(true);
|
||||
aTabReplays->setChecked(true);
|
||||
}
|
||||
|
||||
if (userInfo->user_level() & ServerInfo_User::IsModerator) {
|
||||
tabAdmin = new TabAdmin(this, client, (userInfo->user_level() & ServerInfo_User::IsAdmin));
|
||||
connect(tabAdmin, &TabAdmin::adminLockChanged, this, &TabSupervisor::adminLockChanged);
|
||||
myAddTab(tabAdmin);
|
||||
connect(tabAdmin, &Tab::destroyed, this, [this] { tabAdmin = nullptr; });
|
||||
tabsMenu->addSeparator();
|
||||
tabsMenu->addAction(aTabAdmin);
|
||||
tabsMenu->addAction(aTabLog);
|
||||
|
||||
tabLog = new TabLog(this, client);
|
||||
myAddTab(tabLog);
|
||||
connect(tabLog, &Tab::destroyed, this, [this] { tabLog = nullptr; });
|
||||
} else {
|
||||
tabAdmin = 0;
|
||||
tabLog = 0;
|
||||
aTabAdmin->setChecked(true);
|
||||
aTabLog->setChecked(true);
|
||||
}
|
||||
|
||||
retranslateUi();
|
||||
|
|
@ -266,6 +312,8 @@ void TabSupervisor::start(const ServerInfo_User &_userInfo)
|
|||
|
||||
void TabSupervisor::startLocal(const QList<AbstractClient *> &_clients)
|
||||
{
|
||||
resetTabsMenu();
|
||||
|
||||
tabUserLists = 0;
|
||||
tabDeckStorage = 0;
|
||||
tabReplays = 0;
|
||||
|
|
@ -288,6 +336,8 @@ void TabSupervisor::stop()
|
|||
if ((!client) && localClients.isEmpty())
|
||||
return;
|
||||
|
||||
resetTabsMenu();
|
||||
|
||||
if (!localClients.isEmpty()) {
|
||||
for (int i = 0; i < localClients.size(); ++i)
|
||||
localClients[i]->deleteLater();
|
||||
|
|
@ -337,6 +387,97 @@ void TabSupervisor::stop()
|
|||
userInfo = 0;
|
||||
}
|
||||
|
||||
void TabSupervisor::actTabServer(bool checked)
|
||||
{
|
||||
if (checked && !tabServer) {
|
||||
tabServer = new TabServer(this, client);
|
||||
connect(tabServer, &TabServer::roomJoined, this, &TabSupervisor::addRoomTab);
|
||||
myAddTab(tabServer);
|
||||
connect(tabServer, &Tab::destroyed, this, [this] {
|
||||
tabServer = nullptr;
|
||||
aTabServer->setChecked(false);
|
||||
});
|
||||
} else if (!checked && tabServer) {
|
||||
tabServer->closeRequest();
|
||||
}
|
||||
}
|
||||
|
||||
void TabSupervisor::actTabUserLists(bool checked)
|
||||
{
|
||||
if (checked && !tabUserLists) {
|
||||
tabUserLists = new TabUserLists(this, client, *userInfo);
|
||||
connect(tabUserLists, &TabUserLists::openMessageDialog, this, &TabSupervisor::addMessageTab);
|
||||
connect(tabUserLists, &TabUserLists::userJoined, this, &TabSupervisor::processUserJoined);
|
||||
connect(tabUserLists, &TabUserLists::userLeft, this, &TabSupervisor::processUserLeft);
|
||||
myAddTab(tabUserLists);
|
||||
connect(tabUserLists, &Tab::destroyed, this, [this] {
|
||||
tabUserLists = nullptr;
|
||||
aTabUserLists->setChecked(false);
|
||||
});
|
||||
} else if (!checked && tabUserLists) {
|
||||
tabUserLists->closeRequest();
|
||||
}
|
||||
}
|
||||
|
||||
void TabSupervisor::actTabDeckStorage(bool checked)
|
||||
{
|
||||
if (checked && !tabDeckStorage) {
|
||||
tabDeckStorage = new TabDeckStorage(this, client);
|
||||
connect(tabDeckStorage, &TabDeckStorage::openDeckEditor, this, &TabSupervisor::addDeckEditorTab);
|
||||
myAddTab(tabDeckStorage);
|
||||
connect(tabDeckStorage, &Tab::destroyed, this, [this] {
|
||||
tabDeckStorage = nullptr;
|
||||
aTabDeckStorage->setChecked(false);
|
||||
});
|
||||
} else if (!checked && tabDeckStorage) {
|
||||
tabDeckStorage->closeRequest();
|
||||
}
|
||||
}
|
||||
|
||||
void TabSupervisor::actTabReplays(bool checked)
|
||||
{
|
||||
if (checked && !tabReplays) {
|
||||
tabReplays = new TabReplays(this, client);
|
||||
connect(tabReplays, &TabReplays::openReplay, this, &TabSupervisor::openReplay);
|
||||
myAddTab(tabReplays);
|
||||
connect(tabReplays, &Tab::destroyed, this, [this] {
|
||||
tabReplays = nullptr;
|
||||
aTabReplays->setChecked(false);
|
||||
});
|
||||
} else if (!checked && tabReplays) {
|
||||
tabReplays->closeRequest();
|
||||
}
|
||||
}
|
||||
|
||||
void TabSupervisor::actTabAdmin(bool checked)
|
||||
{
|
||||
if (checked && !tabAdmin) {
|
||||
tabAdmin = new TabAdmin(this, client, (userInfo->user_level() & ServerInfo_User::IsAdmin));
|
||||
connect(tabAdmin, &TabAdmin::adminLockChanged, this, &TabSupervisor::adminLockChanged);
|
||||
myAddTab(tabAdmin);
|
||||
connect(tabAdmin, &Tab::destroyed, this, [this] {
|
||||
tabAdmin = nullptr;
|
||||
aTabAdmin->setChecked(false);
|
||||
});
|
||||
} else if (!checked && tabAdmin) {
|
||||
tabAdmin->closeRequest();
|
||||
}
|
||||
}
|
||||
|
||||
void TabSupervisor::actTabLog(bool checked)
|
||||
{
|
||||
if (checked && !tabLog) {
|
||||
tabLog = new TabLog(this, client);
|
||||
myAddTab(tabLog);
|
||||
connect(tabLog, &Tab::destroyed, this, [this] {
|
||||
tabLog = nullptr;
|
||||
aTabAdmin->setChecked(false);
|
||||
});
|
||||
} else if (!checked && tabLog) {
|
||||
tabLog->closeRequest();
|
||||
}
|
||||
}
|
||||
|
||||
void TabSupervisor::updatePingTime(int value, int max)
|
||||
{
|
||||
if (!tabServer)
|
||||
|
|
|
|||
|
|
@ -81,11 +81,15 @@ private:
|
|||
QList<TabGame *> replayTabs;
|
||||
QMap<QString, TabMessage *> messageTabs;
|
||||
QList<TabDeckEditor *> deckEditorTabs;
|
||||
bool isLocalGame;
|
||||
|
||||
QAction *aTabDeckEditor, *aTabServer, *aTabUserLists, *aTabDeckStorage, *aTabReplays, *aTabAdmin, *aTabLog;
|
||||
|
||||
int myAddTab(Tab *tab);
|
||||
void addCloseButtonToTab(Tab *tab, int tabIndex);
|
||||
QString sanitizeTabName(QString dirty) const;
|
||||
QString sanitizeHtml(QString dirty) const;
|
||||
bool isLocalGame;
|
||||
void resetTabsMenu();
|
||||
|
||||
public:
|
||||
explicit TabSupervisor(AbstractClient *_client, QMenu *tabsMenu, QWidget *parent = nullptr);
|
||||
|
|
@ -136,6 +140,15 @@ public slots:
|
|||
void openReplay(GameReplay *replay);
|
||||
void maximizeMainWindow();
|
||||
private slots:
|
||||
void refreshShortcuts();
|
||||
|
||||
void actTabServer(bool checked);
|
||||
void actTabUserLists(bool checked);
|
||||
void actTabDeckStorage(bool checked);
|
||||
void actTabReplays(bool checked);
|
||||
void actTabAdmin(bool checked);
|
||||
void actTabLog(bool checked);
|
||||
|
||||
void updateCurrent(int index);
|
||||
void updatePingTime(int value, int max);
|
||||
void gameJoined(const Event_GameJoined &event);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue