From f5ad4424aa67013d7b2c7d2a16fd84161ac88282 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 1 Jan 2018 11:57:31 +0100 Subject: [PATCH] TabWidget: Add insertView method for WebTab --- src/lib/app/browserwindow.cpp | 4 ++-- src/lib/tabwidget/tabwidget.cpp | 25 +++++++++++++++++---- src/lib/tabwidget/tabwidget.h | 5 +++-- src/plugins/TabManager/tabmanagerwidget.cpp | 3 ++- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index abebc7161..5ad932303 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2010-2017 David Rosca +* Copyright (C) 2010-2018 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -205,7 +205,7 @@ void BrowserWindow::postLaunch() if (m_startTab) { addTab = false; - m_tabWidget->addView(m_startTab); + m_tabWidget->addView(m_startTab, Qz::NT_SelectedTab); } if (m_startPage) { diff --git a/src/lib/tabwidget/tabwidget.cpp b/src/lib/tabwidget/tabwidget.cpp index cde46ab43..9decc10bc 100644 --- a/src/lib/tabwidget/tabwidget.cpp +++ b/src/lib/tabwidget/tabwidget.cpp @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2010-2017 David Rosca +* Copyright (C) 2010-2018 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -378,17 +378,34 @@ int TabWidget::addView(const LoadRequest &req, const QString &title, const Qz::N return index; } -int TabWidget::addView(WebTab* tab) +int TabWidget::addView(WebTab *tab, const Qz::NewTabPositionFlags &openFlags) +{ + return insertView(count() + 1, tab, openFlags); +} + +int TabWidget::insertView(int index, WebTab *tab, const Qz::NewTabPositionFlags &openFlags) { m_locationBars->addWidget(tab->locationBar()); - int index = addTab(tab, QString()); + int newIndex = insertTab(index, tab, QString()); tab->attach(m_window); + if (openFlags.testFlag(Qz::NT_SelectedTab)) { + setCurrentIndex(newIndex); + } else { + m_lastBackgroundTabIndex = index; + } + connect(tab->webView(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int))); connect(tab->webView(), SIGNAL(urlChanged(QUrl)), this, SIGNAL(changed())); connect(tab->webView(), SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString))); - return index; + // Make sure user notice opening new background tabs + if (!(openFlags & Qz::NT_SelectedTab)) { + m_tabBar->ensureVisible(index); + } + + emit changed(); + return newIndex; } void TabWidget::addTabFromClipboard() diff --git a/src/lib/tabwidget/tabwidget.h b/src/lib/tabwidget/tabwidget.h index dfcf2bc4a..c238aa34e 100644 --- a/src/lib/tabwidget/tabwidget.h +++ b/src/lib/tabwidget/tabwidget.h @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2010-2017 David Rosca +* Copyright (C) 2010-2018 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -100,7 +100,8 @@ public: public slots: int addView(const LoadRequest &req, const Qz::NewTabPositionFlags &openFlags, bool selectLine = false, bool pinned = false); int addView(const LoadRequest &req, const QString &title = tr("New tab"), const Qz::NewTabPositionFlags &openFlags = Qz::NT_SelectedTab, bool selectLine = false, int position = -1, bool pinned = false); - int addView(WebTab* tab); + int addView(WebTab *tab, const Qz::NewTabPositionFlags &openFlags); + int insertView(int index, WebTab *tab, const Qz::NewTabPositionFlags &openFlags); void addTabFromClipboard(); int duplicateTab(int index); diff --git a/src/plugins/TabManager/tabmanagerwidget.cpp b/src/plugins/TabManager/tabmanagerwidget.cpp index 552730da5..1a2fe3014 100644 --- a/src/plugins/TabManager/tabmanagerwidget.cpp +++ b/src/plugins/TabManager/tabmanagerwidget.cpp @@ -1,6 +1,7 @@ /* ============================================================ * TabManager plugin for Falkon * Copyright (C) 2013-2017 S. Razi Alavizadeh +* Copyright (C) 2018 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -546,7 +547,7 @@ static void detachTabsTo(BrowserWindow* targetWindow, const QHashtabWidget()->addView(webTab); + targetWindow->tabWidget()->addView(webTab, Qz::NT_NotSelectedTab); } } }