1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

WebTab: Don't add pinned tabs to tab tree

This commit is contained in:
David Rosca 2018-01-31 19:08:17 +01:00
parent e57fb65c95
commit fa19d97dc4
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
4 changed files with 35 additions and 15 deletions

View File

@ -624,7 +624,7 @@ QWebEnginePage* WebPage::createWindow(QWebEnginePage::WebWindowType type)
TabbedWebView* view = window->weView(index); TabbedWebView* view = window->weView(index);
view->setPage(new WebPage); view->setPage(new WebPage);
if (tView) { if (tView) {
view->webTab()->setParentTab(tView->webTab()); tView->webTab()->addChildTab(view->webTab());
} }
// Workaround focus issue when creating tab // Workaround focus issue when creating tab
if (pos.testFlag(Qz::NT_SelectedTab)) { if (pos.testFlag(Qz::NT_SelectedTab)) {

View File

@ -166,7 +166,7 @@ void TabbedWebView::loadInNewTab(const LoadRequest &req, Qz::NewTabPositionFlags
if (m_window) { if (m_window) {
int index = m_window->tabWidget()->addView(QUrl(), position); int index = m_window->tabWidget()->addView(QUrl(), position);
TabbedWebView *view = m_window->weView(index); TabbedWebView *view = m_window->weView(index);
view->webTab()->setParentTab(webTab()); webTab()->addChildTab(view->webTab());
view->webTab()->locationBar()->showUrl(req.url()); view->webTab()->locationBar()->showUrl(req.url());
view->load(req); view->load(req);
} }

View File

@ -277,18 +277,8 @@ void WebTab::detach()
Q_ASSERT(m_window); Q_ASSERT(m_window);
Q_ASSERT(m_tabBar); Q_ASSERT(m_tabBar);
// Remove parent tab and reparent children // Remove from tab tree
WebTab *parentTab = m_parentTab; removeFromTabTree();
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 icon from tab // Remove icon from tab
m_tabBar->setTabButton(tabIndex(), m_tabBar->iconButtonPosition(), nullptr); m_tabBar->setTabButton(tabIndex(), m_tabBar->iconButtonPosition(), nullptr);
@ -383,6 +373,10 @@ void WebTab::setPinned(bool state)
return; return;
} }
if (state) {
removeFromTabTree();
}
m_isPinned = state; m_isPinned = state;
emit pinnedChanged(m_isPinned); emit pinnedChanged(m_isPinned);
} }
@ -420,7 +414,11 @@ WebTab *WebTab::parentTab() const
void WebTab::setParentTab(WebTab *tab) void WebTab::setParentTab(WebTab *tab)
{ {
if (m_parentTab == tab) { if (m_isPinned || m_parentTab == tab) {
return;
}
if (tab && tab->isPinned()) {
return; return;
} }
@ -444,6 +442,10 @@ void WebTab::setParentTab(WebTab *tab)
void WebTab::addChildTab(WebTab *tab, int index) void WebTab::addChildTab(WebTab *tab, int index)
{ {
if (m_isPinned || !tab || tab->isPinned()) {
return;
}
tab->m_parentTab = this; tab->m_parentTab = this;
WebTab *tabParent = tab->m_parentTab; WebTab *tabParent = tab->m_parentTab;
@ -582,6 +584,23 @@ void WebTab::resizeEvent(QResizeEvent *event)
m_notificationWidget->setFixedWidth(width()); 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 bool WebTab::isCurrentTab() const
{ {
return m_isCurrentTab; return m_isCurrentTab;

View File

@ -131,6 +131,7 @@ signals:
private: private:
void titleWasChanged(const QString &title); void titleWasChanged(const QString &title);
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
void removeFromTabTree();
QVBoxLayout* m_layout; QVBoxLayout* m_layout;
QSplitter* m_splitter; QSplitter* m_splitter;