mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-21 19:18:39 -04:00
TabBar::setCloseTabButton()
Deduplicated the code responsible for setting up the tab closing button.
This commit is contained in:
parent
bbceea3d5e
commit
4c831f0228
@ -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);
|
||||
}
|
||||
|
@ -67,6 +67,9 @@ public slots:
|
||||
void moveToNextTab();
|
||||
void moveToPreviousTab();
|
||||
|
||||
private:
|
||||
void setCloseTabButton(int index);
|
||||
|
||||
private:
|
||||
QStackedWidget* mp_stackedWidget;
|
||||
QScopedPointer<FullScreenWindow> m_fullScreenWindow;
|
||||
|
Loading…
x
Reference in New Issue
Block a user