1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +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)
, 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<WebTab*>(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<WebTab*>(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++) {

View File

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

View File

@ -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)