1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-19 18:26:34 +01:00

Hiding close buttons when there is not enough space in tabbar

- to partially prevent overflowing tabs into tab buttons
- it is now possible to show 24 tabs in tabbar in
  640*480 window without overflowing

closes #527
This commit is contained in:
nowrep 2012-08-27 14:02:35 +02:00
parent 58a07aed81
commit 1e5b7d92cd
2 changed files with 47 additions and 17 deletions

View File

@ -33,7 +33,7 @@
#include <QRect>
#define MAXIMUM_TAB_WIDTH 250
#define MINIMUM_TAB_WIDTH 50
#define MINIMUM_TAB_WIDTH 125
#ifdef Q_WS_WIN
#define PINNED_TAB_WIDTH 38
@ -48,16 +48,16 @@ TabBar::TabBar(QupZilla* mainClass, TabWidget* tabWidget)
, p_QupZilla(mainClass)
, m_tabWidget(tabWidget)
, m_tabPreview(new TabPreview(mainClass, tabWidget))
, m_showTabPreviews(false)
, m_showCloseButtons(false)
, m_clickedTab(0)
, m_pinnedTabsCount(0)
, m_normalTabWidth(0)
, m_lastTabWidth(0)
, m_adjustingLastTab(false)
{
setObjectName("tabbar");
setContextMenuPolicy(Qt::CustomContextMenu);
setElideMode(Qt::ElideRight);
setTabsClosable(true);
setDocumentMode(true);
setFocusPolicy(Qt::NoFocus);
setMouseTracking(true);
@ -83,13 +83,11 @@ void TabBar::loadSettings()
m_tabPreview->setAnimationsEnabled(settings.value("tabPreviewAnimationsEnabled", true).toBool());
m_showTabPreviews = settings.value("showTabPreviews", true).toBool();
m_showCloseButtons = settings.value("showCloseButtonOnTabs", true).toBool();
bool activateLastTab = settings.value("ActivateLastTabWhenClosingActual", false).toBool();
if (settings.value("ActivateLastTabWhenClosingActual", false).toBool()) {
setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);
}
else {
setSelectionBehaviorOnRemove(QTabBar::SelectRightTab);
}
setTabsClosable(m_showCloseButtons);
setSelectionBehaviorOnRemove(activateLastTab ? QTabBar::SelectPreviousTab : QTabBar::SelectRightTab);
settings.endGroup();
}
@ -180,7 +178,7 @@ QSize TabBar::tabSizeHint(int index) const
QSize size = QTabBar::tabSizeHint(index);
WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index));
TabBar* tabBar = const_cast <TabBar*>(this);
m_adjustingLastTab = false;
bool adjustingLastTab = false;
if (webTab && webTab->isPinned()) {
size.setWidth(PINNED_TAB_WIDTH);
@ -193,31 +191,63 @@ QSize TabBar::tabSizeHint(int index) const
size.setWidth(m_normalTabWidth);
}
else if (availableWidth < MINIMUM_TAB_WIDTH * normalTabsCount) {
m_normalTabWidth = MINIMUM_TAB_WIDTH;
size.setWidth(m_normalTabWidth);
// Tabs don't fit at all in tabbar even with MINIMUM_TAB_WIDTH
// We will try to use as low width of tabs as possible
// to try avoid overflowing tabs into tabbar buttons
int maxWidthForTab = availableWidth / normalTabsCount;
if (maxWidthForTab < PINNED_TAB_WIDTH) {
// FIXME: It overflows now
m_normalTabWidth = PINNED_TAB_WIDTH;
size.setWidth(m_normalTabWidth);
}
else {
m_normalTabWidth = maxWidthForTab;
// Fill any empty space (we've got from rounding) with last tab
if (index == count() - 1) {
m_lastTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab;
adjustingLastTab = true;
size.setWidth(m_lastTabWidth);
}
else {
m_lastTabWidth = maxWidthForTab;
size.setWidth(m_lastTabWidth);
}
// Hiding close buttons to save some space
tabBar->setTabsClosable(false);
}
}
else {
int maxWidthForTab = availableWidth / normalTabsCount;
m_normalTabWidth = maxWidthForTab;
//Fill any empty space (we've got from rounding) with last tab
// Fill any empty space (we've got from rounding) with last tab
if (index == count() - 1) {
m_lastTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab;
m_adjustingLastTab = true;
adjustingLastTab = true;
size.setWidth(m_lastTabWidth);
}
else {
m_lastTabWidth = maxWidthForTab;
size.setWidth(m_lastTabWidth);
}
if (tabsClosable() != m_showCloseButtons) {
tabBar->setTabsClosable(m_showCloseButtons);
}
}
}
if (index == count() - 1) {
int xForAddTabButton = (PINNED_TAB_WIDTH * m_pinnedTabsCount) + (count() - m_pinnedTabsCount) * (m_normalTabWidth);
if (m_adjustingLastTab) {
if (adjustingLastTab) {
xForAddTabButton += m_lastTabWidth - m_normalTabWidth;
}
//RTL Support
// RTL Support
if (QApplication::layoutDirection() == Qt::RightToLeft) {
xForAddTabButton = width() - xForAddTabButton;
}

View File

@ -100,13 +100,13 @@ private:
QTimer* m_tabPreviewTimer;
bool m_showTabPreviews;
bool m_showCloseButtons;
int m_clickedTab;
int m_pinnedTabsCount;
mutable int m_normalTabWidth;
mutable int m_lastTabWidth;
mutable bool m_adjustingLastTab;
QPoint m_dragStartPosition;
};