Merge branch 'master' into visual_deck_storage_v2

This commit is contained in:
BruebachL 2025-01-12 19:04:05 +01:00 committed by GitHub
commit b750cc28c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 4377 additions and 3615 deletions

View file

@ -1,6 +1,6 @@
# This script re-signs all apps after CPack packages them. This is necessary because CPack modifies # This script re-signs all apps after CPack packages them. This is necessary because CPack modifies
# the library references used by Cockatrice to App relative paths, invalidating the code signature. # the library references used by Cockatrice to App relative paths, invalidating the code signature.
string(LENGTH $ENV{MACOS_CERTIFICATE_NAME} MACOS_CERTIFICATE_NAME_LEN) string(LENGTH "$ENV{MACOS_CERTIFICATE_NAME}" MACOS_CERTIFICATE_NAME_LEN)
if(APPLE AND MACOS_CERTIFICATE_NAME_LEN GREATER 0) if(APPLE AND MACOS_CERTIFICATE_NAME_LEN GREATER 0)
set(APPLICATIONS "cockatrice" "servatrice" "oracle" "dbconverter") set(APPLICATIONS "cockatrice" "servatrice" "oracle" "dbconverter")

View file

@ -1,13 +1,14 @@
#include "tab.h" #include "tab.h"
#include "../ui/widgets/cards/card_info_display_widget.h" #include "../ui/widgets/cards/card_info_display_widget.h"
#include "./tab_supervisor.h"
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <QScreen> #include <QScreen>
Tab::Tab(TabSupervisor *_tabSupervisor, QWidget *parent) Tab::Tab(TabSupervisor *_tabSupervisor)
: QMainWindow(parent), tabSupervisor(_tabSupervisor), contentsChanged(false), infoPopup(0) : QMainWindow(_tabSupervisor), tabSupervisor(_tabSupervisor), contentsChanged(false), infoPopup(0)
{ {
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
} }

View file

@ -31,7 +31,7 @@ private:
QList<QMenu *> tabMenus; QList<QMenu *> tabMenus;
public: public:
Tab(TabSupervisor *_tabSupervisor, QWidget *parent = nullptr); explicit Tab(TabSupervisor *_tabSupervisor);
const QList<QMenu *> &getTabMenus() const const QList<QMenu *> &getTabMenus() const
{ {
return tabMenus; return tabMenus;
@ -50,7 +50,13 @@ public:
} }
virtual QString getTabText() const = 0; virtual QString getTabText() const = 0;
virtual void retranslateUi() = 0; virtual void retranslateUi() = 0;
virtual void closeRequest() /**
* Sends a request to close the tab.
* Signals for cleanup should be emitted from this method instead of the destructor.
*
* @param forced whether this close request was initiated by the user or forced by the server.
*/
virtual void closeRequest(bool /*forced*/ = false)
{ {
} }
virtual void tabActivated() virtual void tabActivated()

View file

