1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-14 11:02:19 +01:00

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
This commit is contained in:
nowrep 2012-02-27 17:51:57 +01:00
parent 83104a3f9e
commit bcd411c1c0
3 changed files with 59 additions and 43 deletions

View File

@ -101,6 +101,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent)
: QTabWidget(parent) : QTabWidget(parent)
, p_QupZilla(mainClass) , p_QupZilla(mainClass)
, m_lastTabIndex(0) , m_lastTabIndex(0)
, m_lastBackgroundTabIndex(-1)
, m_isClosingToLastTabIndex(false) , m_isClosingToLastTabIndex(false)
, m_closedTabsManager(new ClosedTabsManager(this)) , m_closedTabsManager(new ClosedTabsManager(this))
, m_locationBars(new QStackedWidget()) , m_locationBars(new QStackedWidget())
@ -282,8 +283,13 @@ int TabWidget::addView(QUrl url, const QString &title, const Qz::NewTabPositionF
if (position == -1 && m_newTabAfterActive && !(openFlags & Qz::NT_TabAtTheEnd)) { if (position == -1 && m_newTabAfterActive && !(openFlags & Qz::NT_TabAtTheEnd)) {
// 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) {
position = m_lastBackgroundTabIndex + 1;
}
else {
position = qMax(currentIndex() + 1, m_tabBar->pinnedTabsCount()); position = qMax(currentIndex() + 1, m_tabBar->pinnedTabsCount());
} }
}
LocationBar* locBar = new LocationBar(p_QupZilla); LocationBar* locBar = new LocationBar(p_QupZilla);
m_locationBars->addWidget(locBar); m_locationBars->addWidget(locBar);
@ -306,6 +312,9 @@ int TabWidget::addView(QUrl url, const QString &title, const Qz::NewTabPositionF
if (openFlags & Qz::NT_SelectedTab) { if (openFlags & Qz::NT_SelectedTab) {
setCurrentIndex(index); setCurrentIndex(index);
} }
else {
m_lastBackgroundTabIndex = index;
}
if (count() == 1 && m_hideTabBarWithOneTab) { if (count() == 1 && m_hideTabBarWithOneTab) {
tabBar()->setVisible(false); tabBar()->setVisible(false);
@ -328,26 +337,11 @@ int TabWidget::addView(QUrl url, const QString &title, const Qz::NewTabPositionF
if (openFlags & Qz::NT_SelectedTab) { if (openFlags & Qz::NT_SelectedTab) {
m_isClosingToLastTabIndex = true; m_isClosingToLastTabIndex = true;
// m_locationBars->setCurrentWidget(locBar);
} }
return index; return index;
} }
void TabWidget::setTabText(int index, const QString &text)
{
QString newtext = text;
newtext.replace("&", "&&"); // Avoid Alt+letter shortcuts
if (WebTab* webTab = qobject_cast<WebTab*>(p_QupZilla->tabWidget()->widget(index))) {
if (webTab->isPinned()) {
newtext = "";
}
}
QTabWidget::setTabText(index, newtext);
}
void TabWidget::closeTab(int index) void TabWidget::closeTab(int index)
{ {
if (index == -1) { if (index == -1) {
@ -392,6 +386,8 @@ void TabWidget::closeTab(int index)
tabBar()->setVisible(false); tabBar()->setVisible(false);
} }
m_lastBackgroundTabIndex = -1;
webPage->disconnectObjects(); webPage->disconnectObjects();
webView->disconnectObjects(); webView->disconnectObjects();
webTab->disconnectObjects(); webTab->disconnectObjects();
@ -399,6 +395,49 @@ void TabWidget::closeTab(int index)
webTab->deleteLater(); 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<WebTab*>(p_QupZilla->tabWidget()->widget(index))) {
if (webTab->isPinned()) {
newtext = "";
}
}
QTabWidget::setTabText(index, newtext);
}
void TabWidget::reloadTab(int index) void TabWidget::reloadTab(int index)
{ {
weView(index)->reload(); 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() void TabWidget::reloadAllTabs()
{ {
for (int i = 0; i < count(); i++) { for (int i = 0; i < count(); i++) {

View File

@ -109,6 +109,7 @@ private:
QupZilla* p_QupZilla; QupZilla* p_QupZilla;
int m_lastTabIndex; int m_lastTabIndex;
int m_lastBackgroundTabIndex;
bool m_isClosingToLastTabIndex; bool m_isClosingToLastTabIndex;
TabBar* m_tabBar; TabBar* m_tabBar;

View File

@ -23,7 +23,9 @@ RESOURCES = mousegestures.qrc
TRANSLATIONS = translations/cs_CZ.ts \ TRANSLATIONS = translations/cs_CZ.ts \
translations/sr_BA.ts \ translations/sr_BA.ts \
translations/sr_RS.ts translations/sr_RS.ts \
translations/de_DE.ts \
translations/zh_TW.ts \
include(../../plugins.pri) include(../../plugins.pri)