diff --git a/cockatrice/src/client/tabs/tab_deck_editor.cpp b/cockatrice/src/client/tabs/tab_deck_editor.cpp index 1f8e2cbff..c3ee583d1 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.cpp +++ b/cockatrice/src/client/tabs/tab_deck_editor.cpp @@ -358,7 +358,7 @@ void TabDeckEditor::createMenus() analyzeDeckMenu->addAction(aAnalyzeDeckTappedout); aClose = new QAction(QString(), this); - connect(aClose, SIGNAL(triggered()), this, SLOT(closeRequest())); + connect(aClose, &QAction::triggered, this, [this](bool) { closeRequest(); }); aClearFilterAll = new QAction(QString(), this); aClearFilterAll->setIcon(QPixmap("theme:icons/clearsearch")); @@ -721,11 +721,6 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent) loadLayout(); } -TabDeckEditor::~TabDeckEditor() -{ - emit deckEditorClosing(this); -} - void TabDeckEditor::retranslateUi() { cardInfo->retranslateUi(); @@ -982,8 +977,12 @@ bool TabDeckEditor::confirmClose() void TabDeckEditor::closeRequest(bool forced) { - if (confirmClose()) - deleteLater(); + if (!forced && !confirmClose()) { + return; + } + + emit deckEditorClosing(this); + deleteLater(); } void TabDeckEditor::actNewDeck() diff --git a/cockatrice/src/client/tabs/tab_deck_editor.h b/cockatrice/src/client/tabs/tab_deck_editor.h index 7318b99db..7a3859413 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.h +++ b/cockatrice/src/client/tabs/tab_deck_editor.h @@ -164,7 +164,6 @@ private: public: explicit TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent = nullptr); - ~TabDeckEditor() override; void retranslateUi() override; QString getTabText() const override; void setDeck(DeckLoader *_deckLoader); diff --git a/cockatrice/src/client/tabs/tab_game.cpp b/cockatrice/src/client/tabs/tab_game.cpp index 09ca874c2..36dd945e7 100644 --- a/cockatrice/src/client/tabs/tab_game.cpp +++ b/cockatrice/src/client/tabs/tab_game.cpp @@ -581,16 +581,14 @@ void TabGame::emitUserEvent() TabGame::~TabGame() { + scene->clearViews(); + delete replay; QMapIterator i(players); while (i.hasNext()) { delete i.next().value(); } - - players.clear(); - - emit gameClosing(this); } void TabGame::updatePlayerListDockTitle() @@ -703,7 +701,13 @@ void TabGame::retranslateUi() void TabGame::closeRequest(bool forced) { - actLeaveGame(); + if (!forced && !leaveGame()) { + return; + } + + emit gameClosing(this); + + deleteLater(); } 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 (!spectator) 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) - return; + return false; if (!replay) sendGameCommand(Command_LeaveGame()); } - scene->clearViews(); - deleteLater(); + return true; } void TabGame::actSay() @@ -1598,7 +1606,7 @@ void TabGame::createMenuItems() aConcede = new QAction(this); connect(aConcede, SIGNAL(triggered()), this, SLOT(actConcede())); aLeaveGame = new QAction(this); - connect(aLeaveGame, SIGNAL(triggered()), this, SLOT(actLeaveGame())); + connect(aLeaveGame, &QAction::triggered, this, [this](bool) { closeRequest(); }); aFocusChat = new QAction(this); connect(aFocusChat, SIGNAL(triggered()), sayEdit, SLOT(setFocus())); aCloseReplay = nullptr; @@ -1648,7 +1656,7 @@ void TabGame::createReplayMenuItems() aFocusChat = nullptr; aLeaveGame = nullptr; aCloseReplay = new QAction(this); - connect(aCloseReplay, SIGNAL(triggered()), this, SLOT(actLeaveGame())); + connect(aCloseReplay, &QAction::triggered, this, [this](bool) { closeRequest(); }); phasesMenu = nullptr; gameMenu = new QMenu(this); diff --git a/cockatrice/src/client/tabs/tab_game.h b/cockatrice/src/client/tabs/tab_game.h index 6c1fa4eeb..ec3366dda 100644 --- a/cockatrice/src/client/tabs/tab_game.h +++ b/cockatrice/src/client/tabs/tab_game.h @@ -189,6 +189,7 @@ private: void startGame(bool resuming); void stopGame(); void closeGame(); + bool leaveGame(); void eventSpectatorSay(const Event_GameSay &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 actConcede(); - void actLeaveGame(); void actRemoveLocalArrows(); void actRotateViewCW(); void actRotateViewCCW(); diff --git a/cockatrice/src/client/tabs/tab_message.cpp b/cockatrice/src/client/tabs/tab_message.cpp index 26fe692d3..19abca9fa 100644 --- a/cockatrice/src/client/tabs/tab_message.cpp +++ b/cockatrice/src/client/tabs/tab_message.cpp @@ -38,7 +38,7 @@ TabMessage::TabMessage(TabSupervisor *_tabSupervisor, vbox->addWidget(sayEdit); aLeave = new QAction(this); - connect(aLeave, SIGNAL(triggered()), this, SLOT(actLeave())); + connect(aLeave, &QAction::triggered, this, [this](bool) { closeRequest(); }); messageMenu = new QMenu(this); messageMenu->addAction(aLeave); @@ -53,7 +53,6 @@ TabMessage::TabMessage(TabSupervisor *_tabSupervisor, TabMessage::~TabMessage() { - emit talkClosing(this); delete ownUserInfo; delete otherUserInfo; } @@ -88,7 +87,8 @@ QString TabMessage::getTabText() const void TabMessage::closeRequest(bool forced) { - actLeave(); + emit talkClosing(this); + deleteLater(); } 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.")); } -void TabMessage::actLeave() -{ - deleteLater(); -} - void TabMessage::processUserMessageEvent(const Event_UserMessage &event) { auto userInfo = event.sender_name() == otherUserInfo->name() ? otherUserInfo : ownUserInfo; diff --git a/cockatrice/src/client/tabs/tab_message.h b/cockatrice/src/client/tabs/tab_message.h index d68bcaf0d..12a4188a2 100644 --- a/cockatrice/src/client/tabs/tab_message.h +++ b/cockatrice/src/client/tabs/tab_message.h @@ -29,7 +29,6 @@ signals: void maximizeClient(); private slots: void sendMessage(); - void actLeave(); void messageSent(const Response &response); void addMentionTag(QString mentionTag); void messageClicked(); diff --git a/cockatrice/src/client/tabs/tab_room.cpp b/cockatrice/src/client/tabs/tab_room.cpp index 6fee94d21..1b8f852ed 100644 --- a/cockatrice/src/client/tabs/tab_room.cpp +++ b/cockatrice/src/client/tabs/tab_room.cpp @@ -101,7 +101,7 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, hbox->addWidget(userList, 1); aLeaveRoom = new QAction(this); - connect(aLeaveRoom, SIGNAL(triggered()), this, SLOT(actLeaveRoom())); + connect(aLeaveRoom, &QAction::triggered, this, [this](bool) { closeRequest(); }); roomMenu = new QMenu(this); roomMenu->addAction(aLeaveRoom); @@ -135,11 +135,6 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, setCentralWidget(mainWidget); } -TabRoom::~TabRoom() -{ - emit roomClosing(this); -} - void TabRoom::retranslateUi() { gameSelector->retranslateUi(); @@ -177,7 +172,9 @@ void TabRoom::actShowPopup(const QString &message) void TabRoom::closeRequest(bool forced) { - actLeaveRoom(); + sendRoomCommand(prepareRoomCommand(Command_LeaveRoom())); + emit roomClosing(this); + deleteLater(); } 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.")); } -void TabRoom::actLeaveRoom() -{ - sendRoomCommand(prepareRoomCommand(Command_LeaveRoom())); - deleteLater(); -} - void TabRoom::actClearChat() { chatView->clearChat(); diff --git a/cockatrice/src/client/tabs/tab_room.h b/cockatrice/src/client/tabs/tab_room.h index 5d263766a..32152e933 100644 --- a/cockatrice/src/client/tabs/tab_room.h +++ b/cockatrice/src/client/tabs/tab_room.h @@ -70,7 +70,6 @@ signals: private slots: void sendMessage(); void sayFinished(const Response &response); - void actLeaveRoom(); void actClearChat(); void actOpenChatSettings(); void addMentionTag(QString mentionTag); @@ -91,7 +90,6 @@ public: AbstractClient *_client, ServerInfo_User *_ownUser, const ServerInfo_Room &info); - ~TabRoom() override; void retranslateUi() override; void closeRequest(bool forced = false) override; void tabActivated() override;