@ -18,11 +18,8 @@
#include <QPushButton> #include <QPushButton>
#include <QVBoxLayout> #include <QVBoxLayout>
TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor, TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &userInfo)
AbstractClient *_client, : Tab(_tabSupervisor), client(_client)
const ServerInfo_User &userInfo,
QWidget *parent)
: Tab(_tabSupervisor, parent), client(_client)
{ {
allUsersList = new UserList(_tabSupervisor, client, UserList::AllUsersList); allUsersList = new UserList(_tabSupervisor, client, UserList::AllUsersList);
buddyList = new UserList(_tabSupervisor, client, UserList::BuddyList); buddyList = new UserList(_tabSupervisor, client, UserList::BuddyList);

View file

@ -46,12 +46,9 @@ private:
void addToList(const std::string &listName, const QString &userName); void addToList(const std::string &listName, const QString &userName);
public: public:
TabUserLists(TabSupervisor *_tabSupervisor, TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &userInfo);
AbstractClient *_client, void retranslateUi() override;
const ServerInfo_User &userInfo, QString getTabText() const override
QWidget *parent = nullptr);
void retranslateUi();
QString getTabText() const
{ {
return tr("Account"); return tr("Account");
} }

View file

@ -54,8 +54,8 @@ int ShutdownDialog::getMinutes() const
return minutesEdit->value(); return minutesEdit->value();
} }
TabAdmin::TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, bool _fullAdmin, QWidget *parent) TabAdmin::TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, bool _fullAdmin)
: Tab(_tabSupervisor, parent), locked(true), client(_client), fullAdmin(_fullAdmin) : Tab(_tabSupervisor), locked(true), client(_client), fullAdmin(_fullAdmin)
{ {
updateServerMessageButton = new QPushButton; updateServerMessageButton = new QPushButton;
connect(updateServerMessageButton, &QPushButton::clicked, this, &TabAdmin::actUpdateServerMessage); connect(updateServerMessageButton, &QPushButton::clicked, this, &TabAdmin::actUpdateServerMessage);

View file

@ -22,7 +22,7 @@ private:
QSpinBox *minutesEdit; QSpinBox *minutesEdit;
public: public:
ShutdownDialog(QWidget *parent = nullptr); explicit ShutdownDialog(QWidget *parent = nullptr);
QString getReason() const; QString getReason() const;
int getMinutes() const; int getMinutes() const;
}; };
@ -54,9 +54,9 @@ private slots:
void actLock(); void actLock();
public: public:
TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, bool _fullAdmin, QWidget *parent = nullptr); TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, bool _fullAdmin);
void retranslateUi(); void retranslateUi() override;
QString getTabText() const QString getTabText() const override
{ {
return tr("Administration"); return tr("Administration");
} }

View file

@ -358,7 +358,7 @@ void TabDeckEditor::createMenus()
analyzeDeckMenu->addAction(aAnalyzeDeckTappedout); analyzeDeckMenu->addAction(aAnalyzeDeckTappedout);
aClose = new QAction(QString(), this); aClose = new QAction(QString(), this);
connect(aClose, SIGNAL(triggered()), this, SLOT(closeRequest())); connect(aClose, &QAction::triggered, this, [this] { closeRequest(); });
aClearFilterAll = new QAction(QString(), this); aClearFilterAll = new QAction(QString(), this);
aClearFilterAll->setIcon(QPixmap("theme:icons/clearsearch")); aClearFilterAll->setIcon(QPixmap("theme:icons/clearsearch"));
@ -698,8 +698,7 @@ void TabDeckEditor::loadLayout()
QTimer::singleShot(100, this, SLOT(freeDocksSize())); QTimer::singleShot(100, this, SLOT(freeDocksSize()));
} }
TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent) TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor) : Tab(_tabSupervisor), modified(false)
: Tab(_tabSupervisor, parent), modified(false)
{ {
setObjectName("TabDeckEditor"); setObjectName("TabDeckEditor");
@ -721,11 +720,6 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
loadLayout(); loadLayout();
} }
TabDeckEditor::~TabDeckEditor()
{
emit deckEditorClosing(this);
}
void TabDeckEditor::retranslateUi() void TabDeckEditor::retranslateUi()
{ {
cardInfo->retranslateUi(); cardInfo->retranslateUi();
@ -987,10 +981,14 @@ bool TabDeckEditor::confirmClose()
return true; return true;
} }
void TabDeckEditor::closeRequest() void TabDeckEditor::closeRequest(bool forced)
{ {
if (confirmClose()) if (!forced && !confirmClose()) {
deleteLater(); return;
}
emit deckEditorClosing(this);
close();
} }
void TabDeckEditor::actNewDeck() void TabDeckEditor::actNewDeck()

View file

