From fd5f068ae912bec800df24fcac624fb1e3d9593e Mon Sep 17 00:00:00 2001 From: aqua Date: Sat, 3 Sep 2022 15:00:06 +0300 Subject: Close main window after last tab is closed --- src/rekonqwindow.cpp | 8 +++++--- src/tabbar/tabbar.cpp | 11 ++++++++++- src/tabbar/tabbar.h | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/rekonqwindow.cpp b/src/rekonqwindow.cpp index ef772936..f969622c 100644 --- a/src/rekonqwindow.cpp +++ b/src/rekonqwindow.cpp @@ -23,9 +23,11 @@ RekonqWindow::RekonqWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::Re { ui->setupUi(this); - connect(ui->tabs, &QTabBar::currentChanged, this, [this](int index) { - auto *view = ui->tabs->view(index); - Q_CHECK_PTR(view); + connect(ui->tabs, &TabBar::currentChanged, this, [this](RekonqView *view) { + if (view == nullptr) { // last tab has been closed + close(); + return; + } ui->views->setCurrentWidget(view); ui->urlBar->setCurrentView(view); diff --git a/src/tabbar/tabbar.cpp b/src/tabbar/tabbar.cpp index 9bb05d43..fb5c0444 100644 --- a/src/tabbar/tabbar.cpp +++ b/src/tabbar/tabbar.cpp @@ -27,6 +27,15 @@ TabBar::TabBar(QWidget *parent) : QTabBar(parent) setMovable(true); setAcceptDrops(true); + connect(this, &QTabBar::currentChanged, this, [this](int index) { + if (index == -1) { + emit currentChanged(nullptr); + return; + } + auto view = m_views.at(index); + Q_ASSERT(!view.isNull()); + emit currentChanged(view); + }); connect(this, &QTabBar::tabMoved, this, [this](int from, int to) { m_views.move(from, to); }); connect(this, &QTabBar::tabCloseRequested, this, [this](int index) { @@ -595,4 +604,4 @@ void TabBar::unpinTab() SessionManager::self()->saveSession(); } -*/ \ No newline at end of file +*/ diff --git a/src/tabbar/tabbar.h b/src/tabbar/tabbar.h index 077255a4..793e2acf 100644 --- a/src/tabbar/tabbar.h +++ b/src/tabbar/tabbar.h @@ -36,6 +36,7 @@ public: } signals: + void currentChanged(RekonqView *view); void removeView(RekonqView *); protected: -- cgit v1.2.1