1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

TabWidget: Track last WebTab instead of only index

This commit is contained in:
David Rosca 2018-02-04 13:14:46 +01:00
parent dbd4e75941
commit ca15006145
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 23 additions and 23 deletions

View File

@ -87,8 +87,6 @@ TabWidget::TabWidget(BrowserWindow *window, QWidget *parent)
, m_window(window) , m_window(window)
, m_locationBars(new QStackedWidget) , m_locationBars(new QStackedWidget)
, m_closedTabsManager(new ClosedTabsManager) , m_closedTabsManager(new ClosedTabsManager)
, m_lastTabIndex(-1)
, m_lastBackgroundTabIndex(-1)
{ {
setObjectName(QSL("tabwidget")); setObjectName(QSL("tabwidget"));
@ -323,7 +321,7 @@ int TabWidget::addView(const LoadRequest &req, const Qz::NewTabPositionFlags &op
int TabWidget::addView(const LoadRequest &req, const QString &title, const Qz::NewTabPositionFlags &openFlags, bool selectLine, int position, bool pinned) int TabWidget::addView(const LoadRequest &req, const QString &title, const Qz::NewTabPositionFlags &openFlags, bool selectLine, int position, bool pinned)
{ {
QUrl url = req.url(); QUrl url = req.url();
m_lastTabIndex = currentIndex(); m_lastTab = weTab();
m_currentTabFresh = false; m_currentTabFresh = false;
if (url.isEmpty() && !(openFlags & Qz::NT_CleanTab)) { if (url.isEmpty() && !(openFlags & Qz::NT_CleanTab)) {
@ -339,8 +337,8 @@ int TabWidget::addView(const LoadRequest &req, const QString &title, const Qz::N
if (openAfterActive && position == -1) { if (openAfterActive && position == -1) {
// If we are opening newBgTab from pinned tab, make sure it won't be // If we are opening newBgTab from pinned tab, make sure it won't be
// opened between other pinned tabs // opened between other pinned tabs
if (openFlags & Qz::NT_NotSelectedTab && m_lastBackgroundTabIndex != -1) { if (openFlags & Qz::NT_NotSelectedTab && m_lastBackgroundTab) {
position = m_lastBackgroundTabIndex + 1; position = m_lastBackgroundTab->tabIndex() + 1;
} }
else { else {
position = qMax(currentIndex() + 1, m_tabBar->pinnedTabsCount()); position = qMax(currentIndex() + 1, m_tabBar->pinnedTabsCount());
@ -361,9 +359,8 @@ int TabWidget::addView(const LoadRequest &req, const QString &title, const Qz::N
if (openFlags & Qz::NT_SelectedTab) { if (openFlags & Qz::NT_SelectedTab) {
setCurrentIndex(index); setCurrentIndex(index);
} } else {
else { m_lastBackgroundTab = webTab;
m_lastBackgroundTabIndex = index;
} }
connect(webTab->webView(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int))); connect(webTab->webView(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
@ -412,7 +409,7 @@ int TabWidget::insertView(int index, WebTab *tab, const Qz::NewTabPositionFlags
if (openFlags.testFlag(Qz::NT_SelectedTab)) { if (openFlags.testFlag(Qz::NT_SelectedTab)) {
setCurrentIndex(newIndex); setCurrentIndex(newIndex);
} else { } else {
m_lastBackgroundTabIndex = index; m_lastBackgroundTab = tab;
} }
connect(tab->webView(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int))); connect(tab->webView(), SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int)));
@ -463,7 +460,7 @@ void TabWidget::closeTab(int index)
disconnect(webView, SIGNAL(urlChanged(QUrl)), this, SIGNAL(changed())); disconnect(webView, SIGNAL(urlChanged(QUrl)), this, SIGNAL(changed()));
disconnect(webView, SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString))); disconnect(webView, SIGNAL(ipChanged(QString)), m_window->ipLabel(), SLOT(setText(QString)));
m_lastBackgroundTabIndex = -1; m_lastBackgroundTab = nullptr;
webTab->detach(); webTab->detach();
webTab->deleteLater(); webTab->deleteLater();
@ -510,12 +507,12 @@ void TabWidget::currentTabChanged(int index)
if (!validIndex(index)) if (!validIndex(index))
return; return;
m_lastBackgroundTabIndex = -1; m_lastBackgroundTab = nullptr;
m_lastTabIndex = index;
m_currentTabFresh = false; m_currentTabFresh = false;
WebTab* webTab = weTab(index); WebTab* webTab = weTab(index);
webTab->tabActivated(); webTab->tabActivated();
m_lastTab = webTab;
LocationBar* locBar = webTab->locationBar(); LocationBar* locBar = webTab->locationBar();
@ -530,11 +527,7 @@ void TabWidget::currentTabChanged(int index)
void TabWidget::tabWasMoved(int before, int after) void TabWidget::tabWasMoved(int before, int after)
{ {
Q_UNUSED(before) m_lastBackgroundTab = nullptr;
Q_UNUSED(after)
m_lastBackgroundTabIndex = -1;
m_lastTabIndex = before;
emit changed(); emit changed();
emit tabMoved(before, after); emit tabMoved(before, after);
@ -542,7 +535,7 @@ void TabWidget::tabWasMoved(int before, int after)
void TabWidget::setCurrentIndex(int index) void TabWidget::setCurrentIndex(int index)
{ {
m_lastTabIndex = currentIndex(); m_lastTab = weTab();
TabStackedWidget::setCurrentIndex(index); TabStackedWidget::setCurrentIndex(index);
} }
@ -578,9 +571,14 @@ void TabWidget::reloadTab(int index)
weTab(index)->reload(); weTab(index)->reload();
} }
WebTab *TabWidget::lastTab() const
{
return m_lastTab;
}
int TabWidget::lastTabIndex() const int TabWidget::lastTabIndex() const
{ {
return m_lastTabIndex; return m_lastTab ? m_lastTab->tabIndex() : -1;
} }
int TabWidget::extraReservedWidth() const int TabWidget::extraReservedWidth() const

View File

@ -18,8 +18,8 @@
#ifndef TABWIDGET_H #ifndef TABWIDGET_H
#define TABWIDGET_H #define TABWIDGET_H
#include <QTabWidget>
#include <QMenu> #include <QMenu>
#include <QPointer>
#include "tabstackedwidget.h" #include "tabstackedwidget.h"
#include "toolbutton.h" #include "toolbutton.h"
@ -81,9 +81,11 @@ public:
int normalTabsCount() const; int normalTabsCount() const;
int pinnedTabsCount() const; int pinnedTabsCount() const;
int lastTabIndex() const;
int extraReservedWidth() const; int extraReservedWidth() const;
WebTab *lastTab() const;
int lastTabIndex() const;
TabBar* tabBar() const; TabBar* tabBar() const;
ClosedTabsManager* closedTabsManager() const; ClosedTabsManager* closedTabsManager() const;
QList<WebTab*> allTabs(bool withPinned = true); QList<WebTab*> allTabs(bool withPinned = true);
@ -168,8 +170,8 @@ private:
AddTabButton* m_buttonAddTab; AddTabButton* m_buttonAddTab;
AddTabButton* m_buttonAddTab2; AddTabButton* m_buttonAddTab2;
int m_lastTabIndex; QPointer<WebTab> m_lastTab;
int m_lastBackgroundTabIndex; QPointer<WebTab> m_lastBackgroundTab;
bool m_dontCloseWithOneTab; bool m_dontCloseWithOneTab;
bool m_showClosedTabsButton; bool m_showClosedTabsButton;