@ -163,8 +163,7 @@ private:
QWidget *centralWidget; QWidget *centralWidget;
public: public:
explicit TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent = nullptr); explicit TabDeckEditor(TabSupervisor *_tabSupervisor);
~TabDeckEditor() override;
void retranslateUi() override; void retranslateUi() override;
QString getTabText() const override; QString getTabText() const override;
void setDeck(DeckLoader *_deckLoader); void setDeck(DeckLoader *_deckLoader);
@ -179,7 +178,7 @@ public:
void updateCardInfo(CardInfoPtr _card); void updateCardInfo(CardInfoPtr _card);
public slots: public slots:
void closeRequest() override; void closeRequest(bool forced = false) override;
void showPrintingSelector(); void showPrintingSelector();
signals: signals:
void openDeckEditor(const DeckLoader *deckLoader); void openDeckEditor(const DeckLoader *deckLoader);

View file

@ -64,8 +64,8 @@ private slots:
public: public:
TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client); TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client);
void retranslateUi(); void retranslateUi() override;
QString getTabText() const QString getTabText() const override
{ {
return tr("Deck storage"); return tr("Deck storage");
} }

View file

@ -164,7 +164,7 @@ void DeckViewContainer::retranslateUi()
{ {
loadLocalButton->setText(tr("Load deck...")); loadLocalButton->setText(tr("Load deck..."));
loadRemoteButton->setText(tr("Load remote deck...")); loadRemoteButton->setText(tr("Load remote deck..."));
unloadDeckButton->setText(tr("Unload deck...")); unloadDeckButton->setText(tr("Unload deck"));
readyStartButton->setText(tr("Ready to start")); readyStartButton->setText(tr("Ready to start"));
forceStartGameButton->setText(tr("Force start")); forceStartGameButton->setText(tr("Force start"));
updateSideboardLockButtonText(); updateSideboardLockButtonText();
@ -581,16 +581,14 @@ void TabGame::emitUserEvent()
TabGame::~TabGame() TabGame::~TabGame()
{ {
scene->clearViews();
delete replay; delete replay;
QMapIterator<int, Player *> i(players); QMapIterator<int, Player *> i(players);
while (i.hasNext()) { while (i.hasNext()) {
delete i.next().value(); delete i.next().value();
} }
players.clear();
emit gameClosing(this);
} }
void TabGame::updatePlayerListDockTitle() void TabGame::updatePlayerListDockTitle()
@ -701,9 +699,15 @@ void TabGame::retranslateUi()
scene->retranslateUi(); scene->retranslateUi();
} }
void TabGame::closeRequest() void TabGame::closeRequest(bool forced)
{ {
actLeaveGame(); if (!forced && !leaveGame()) {
return;
}
emit gameClosing(this);
close();
} }
void TabGame::replayNextEvent(Player::EventProcessingOptions options) void TabGame::replayNextEvent(Player::EventProcessingOptions options)
@ -794,19 +798,23 @@ void TabGame::actConcede()
} }
} }
void TabGame::actLeaveGame() /**
* Confirms the leave game and sends the leave game command, if applicable.
*
* @return True if the leave game is confirmed
*/
bool TabGame::leaveGame()
{ {
if (!gameClosed) { if (!gameClosed) {
if (!spectator) if (!spectator)
if (QMessageBox::question(this, tr("Leave game"), tr("Are you sure you want to leave this game?"), if (QMessageBox::question(this, tr("Leave game"), tr("Are you sure you want to leave this game?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
return; return false;
if (!replay) if (!replay)
sendGameCommand(Command_LeaveGame()); sendGameCommand(Command_LeaveGame());
} }
scene->clearViews(); return true;
deleteLater();
} }
void TabGame::actSay() void TabGame::actSay()
@ -1598,7 +1606,7 @@ void TabGame::createMenuItems()
aConcede = new QAction(this); aConcede = new QAction(this);
connect(aConcede, SIGNAL(triggered()), this, SLOT(actConcede())); connect(aConcede, SIGNAL(triggered()), this, SLOT(actConcede()));
aLeaveGame = new QAction(this); aLeaveGame = new QAction(this);
connect(aLeaveGame, SIGNAL(triggered()), this, SLOT(actLeaveGame())); connect(aLeaveGame, &QAction::triggered, this, [this] { closeRequest(); });
aFocusChat = new QAction(this); aFocusChat = new QAction(this);
connect(aFocusChat, SIGNAL(triggered()), sayEdit, SLOT(setFocus())); connect(aFocusChat, SIGNAL(triggered()), sayEdit, SLOT(setFocus()));
aCloseReplay = nullptr; aCloseReplay = nullptr;
@ -1648,7 +1656,7 @@ void TabGame::createReplayMenuItems()
aFocusChat = nullptr; aFocusChat = nullptr;
aLeaveGame = nullptr; aLeaveGame = nullptr;
aCloseReplay = new QAction(this); aCloseReplay = new QAction(this);
connect(aCloseReplay, SIGNAL(triggered()), this, SLOT(actLeaveGame())); connect(aCloseReplay, &QAction::triggered, this, [this] { closeRequest(); });
phasesMenu = nullptr; phasesMenu = nullptr;
gameMenu = new QMenu(this); gameMenu = new QMenu(this);

View file

@ -72,7 +72,7 @@ signals:
void stateChanged(); void stateChanged();
public: public:
ToggleButton(QWidget *parent = nullptr); explicit ToggleButton(QWidget *parent = nullptr);
bool getState() const bool getState() const
{ {
return state; return state;
@ -80,7 +80,7 @@ public:
void setState(bool _state); void setState(bool _state);
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event) override;
}; };
class DeckViewContainer : public QWidget class DeckViewContainer : public QWidget
@ -189,6 +189,7 @@ private:
void startGame(bool resuming); void startGame(bool resuming);
void stopGame(); void stopGame();
void closeGame(); void closeGame();
bool leaveGame();
void eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext &context); void eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext &context);
void eventSpectatorLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context); void eventSpectatorLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context);
@ -242,7 +243,6 @@ private slots:
void actGameInfo(); void actGameInfo();
void actConcede(); void actConcede();
void actLeaveGame();
void actRemoveLocalArrows(); void actRemoveLocalArrows();
void actRotateViewCW(); void actRotateViewCW();
void actRotateViewCCW(); void actRotateViewCCW();
@ -278,7 +278,7 @@ public:
~TabGame() override; ~TabGame() override;
void retranslateUi() override; void retranslateUi() override;
void updatePlayerListDockTitle(); void updatePlayerListDockTitle();
void closeRequest() override; void closeRequest(bool forced = false) override;
const QMap<int, Player *> &getPlayers() const const QMap<int, Player *> &getPlayers() const
{ {
return players; return players;

View file

@ -21,8 +21,7 @@
#include <QtGui> #include <QtGui>
#include <QtWidgets> #include <QtWidgets>
TabLog::TabLog(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent) TabLog::TabLog(TabSupervisor *_tabSupervisor, AbstractClient *_client) : Tab(_tabSupervisor), client(_client)
: Tab(_tabSupervisor, parent), client(_client)
{ {
roomTable = new QTableWidget(); roomTable = new QTableWidget();
roomTable->setColumnCount(6); roomTable->setColumnCount(6);

View file

@ -53,10 +53,10 @@ private slots:
void restartLayout(); void restartLayout();
public: public:
TabLog(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent = nullptr); TabLog(TabSupervisor *_tabSupervisor, AbstractClient *_client);
~TabLog(); ~TabLog() override;
void retranslateUi(); void retranslateUi() override;
QString getTabText() const QString getTabText() const override
{ {
return tr("Logs"); return tr("Logs");
} }

View file

@ -38,7 +38,7 @@ TabMessage::TabMessage(TabSupervisor *_tabSupervisor,
vbox->addWidget(sayEdit); vbox->addWidget(sayEdit);
aLeave = new QAction(this); aLeave = new QAction(this);
connect(aLeave, SIGNAL(triggered()), this, SLOT(actLeave())); connect(aLeave, &QAction::triggered, this, [this] { closeRequest(); });
messageMenu = new QMenu(this); messageMenu = new QMenu(this);
messageMenu->addAction(aLeave); messageMenu->addAction(aLeave);
@ -53,7 +53,6 @@ TabMessage::TabMessage(TabSupervisor *_tabSupervisor,
TabMessage::~TabMessage() TabMessage::~TabMessage()
{ {
emit talkClosing(this);
delete ownUserInfo; delete ownUserInfo;
delete otherUserInfo; delete otherUserInfo;
} }
@ -86,9 +85,10 @@ QString TabMessage::getTabText() const
return tr("%1 - Private chat").arg(QString::fromStdString(otherUserInfo->name())); return tr("%1 - Private chat").arg(QString::fromStdString(otherUserInfo->name()));
} }
void TabMessage::closeRequest() void TabMessage::closeRequest(bool /*forced*/)
{ {
actLeave(); emit talkClosing(this);
close();
} }
void TabMessage::sendMessage() void TabMessage::sendMessage()
@ -114,11 +114,6 @@ void TabMessage::messageSent(const Response &response)
"This user is ignoring you, they cannot see your messages in main chat and you cannot join their games.")); "This user is ignoring you, they cannot see your messages in main chat and you cannot join their games."));
} }
void TabMessage::actLeave()
{
deleteLater();
}
void TabMessage::processUserMessageEvent(const Event_UserMessage &event) void TabMessage::processUserMessageEvent(const Event_UserMessage &event)
{ {
auto userInfo = event.sender_name() == otherUserInfo->name() ? otherUserInfo : ownUserInfo; auto userInfo = event.sender_name() == otherUserInfo->name() ? otherUserInfo : ownUserInfo;

View file

@ -29,7 +29,6 @@ signals:
void maximizeClient(); void maximizeClient();
private slots: private slots:
void sendMessage(); void sendMessage();
void actLeave();
void messageSent(const Response &response); void messageSent(const Response &response);
void addMentionTag(QString mentionTag); void addMentionTag(QString mentionTag);
void messageClicked(); void messageClicked();
@ -39,12 +38,12 @@ public:
AbstractClient *_client, AbstractClient *_client,
const ServerInfo_User &_ownUserInfo, const ServerInfo_User &_ownUserInfo,
const ServerInfo_User &_otherUserInfo); const ServerInfo_User &_otherUserInfo);
~TabMessage(); ~TabMessage() override;
void retranslateUi(); void retranslateUi() override;
void closeRequest(); void closeRequest(bool forced = false) override;
void tabActivated(); void tabActivated() override;
QString getUserName() const; QString getUserName() const;
QString getTabText() const; QString getTabText() const override;
void processUserMessageEvent(const Event_UserMessage &event); void processUserMessageEvent(const Event_UserMessage &event);

