TabBar::setCloseTabButton()

Deduplicated the code responsible for setting up the tab closing button.
This commit is contained in:
Veloman Yunkan 2024-03-12 18:03:17 +04:00
parent bbceea3d5e
commit 4c831f0228
2 changed files with 14 additions and 6 deletions

View File

@ -71,9 +71,7 @@ void TabBar::openOrSwitchToSettingsTab()
mp_stackedWidget->insertWidget(index, view);
emit tabDisplayed(TabType::SettingsTab);
insertTab(index,QIcon(":/icons/settings.svg"), gt("settings"));
QToolButton *tb = new QToolButton(this);
tb->setDefaultAction(KiwixApp::instance()->getAction(KiwixApp::CloseTabAction));
setTabButton(index, QTabBar::RightSide, tb);
setCloseTabButton(index);
setCurrentIndex(index);
}
@ -124,15 +122,22 @@ void TabBar::moveToPreviousTab()
setCurrentIndex(index <= 0 ? realTabCount() - 1 : index - 1);
}
void TabBar::setCloseTabButton(int index)
{
Q_ASSERT(index > 0 && index < realTabCount());
QToolButton *tb = new QToolButton(this);
tb->setDefaultAction(KiwixApp::instance()->getAction(KiwixApp::CloseTabAction));
setTabButton(index, QTabBar::RightSide, tb);
}
ZimView* TabBar::createNewTab(bool setCurrent, bool nextToCurrentTab)
{
auto tab = new ZimView(this, this);
const int index = nextToCurrentTab ? currentIndex() + 1 : realTabCount();
mp_stackedWidget->insertWidget(index, tab);
insertTab(index, "");
QToolButton *tb = new QToolButton(this);
tb->setDefaultAction(KiwixApp::instance()->getAction(KiwixApp::CloseTabAction));
setTabButton(index, QTabBar::RightSide, tb);
setCloseTabButton(index);
if (setCurrent) {
setCurrentIndex(index);
}

View File

@ -67,6 +67,9 @@ public slots:
void moveToNextTab();
void moveToPreviousTab();
private:
void setCloseTabButton(int index);
private:
QStackedWidget* mp_stackedWidget;
QScopedPointer<FullScreenWindow> m_fullScreenWindow;