diff --git a/src/lib/webengine/webpage.cpp b/src/lib/webengine/webpage.cpp index a1e5672a9..b71d53bf6 100644 --- a/src/lib/webengine/webpage.cpp +++ b/src/lib/webengine/webpage.cpp @@ -624,7 +624,7 @@ QWebEnginePage* WebPage::createWindow(QWebEnginePage::WebWindowType type) TabbedWebView* view = window->weView(index); view->setPage(new WebPage); if (tView) { - view->webTab()->setParentTab(tView->webTab()); + tView->webTab()->addChildTab(view->webTab()); } // Workaround focus issue when creating tab if (pos.testFlag(Qz::NT_SelectedTab)) { diff --git a/src/lib/webtab/tabbedwebview.cpp b/src/lib/webtab/tabbedwebview.cpp index 03aa85a96..6ecca2a35 100644 --- a/src/lib/webtab/tabbedwebview.cpp +++ b/src/lib/webtab/tabbedwebview.cpp @@ -166,7 +166,7 @@ void TabbedWebView::loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags if (m_window) { int index = m_window->tabWidget()->addView(QUrl(), position); TabbedWebView *view = m_window->weView(index); - view->webTab()->setParentTab(webTab()); + webTab()->addChildTab(view->webTab()); view->webTab()->locationBar()->showUrl(req.url()); view->load(req); } diff --git a/src/lib/webtab/webtab.cpp b/src/lib/webtab/webtab.cpp index 0883ab8ee..6c9b9aec7 100644 --- a/src/lib/webtab/webtab.cpp +++ b/src/lib/webtab/webtab.cpp @@ -277,18 +277,8 @@ void WebTab::detach() Q_ASSERT(m_window); Q_ASSERT(m_tabBar); - // Remove parent tab and reparent children - WebTab *parentTab = m_parentTab; - const int parentIndex = parentTab ? parentTab->m_childTabs.indexOf(this) : -1; - setParentTab(nullptr); - int i = 0; - while (!m_childTabs.isEmpty()) { - WebTab *child = m_childTabs.at(0); - child->setParentTab(nullptr); - if (parentTab) { - parentTab->addChildTab(child, parentIndex + i++); - } - } + // Remove from tab tree + removeFromTabTree(); // Remove icon from tab m_tabBar->setTabButton(tabIndex(), m_tabBar->iconButtonPosition(), nullptr); @@ -383,6 +373,10 @@ void WebTab::setPinned(bool state) return; } + if (state) { + removeFromTabTree(); + } + m_isPinned = state; emit pinnedChanged(m_isPinned); } @@ -420,7 +414,11 @@ WebTab *WebTab::parentTab() const void WebTab::setParentTab(WebTab *tab) { - if (m_parentTab == tab) { + if (m_isPinned || m_parentTab == tab) { + return; + } + + if (tab && tab->isPinned()) { return; } @@ -444,6 +442,10 @@ void WebTab::setParentTab(WebTab *tab) void WebTab::addChildTab(WebTab *tab, int index) { + if (m_isPinned || !tab || tab->isPinned()) { + return; + } + tab->m_parentTab = this; WebTab *tabParent = tab->m_parentTab; @@ -582,6 +584,23 @@ void WebTab::resizeEvent(QResizeEvent *event) m_notificationWidget->setFixedWidth(width()); } +void WebTab::removeFromTabTree() +{ + WebTab *parentTab = m_parentTab; + const int parentIndex = parentTab ? parentTab->m_childTabs.indexOf(this) : -1; + + setParentTab(nullptr); + + int i = 0; + while (!m_childTabs.isEmpty()) { + WebTab *child = m_childTabs.at(0); + child->setParentTab(nullptr); + if (parentTab) { + parentTab->addChildTab(child, parentIndex + i++); + } + } +} + bool WebTab::isCurrentTab() const { return m_isCurrentTab; diff --git a/src/lib/webtab/webtab.h b/src/lib/webtab/webtab.h index d5e7fb6d4..58ed9853a 100644 --- a/src/lib/webtab/webtab.h +++ b/src/lib/webtab/webtab.h @@ -131,6 +131,7 @@ signals: private: void titleWasChanged(const QString &title); void resizeEvent(QResizeEvent *event) override; + void removeFromTabTree(); QVBoxLayout* m_layout; QSplitter* m_splitter;