View file

@ -59,8 +59,8 @@ signals:
public: public:
TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client); TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client);
void retranslateUi(); void retranslateUi() override;
QString getTabText() const QString getTabText() const override
{ {
return tr("Game replays"); return tr("Game replays");
} }

View file

@ -101,7 +101,7 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor,
hbox->addWidget(userList, 1); hbox->addWidget(userList, 1);
aLeaveRoom = new QAction(this); aLeaveRoom = new QAction(this);
connect(aLeaveRoom, SIGNAL(triggered()), this, SLOT(actLeaveRoom())); connect(aLeaveRoom, &QAction::triggered, this, [this] { closeRequest(); });
roomMenu = new QMenu(this); roomMenu = new QMenu(this);
roomMenu->addAction(aLeaveRoom); roomMenu->addAction(aLeaveRoom);
@ -135,11 +135,6 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor,
setCentralWidget(mainWidget); setCentralWidget(mainWidget);
} }
TabRoom::~TabRoom()
{
emit roomClosing(this);
}
void TabRoom::retranslateUi() void TabRoom::retranslateUi()
{ {
gameSelector->retranslateUi(); gameSelector->retranslateUi();
@ -175,9 +170,11 @@ void TabRoom::actShowPopup(const QString &message)
} }
} }
void TabRoom::closeRequest() void TabRoom::closeRequest(bool /*forced*/)
{ {
actLeaveRoom(); sendRoomCommand(prepareRoomCommand(Command_LeaveRoom()));
emit roomClosing(this);
close();
} }
void TabRoom::tabActivated() void TabRoom::tabActivated()
@ -216,12 +213,6 @@ void TabRoom::sayFinished(const Response &response)
chatView->appendMessage(tr("You are flooding the chat. Please wait a couple of seconds.")); chatView->appendMessage(tr("You are flooding the chat. Please wait a couple of seconds."));
} }
void TabRoom::actLeaveRoom()
{
sendRoomCommand(prepareRoomCommand(Command_LeaveRoom()));
deleteLater();
}
void TabRoom::actClearChat() void TabRoom::actClearChat()
{ {
chatView->clearChat(); chatView->clearChat();

View file

@ -70,7 +70,6 @@ signals:
private slots: private slots:
void sendMessage(); void sendMessage();
void sayFinished(const Response &response); void sayFinished(const Response &response);
void actLeaveRoom();
void actClearChat(); void actClearChat();
void actOpenChatSettings(); void actOpenChatSettings();
void addMentionTag(QString mentionTag); void addMentionTag(QString mentionTag);
@ -91,10 +90,9 @@ public:
AbstractClient *_client, AbstractClient *_client,
ServerInfo_User *_ownUser, ServerInfo_User *_ownUser,
const ServerInfo_Room &info); const ServerInfo_Room &info);
~TabRoom(); void retranslateUi() override;
void retranslateUi(); void closeRequest(bool forced = false) override;
void closeRequest(); void tabActivated() override;
void tabActivated();
void processRoomEvent(const RoomEvent &event); void processRoomEvent(const RoomEvent &event);
int getRoomId() const int getRoomId() const
{ {
@ -108,7 +106,7 @@ public:
{ {
return roomName; return roomName;
} }
QString getTabText() const QString getTabText() const override
{ {
return roomName; return roomName;
} }

View file

@ -138,8 +138,7 @@ void RoomSelector::joinClicked()
emit joinRoomRequest(id, true); emit joinRoomRequest(id, true);
} }
TabServer::TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent) TabServer::TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client) : Tab(_tabSupervisor), client(_client)
: Tab(_tabSupervisor, parent), client(_client)
{ {
roomSelector = new RoomSelector(client); roomSelector = new RoomSelector(client);
serverInfoBox = new QTextBrowser; serverInfoBox = new QTextBrowser;

View file

@ -34,7 +34,7 @@ signals:
void joinRoomRequest(int, bool setCurrent); void joinRoomRequest(int, bool setCurrent);
public: public:
RoomSelector(AbstractClient *_client, QWidget *parent = nullptr); explicit RoomSelector(AbstractClient *_client, QWidget *parent = nullptr);
void retranslateUi(); void retranslateUi();
}; };
@ -55,9 +55,9 @@ private:
bool shouldEmitUpdate = false; bool shouldEmitUpdate = false;
public: public:
TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent = nullptr); TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client);
void retranslateUi(); void retranslateUi() override;
QString getTabText() const QString getTabText() const override
{ {
return tr("Server"); return tr("Server");
} }

