mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 00:42:14 -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);
|
tabBar()->setStyle(new MacOSTabFixStyle);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// connect tab changes
|
||||||
connect(this, &TabSupervisor::currentChanged, this, &TabSupervisor::updateCurrent);
|
connect(this, &TabSupervisor::currentChanged, this, &TabSupervisor::updateCurrent);
|
||||||
|
|
||||||
|
// connect client
|
||||||
connect(client, &AbstractClient::roomEventReceived, this, &TabSupervisor::processRoomEvent);
|
connect(client, &AbstractClient::roomEventReceived, this, &TabSupervisor::processRoomEvent);
|
||||||
connect(client, &AbstractClient::gameEventContainerReceived, this, &TabSupervisor::processGameEventContainer);
|
connect(client, &AbstractClient::gameEventContainerReceived, this, &TabSupervisor::processGameEventContainer);
|
||||||
connect(client, &AbstractClient::gameJoinedEventReceived, this, &TabSupervisor::gameJoined);
|
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::maxPingTime, this, &TabSupervisor::updatePingTime);
|
||||||
connect(client, &AbstractClient::notifyUserEventReceived, this, &TabSupervisor::processNotifyUserEvent);
|
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();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,6 +169,16 @@ TabSupervisor::~TabSupervisor()
|
||||||
|
|
||||||
void TabSupervisor::retranslateUi()
|
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;
|
QList<Tab *> tabs;
|
||||||
tabs.append(tabServer);
|
tabs.append(tabServer);
|
||||||
tabs.append(tabReplays);
|
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()
|
bool TabSupervisor::closeRequest()
|
||||||
{
|
{
|
||||||
if (getGameCount()) {
|
if (getGameCount()) {
|
||||||
|
|
@ -213,52 +265,46 @@ int TabSupervisor::myAddTab(Tab *tab)
|
||||||
return idx;
|
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)
|
void TabSupervisor::start(const ServerInfo_User &_userInfo)
|
||||||
{
|
{
|
||||||
isLocalGame = false;
|
isLocalGame = false;
|
||||||
userInfo = new ServerInfo_User(_userInfo);
|
userInfo = new ServerInfo_User(_userInfo);
|
||||||
|
|
||||||
tabServer = new TabServer(this, client);
|
resetTabsMenu();
|
||||||
connect(tabServer, &TabServer::roomJoined, this, &TabSupervisor::addRoomTab);
|
|
||||||
myAddTab(tabServer);
|
|
||||||
connect(tabServer, &Tab::destroyed, this, [this] { tabServer = nullptr; });
|
|
||||||
|
|
||||||
tabUserLists = new TabUserLists(this, client, *userInfo);
|
tabsMenu->addSeparator();
|
||||||
connect(tabUserLists, &TabUserLists::openMessageDialog, this, &TabSupervisor::addMessageTab);
|
tabsMenu->addAction(aTabServer);
|
||||||
connect(tabUserLists, &TabUserLists::userJoined, this, &TabSupervisor::processUserJoined);
|
tabsMenu->addAction(aTabUserLists);
|
||||||
connect(tabUserLists, &TabUserLists::userLeft, this, &TabSupervisor::processUserLeft);
|
|
||||||
myAddTab(tabUserLists);
|
aTabServer->setChecked(true);
|
||||||
connect(tabUserLists, &Tab::destroyed, this, [this] { tabUserLists = nullptr; });
|
aTabUserLists->setChecked(true);
|
||||||
|
|
||||||
updatePingTime(0, -1);
|
updatePingTime(0, -1);
|
||||||
|
|
||||||
if (userInfo->user_level() & ServerInfo_User::IsRegistered) {
|
if (userInfo->user_level() & ServerInfo_User::IsRegistered) {
|
||||||
tabDeckStorage = new TabDeckStorage(this, client);
|
tabsMenu->addAction(aTabDeckStorage);
|
||||||
connect(tabDeckStorage, &TabDeckStorage::openDeckEditor, this, &TabSupervisor::addDeckEditorTab);
|
tabsMenu->addAction(aTabReplays);
|
||||||
myAddTab(tabDeckStorage);
|
|
||||||
connect(tabDeckStorage, &Tab::destroyed, this, [this] { tabDeckStorage = nullptr; });
|
|
||||||
|
|
||||||
tabReplays = new TabReplays(this, client);
|
aTabDeckStorage->setChecked(true);
|
||||||
connect(tabReplays, &TabReplays::openReplay, this, &TabSupervisor::openReplay);
|
aTabReplays->setChecked(true);
|
||||||
myAddTab(tabReplays);
|
|
||||||
connect(tabReplays, &Tab::destroyed, this, [this] { tabReplays = nullptr; });
|
|
||||||
} else {
|
|
||||||
tabDeckStorage = 0;
|
|
||||||
tabReplays = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userInfo->user_level() & ServerInfo_User::IsModerator) {
|
if (userInfo->user_level() & ServerInfo_User::IsModerator) {
|
||||||
tabAdmin = new TabAdmin(this, client, (userInfo->user_level() & ServerInfo_User::IsAdmin));
|
tabsMenu->addSeparator();
|
||||||
connect(tabAdmin, &TabAdmin::adminLockChanged, this, &TabSupervisor::adminLockChanged);
|
tabsMenu->addAction(aTabAdmin);
|
||||||
myAddTab(tabAdmin);
|
tabsMenu->addAction(aTabLog);
|
||||||
connect(tabAdmin, &Tab::destroyed, this, [this] { tabAdmin = nullptr; });
|
|
||||||
|
|
||||||
tabLog = new TabLog(this, client);
|
aTabAdmin->setChecked(true);
|
||||||
myAddTab(tabLog);
|
aTabLog->setChecked(true);
|
||||||
connect(tabLog, &Tab::destroyed, this, [this] { tabLog = nullptr; });
|
|
||||||
} else {
|
|
||||||
tabAdmin = 0;
|
|
||||||
tabLog = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
|
|
@ -266,6 +312,8 @@ void TabSupervisor::start(const ServerInfo_User &_userInfo)
|
||||||
|
|
||||||
void TabSupervisor::startLocal(const QList<AbstractClient *> &_clients)
|
void TabSupervisor::startLocal(const QList<AbstractClient *> &_clients)
|
||||||
{
|
{
|
||||||
|
resetTabsMenu();
|
||||||
|
|
||||||
tabUserLists = 0;
|
tabUserLists = 0;
|
||||||
tabDeckStorage = 0;
|
tabDeckStorage = 0;
|
||||||
tabReplays = 0;
|
tabReplays = 0;
|
||||||
|
|
@ -288,6 +336,8 @@ void TabSupervisor::stop()
|
||||||
if ((!client) && localClients.isEmpty())
|
if ((!client) && localClients.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
resetTabsMenu();
|
||||||
|
|
||||||
if (!localClients.isEmpty()) {
|
if (!localClients.isEmpty()) {
|
||||||
for (int i = 0; i < localClients.size(); ++i)
|
for (int i = 0; i < localClients.size(); ++i)
|
||||||
localClients[i]->deleteLater();
|
localClients[i]->deleteLater();
|
||||||
|
|
@ -337,6 +387,97 @@ void TabSupervisor::stop()
|
||||||
userInfo = 0;
|
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)
|
void TabSupervisor::updatePingTime(int value, int max)
|
||||||
{
|
{
|
||||||
if (!tabServer)
|
if (!tabServer)
|
||||||
|
|
|
||||||
|
|
@ -81,11 +81,15 @@ private:
|
||||||
QList<TabGame *> replayTabs;
|
QList<TabGame *> replayTabs;
|
||||||
QMap<QString, TabMessage *> messageTabs;
|
QMap<QString, TabMessage *> messageTabs;
|
||||||
QList<TabDeckEditor *> deckEditorTabs;
|
QList<TabDeckEditor *> deckEditorTabs;
|
||||||
|
bool isLocalGame;
|
||||||
|
|
||||||
|
QAction *aTabDeckEditor, *aTabServer, *aTabUserLists, *aTabDeckStorage, *aTabReplays, *aTabAdmin, *aTabLog;
|
||||||
|
|
||||||
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;
|
||||||
QString sanitizeHtml(QString dirty) const;
|
QString sanitizeHtml(QString dirty) const;
|
||||||
bool isLocalGame;
|
void resetTabsMenu();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TabSupervisor(AbstractClient *_client, QMenu *tabsMenu, QWidget *parent = nullptr);
|
explicit TabSupervisor(AbstractClient *_client, QMenu *tabsMenu, QWidget *parent = nullptr);
|
||||||
|
|
@ -136,6 +140,15 @@ public slots:
|
||||||
void openReplay(GameReplay *replay);
|
void openReplay(GameReplay *replay);
|
||||||
void maximizeMainWindow();
|
void maximizeMainWindow();
|
||||||
private slots:
|
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 updateCurrent(int index);
|
||||||
void updatePingTime(int value, int max);
|
void updatePingTime(int value, int max);
|
||||||
void gameJoined(const Event_GameJoined &event);
|
void gameJoined(const Event_GameJoined &event);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue