From bcd411c1c0d9c181519e77ca0d7cf811977c9b9d Mon Sep 17 00:00:00 2001 From: nowrep Date: Mon, 27 Feb 2012 17:51:57 +0100 Subject: [PATCH] Improved behaviour of opening new tab after current. - when opening multiple background tabs from current tab, newly opened tabs will be added after previous opened, not right after current so you will be able to switch to new tabs in opening order --- src/lib/webview/tabwidget.cpp | 97 ++++++++++++--------- src/lib/webview/tabwidget.h | 1 + src/plugins/MouseGestures/MouseGestures.pro | 4 +- 3 files changed, 59 insertions(+), 43 deletions(-) diff --git a/src/lib/webview/tabwidget.cpp b/src/lib/webview/tabwidget.cpp index c2490d3dc..827a0842b 100644 --- a/src/lib/webview/tabwidget.cpp +++ b/src/lib/webview/tabwidget.cpp @@ -101,6 +101,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent) : QTabWidget(parent) , p_QupZilla(mainClass) , m_lastTabIndex(0) + , m_lastBackgroundTabIndex(-1) , m_isClosingToLastTabIndex(false) , m_closedTabsManager(new ClosedTabsManager(this)) , m_locationBars(new QStackedWidget()) @@ -282,7 +283,12 @@ int TabWidget::addView(QUrl url, const QString &title, const Qz::NewTabPositionF if (position == -1 && m_newTabAfterActive && !(openFlags & Qz::NT_TabAtTheEnd)) { // If we are opening newBgTab from pinned tab, make sure it won't be // opened between other pinned tabs - position = qMax(currentIndex() + 1, m_tabBar->pinnedTabsCount()); + if (openFlags & Qz::NT_NotSelectedTab && m_lastBackgroundTabIndex != -1) { + position = m_lastBackgroundTabIndex + 1; + } + else { + position = qMax(currentIndex() + 1, m_tabBar->pinnedTabsCount()); + } } LocationBar* locBar = new LocationBar(p_QupZilla); @@ -306,6 +312,9 @@ int TabWidget::addView(QUrl url, const QString &title, const Qz::NewTabPositionF if (openFlags & Qz::NT_SelectedTab) { setCurrentIndex(index); } + else { + m_lastBackgroundTabIndex = index; + } if (count() == 1 && m_hideTabBarWithOneTab) { tabBar()->setVisible(false); @@ -328,26 +337,11 @@ int TabWidget::addView(QUrl url, const QString &title, const Qz::NewTabPositionF if (openFlags & Qz::NT_SelectedTab) { m_isClosingToLastTabIndex = true; -// m_locationBars->setCurrentWidget(locBar); } return index; } -void TabWidget::setTabText(int index, const QString &text) -{ - QString newtext = text; - newtext.replace("&", "&&"); // Avoid Alt+letter shortcuts - - if (WebTab* webTab = qobject_cast(p_QupZilla->tabWidget()->widget(index))) { - if (webTab->isPinned()) { - newtext = ""; - } - } - - QTabWidget::setTabText(index, newtext); -} - void TabWidget::closeTab(int index) { if (index == -1) { @@ -392,6 +386,8 @@ void TabWidget::closeTab(int index) tabBar()->setVisible(false); } + m_lastBackgroundTabIndex = -1; + webPage->disconnectObjects(); webView->disconnectObjects(); webTab->disconnectObjects(); @@ -399,6 +395,49 @@ void TabWidget::closeTab(int index) webTab->deleteLater(); } +void TabWidget::currentTabChanged(int index) +{ + if (index < 0) { + return; + } + + m_isClosingToLastTabIndex = false; + m_lastBackgroundTabIndex = -1; + + TabbedWebView* webView = weView(); + LocationBar* locBar = webView->webTab()->locationBar(); + + if (m_locationBars->indexOf(locBar) != -1) { + m_locationBars->setCurrentWidget(locBar); + } + + p_QupZilla->currentTabChanged(); + m_tabBar->updateCloseButton(index); +} + +void TabWidget::tabMoved(int before, int after) +{ + Q_UNUSED(before) + Q_UNUSED(after) + + m_isClosingToLastTabIndex = false; + m_lastBackgroundTabIndex = -1; +} + +void TabWidget::setTabText(int index, const QString &text) +{ + QString newtext = text; + newtext.replace("&", "&&"); // Avoid Alt+letter shortcuts + + if (WebTab* webTab = qobject_cast(p_QupZilla->tabWidget()->widget(index))) { + if (webTab->isPinned()) { + newtext = ""; + } + } + + QTabWidget::setTabText(index, newtext); +} + void TabWidget::reloadTab(int index) { weView(index)->reload(); @@ -414,32 +453,6 @@ void TabWidget::showTabBar() } } -void TabWidget::tabMoved(int before, int after) -{ - Q_UNUSED(before) - Q_UNUSED(after) - - m_isClosingToLastTabIndex = false; -} - -void TabWidget::currentTabChanged(int index) -{ - if (index < 0) { - return; - } - - m_isClosingToLastTabIndex = false; - TabbedWebView* webView = weView(); - LocationBar* locBar = webView->webTab()->locationBar(); - - if (m_locationBars->indexOf(locBar) != -1) { - m_locationBars->setCurrentWidget(locBar); - } - - p_QupZilla->currentTabChanged(); - m_tabBar->updateCloseButton(index); -} - void TabWidget::reloadAllTabs() { for (int i = 0; i < count(); i++) { diff --git a/src/lib/webview/tabwidget.h b/src/lib/webview/tabwidget.h index cffed703f..7654e1aff 100644 --- a/src/lib/webview/tabwidget.h +++ b/src/lib/webview/tabwidget.h @@ -109,6 +109,7 @@ private: QupZilla* p_QupZilla; int m_lastTabIndex; + int m_lastBackgroundTabIndex; bool m_isClosingToLastTabIndex; TabBar* m_tabBar; diff --git a/src/plugins/MouseGestures/MouseGestures.pro b/src/plugins/MouseGestures/MouseGestures.pro index 0d09af74f..b1a346093 100644 --- a/src/plugins/MouseGestures/MouseGestures.pro +++ b/src/plugins/MouseGestures/MouseGestures.pro @@ -23,7 +23,9 @@ RESOURCES = mousegestures.qrc TRANSLATIONS = translations/cs_CZ.ts \ translations/sr_BA.ts \ - translations/sr_RS.ts + translations/sr_RS.ts \ + translations/de_DE.ts \ + translations/zh_TW.ts \ include(../../plugins.pri)