View file

@ -304,29 +304,26 @@ void TabSupervisor::stop()
tabAdmin = 0; tabAdmin = 0;
tabLog = 0; tabLog = 0;
for (const auto tab : deckEditorTabs) { QList<Tab *> tabsToDelete;
disconnect(tab, nullptr, this, nullptr);
tab->deleteLater();
}
deckEditorTabs.clear();
for (auto i = roomTabs.cbegin(), end = roomTabs.cend(); i != end; ++i) { for (auto i = roomTabs.cbegin(), end = roomTabs.cend(); i != end; ++i) {
disconnect(i.value(), nullptr, this, nullptr); tabsToDelete << i.value();
i.value()->deleteLater();
} }
roomTabs.clear(); roomTabs.clear();
for (auto i = gameTabs.cbegin(), end = gameTabs.cend(); i != end; ++i) { for (auto i = gameTabs.cbegin(), end = gameTabs.cend(); i != end; ++i) {
disconnect(i.value(), nullptr, this, nullptr); tabsToDelete << i.value();
i.value()->deleteLater();
} }
gameTabs.clear(); gameTabs.clear();
for (const auto tab : replayTabs) { for (auto i = messageTabs.cbegin(), end = messageTabs.cend(); i != end; ++i) {
disconnect(tab, nullptr, this, nullptr); tabsToDelete << i.value();
tab->deleteLater(); }
messageTabs.clear();
for (const auto tab : tabsToDelete) {
tab->closeRequest(true);
} }
replayTabs.clear();
delete userInfo; delete userInfo;
userInfo = 0; userInfo = 0;
@ -342,19 +339,12 @@ void TabSupervisor::updatePingTime(int value, int max)
setTabIcon(indexOf(tabServer), QIcon(PingPixmapGenerator::generatePixmap(15, value, max))); setTabIcon(indexOf(tabServer), QIcon(PingPixmapGenerator::generatePixmap(15, value, max)));
} }
void TabSupervisor::closeButtonPressed()
{
Tab *tab = static_cast<Tab *>(static_cast<CloseButton *>(sender())->property("tab").value<QObject *>());
tab->closeRequest();
}
void TabSupervisor::addCloseButtonToTab(Tab *tab, int tabIndex) void TabSupervisor::addCloseButtonToTab(Tab *tab, int tabIndex)
{ {
QTabBar::ButtonPosition closeSide = auto closeSide = static_cast<QTabBar::ButtonPosition>(
(QTabBar::ButtonPosition)tabBar()->style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, tabBar()); tabBar()->style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, nullptr, tabBar()));
CloseButton *closeButton = new CloseButton; auto *closeButton = new CloseButton(tab);
connect(closeButton, &CloseButton::clicked, this, &TabSupervisor::closeButtonPressed); connect(closeButton, &CloseButton::clicked, tab, [tab] { tab->closeRequest(); });
closeButton->setProperty("tab", QVariant::fromValue((QObject *)tab));
tabBar()->setTabButton(tabIndex, closeSide, closeButton); tabBar()->setTabButton(tabIndex, closeSide, closeButton);
} }

