mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-02 03:23:56 -07:00
Always set TabSupervisor as parent in Tab subclasses (#5449)
* refactor closeTab * always set tab parent to tabSupervisor * set tabSupervisor parent * use close instead of deleteLater * be more clear about overloads
This commit is contained in:
parent
3a4ec1062b
commit
a6fc88c79a
18 changed files with 25 additions and 41 deletions
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ private:
|
||||||
QList<QMenu *> tabMenus;
|
QList<QMenu *> tabMenus;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Tab(TabSupervisor *_tabSupervisor, QWidget *parent = nullptr);
|
explicit Tab(TabSupervisor *_tabSupervisor);
|
||||||
const QList<QMenu *> &getTabMenus() const
|
const QList<QMenu *> &getTabMenus() const
|
||||||
{
|
{
|
||||||
return tabMenus;
|
return tabMenus;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,7 @@ 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,
|
|
||||||
const ServerInfo_User &userInfo,
|
|
||||||
QWidget *parent = nullptr);
|
|
||||||
void retranslateUi() override;
|
void retranslateUi() override;
|
||||||
QString getTabText() const override
|
QString getTabText() const override
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ 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() override;
|
void retranslateUi() override;
|
||||||
QString getTabText() const override
|
QString getTabText() const override
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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");
|
||||||
|
|
||||||
|
|
@ -982,7 +981,7 @@ void TabDeckEditor::closeRequest(bool forced)
|
||||||
}
|
}
|
||||||
|
|
||||||
emit deckEditorClosing(this);
|
emit deckEditorClosing(this);
|
||||||
deleteLater();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckEditor::actNewDeck()
|
void TabDeckEditor::actNewDeck()
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ private:
|
||||||
QWidget *centralWidget;
|
QWidget *centralWidget;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent = nullptr);
|
explicit TabDeckEditor(TabSupervisor *_tabSupervisor);
|
||||||
void retranslateUi() override;
|
void retranslateUi() override;
|
||||||
QString getTabText() const override;
|
QString getTabText() const override;
|
||||||
void setDeck(DeckLoader *_deckLoader);
|
void setDeck(DeckLoader *_deckLoader);
|
||||||
|
|
|
||||||
|
|
@ -707,7 +707,7 @@ void TabGame::closeRequest(bool forced)
|
||||||
|
|
||||||
emit gameClosing(this);
|
emit gameClosing(this);
|
||||||
|
|
||||||
deleteLater();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::replayNextEvent(Player::EventProcessingOptions options)
|
void TabGame::replayNextEvent(Player::EventProcessingOptions options)
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ private slots:
|
||||||
void restartLayout();
|
void restartLayout();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TabLog(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent = nullptr);
|
TabLog(TabSupervisor *_tabSupervisor, AbstractClient *_client);
|
||||||
~TabLog() override;
|
~TabLog() override;
|
||||||
void retranslateUi() override;
|
void retranslateUi() override;
|
||||||
QString getTabText() const override
|
QString getTabText() const override
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ QString TabMessage::getTabText() const
|
||||||
void TabMessage::closeRequest(bool /*forced*/)
|
void TabMessage::closeRequest(bool /*forced*/)
|
||||||
{
|
{
|
||||||
emit talkClosing(this);
|
emit talkClosing(this);
|
||||||
deleteLater();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabMessage::sendMessage()
|
void TabMessage::sendMessage()
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ void TabRoom::closeRequest(bool /*forced*/)
|
||||||
{
|
{
|
||||||
sendRoomCommand(prepareRoomCommand(Command_LeaveRoom()));
|
sendRoomCommand(prepareRoomCommand(Command_LeaveRoom()));
|
||||||
emit roomClosing(this);
|
emit roomClosing(this);
|
||||||
deleteLater();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabRoom::tabActivated()
|
void TabRoom::tabActivated()
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ private:
|
||||||
bool shouldEmitUpdate = false;
|
bool shouldEmitUpdate = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent = nullptr);
|
TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client);
|
||||||
void retranslateUi() override;
|
void retranslateUi() override;
|
||||||
QString getTabText() const override
|
QString getTabText() const override
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -339,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue