Extracted TabBar::openOrSwitchToSettingsTab()

This commit is contained in:
Veloman Yunkan 2024-03-12 16:23:19 +04:00
parent caa6195caa
commit b39597b501
2 changed files with 21 additions and 17 deletions

View File

@ -48,23 +48,7 @@ TabBar::TabBar(QWidget *parent) :
current->setUrl("zim://" + current->zimId() + ".zim/");
});
connect(app->getAction(KiwixApp::SettingAction), &QAction::triggered,
this, [=]() {
SettingsView* view = KiwixApp::instance()->getSettingsManager()->getView();
for (int i = 0 ; i < mp_stackedWidget->count(); i++) {
if (mp_stackedWidget->widget(i) == view) {
setCurrentIndex(i);
return;
}
}
int index = currentIndex() + 1;
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);
setCurrentIndex(index);
});
this, &TabBar::openOrSwitchToSettingsTab);
for (int i = 0 ; i <= 9 ; i++) {
QAction *a = new QAction(this);
@ -95,6 +79,25 @@ TabBar::TabBar(QWidget *parent) :
this, SLOT(onTabMoved(int,int)), Qt::DirectConnection);
}
void TabBar::openOrSwitchToSettingsTab()
{
SettingsView* view = KiwixApp::instance()->getSettingsManager()->getView();
for (int i = 0 ; i < mp_stackedWidget->count(); i++) {
if (mp_stackedWidget->widget(i) == view) {
setCurrentIndex(i);
return;
}
}
int index = currentIndex() + 1;
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);
setCurrentIndex(index);
}
void TabBar::setStackedWidget(QStackedWidget *widget) {
mp_stackedWidget = widget;
connect(this, &QTabBar::currentChanged,

View File

@ -61,6 +61,7 @@ signals:
public slots:
void closeTab(int index);
void openOrSwitchToSettingsTab();
void fullScreenRequested(QWebEngineFullScreenRequest request);
void on_webview_titleChanged(const QString& title);
void moveToNextTab();