View file

@ -38,28 +38,28 @@ class MacOSTabFixStyle : public QProxyStyle
{ {
Q_OBJECT Q_OBJECT
public: public:
QRect subElementRect(SubElement, const QStyleOption *, const QWidget *) const; QRect subElementRect(SubElement, const QStyleOption *, const QWidget *) const override;
}; };
class CloseButton : public QAbstractButton class CloseButton : public QAbstractButton
{ {
Q_OBJECT Q_OBJECT
public: public:
CloseButton(QWidget *parent = nullptr); explicit CloseButton(QWidget *parent = nullptr);
QSize sizeHint() const; QSize sizeHint() const override;
inline QSize minimumSizeHint() const inline QSize minimumSizeHint() const override
{ {
return sizeHint(); return sizeHint();
} }
protected: protected:
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
void enterEvent(QEnterEvent *event); void enterEvent(QEnterEvent *event) override;
#else #else
void enterEvent(QEvent *event); void enterEvent(QEvent *event) override;
#endif #endif
void leaveEvent(QEvent *event); void leaveEvent(QEvent *event) override;
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event) override;
}; };
class TabSupervisor : public QTabWidget, public UserlistProxy class TabSupervisor : public QTabWidget, public UserlistProxy
@ -87,8 +87,8 @@ private:
bool isLocalGame; bool isLocalGame;
public: public:
TabSupervisor(AbstractClient *_client, QWidget *parent = nullptr); explicit TabSupervisor(AbstractClient *_client, QWidget *parent = nullptr);
~TabSupervisor(); ~TabSupervisor() override;
void retranslateUi(); void retranslateUi();
void start(const ServerInfo_User &userInfo); void start(const ServerInfo_User &userInfo);
void startLocal(const QList<AbstractClient *> &_clients); void startLocal(const QList<AbstractClient *> &_clients);
@ -116,11 +116,11 @@ public:
} }
bool getAdminLocked() const; bool getAdminLocked() const;
bool closeRequest(); bool closeRequest();
bool isOwnUserRegistered() const; bool isOwnUserRegistered() const override;
QString getOwnUsername() const; QString getOwnUsername() const override;
bool isUserBuddy(const QString &userName) const; bool isUserBuddy(const QString &userName) const override;
bool isUserIgnored(const QString &userName) const; bool isUserIgnored(const QString &userName) const override;
const ServerInfo_User *getOnlineUser(const QString &userName) const; const ServerInfo_User *getOnlineUser(const QString &userName) const override;
bool switchToGameTabIfAlreadyExists(const int gameId); bool switchToGameTabIfAlreadyExists(const int gameId);
void actShowPopup(const QString &message); void actShowPopup(const QString &message);
signals: signals:
@ -135,7 +135,6 @@ public slots:
void openReplay(GameReplay *replay); void openReplay(GameReplay *replay);
void maximizeMainWindow(); void maximizeMainWindow();
private slots: private slots:
void closeButtonPressed();
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);

