refactor closeTab

This commit is contained in:
RickyRister 2025-01-11 22:06:01 -08:00
parent 3a4ec1062b
commit 2a62b8c6ef
2 changed files with 4 additions and 12 deletions

View file

@ -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::closeRequest);
closeButton->setProperty("tab", QVariant::fromValue((QObject *)tab));
tabBar()->setTabButton(tabIndex, closeSide, closeButton); tabBar()->setTabButton(tabIndex, closeSide, closeButton);
} }

View file

@ -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);