View file

@ -58,7 +58,7 @@ TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor, Abstra
retranslateUi(); retranslateUi();
} }
void TabDeckStorageVisual::closeRequest() void TabDeckStorageVisual::closeRequest(bool /*forced*/)
{ {
this->close(); this->close();
} }

View file

@ -866,7 +866,7 @@ MainWindow::MainWindow(QWidget *parent)
createActions(); createActions();
createMenus(); createMenus();
tabSupervisor = new TabSupervisor(client); tabSupervisor = new TabSupervisor(client, this);
connect(tabSupervisor, &TabSupervisor::setMenu, this, &MainWindow::updateTabMenu); connect(tabSupervisor, &TabSupervisor::setMenu, this, &MainWindow::updateTabMenu);
connect(tabSupervisor, &TabSupervisor::localGameEnded, this, &MainWindow::localGameEnded); connect(tabSupervisor, &TabSupervisor::localGameEnded, this, &MainWindow::localGameEnded);
connect(tabSupervisor, &TabSupervisor::showWindowIfHidden, this, &MainWindow::showWindowIfHidden); connect(tabSupervisor, &TabSupervisor::showWindowIfHidden, this, &MainWindow::showWindowIfHidden);

View file

@ -3668,7 +3668,7 @@ Cockatrice will now reload the card database.</translation>
<source>%1 is looking at the %4 %3 card(s) %2.</source> <source>%1 is looking at the %4 %3 card(s) %2.</source>
<oldsource>%1 is looking at the top %3 card(s) %2.</oldsource> <oldsource>%1 is looking at the top %3 card(s) %2.</oldsource>
<comment>top card for singular, top %3 cards for plural</comment> <comment>top card for singular, top %3 cards for plural</comment>
<translation><numerusform>%1 is looking at the %4 %3 card(s) %2.</numerusform><numerusform>%1 is looking at the %4 %3 card(s) %2.</numerusform></translation> <translation><numerusform>%1 is looking at the %4 %3 card %2.</numerusform><numerusform>%1 is looking at the %4 %3 cards %2.</numerusform></translation>
</message> </message>
<message> <message>
<location filename="src/server/message_log_widget.cpp" line="393"/> <location filename="src/server/message_log_widget.cpp" line="393"/>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff