1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Merge pull request #672 from srazi/master

A better size-hint for active tab.
This commit is contained in:
David Rosca 2012-12-11 04:29:08 -08:00
commit 7b66f5551b
2 changed files with 53 additions and 21 deletions

View File

@ -46,7 +46,7 @@ TabBar::TabBar(QupZilla* mainClass, TabWidget* tabWidget)
, m_clickedTab(0) , m_clickedTab(0)
, m_pinnedTabsCount(0) , m_pinnedTabsCount(0)
, m_normalTabWidth(0) , m_normalTabWidth(0)
, m_lastTabWidth(0) , m_activeTabWidth(0)
{ {
setObjectName("tabbar"); setObjectName("tabbar");
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
@ -174,15 +174,19 @@ QSize TabBar::tabSizeHint(int index) const
} }
static int PINNED_TAB_WIDTH = -1; static int PINNED_TAB_WIDTH = -1;
static int MINIMUM_ACTIVE_TAB_WIDTH = -1;
if (PINNED_TAB_WIDTH == -1) { if (PINNED_TAB_WIDTH == -1) {
PINNED_TAB_WIDTH = 16 + style()->pixelMetric(QStyle::PM_TabBarTabHSpace, 0, this); PINNED_TAB_WIDTH = 16 + style()->pixelMetric(QStyle::PM_TabBarTabHSpace, 0, this);
MINIMUM_ACTIVE_TAB_WIDTH = PINNED_TAB_WIDTH + style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, this);
// just a hack: we want to be sure buttonAddTab and buttonListTabs can't cover the active tab
MINIMUM_ACTIVE_TAB_WIDTH = qMax(MINIMUM_ACTIVE_TAB_WIDTH, 6 + m_tabWidget->buttonListTabs()->width() + m_tabWidget->buttonAddTab()->width());
} }
QSize size = QTabBar::tabSizeHint(index); QSize size = QTabBar::tabSizeHint(index);
WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index)); WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(index));
TabBar* tabBar = const_cast <TabBar*>(this); TabBar* tabBar = const_cast <TabBar*>(this);
bool adjustingLastTab = false; bool adjustingActiveTab = false;
if (webTab && webTab->isPinned()) { if (webTab && webTab->isPinned()) {
size.setWidth(PINNED_TAB_WIDTH); size.setWidth(PINNED_TAB_WIDTH);
@ -200,24 +204,41 @@ QSize TabBar::tabSizeHint(int index) const
// to try avoid overflowing tabs into tabbar buttons // to try avoid overflowing tabs into tabbar buttons
int maxWidthForTab = availableWidth / normalTabsCount; int maxWidthForTab = availableWidth / normalTabsCount;
m_activeTabWidth = maxWidthForTab;
if (m_activeTabWidth < MINIMUM_ACTIVE_TAB_WIDTH) {
maxWidthForTab = (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH) / (normalTabsCount - 1);
m_activeTabWidth = MINIMUM_ACTIVE_TAB_WIDTH;
adjustingActiveTab = true;
}
if (maxWidthForTab < PINNED_TAB_WIDTH) { if (maxWidthForTab < PINNED_TAB_WIDTH) {
// FIXME: It overflows now // FIXME: It overflows now
m_normalTabWidth = PINNED_TAB_WIDTH; m_normalTabWidth = PINNED_TAB_WIDTH;
size.setWidth(m_normalTabWidth); if (index == currentIndex()) {
size.setWidth(m_activeTabWidth);
}
else {
size.setWidth(m_normalTabWidth);
}
} }
else { else {
m_normalTabWidth = maxWidthForTab; 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 active tab
if (index == count() - 1) { if (index == currentIndex()) {
m_lastTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab; if (adjustingActiveTab) {
adjustingLastTab = true; m_activeTabWidth = (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH
size.setWidth(m_lastTabWidth); - maxWidthForTab * (normalTabsCount - 1)) + m_activeTabWidth;
}
else {
m_activeTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab;
}
adjustingActiveTab = true;
size.setWidth(m_activeTabWidth);
} }
else { else {
m_lastTabWidth = maxWidthForTab; size.setWidth(m_normalTabWidth);
size.setWidth(m_lastTabWidth);
} }
if (tabsClosable()) { if (tabsClosable()) {
@ -230,17 +251,28 @@ QSize TabBar::tabSizeHint(int index) const
} }
else { else {
int maxWidthForTab = availableWidth / normalTabsCount; int maxWidthForTab = availableWidth / normalTabsCount;
m_activeTabWidth = maxWidthForTab;
if (m_activeTabWidth < MINIMUM_ACTIVE_TAB_WIDTH) {
maxWidthForTab = (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH) / (normalTabsCount - 1);
m_activeTabWidth = MINIMUM_ACTIVE_TAB_WIDTH;
adjustingActiveTab = true;
}
m_normalTabWidth = maxWidthForTab; 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 active tab
if (index == count() - 1) { if (index == currentIndex()) {
m_lastTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab; if (adjustingActiveTab) {
adjustingLastTab = true; m_activeTabWidth = (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH
size.setWidth(m_lastTabWidth); - maxWidthForTab * (normalTabsCount - 1)) + m_activeTabWidth;
}
else {
m_activeTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab;
}
adjustingActiveTab = true;
size.setWidth(m_activeTabWidth);
} }
else { else {
m_lastTabWidth = maxWidthForTab; size.setWidth(m_normalTabWidth);
size.setWidth(m_lastTabWidth);
} }
// Restore close buttons according to preferences // Restore close buttons according to preferences
@ -255,10 +287,10 @@ QSize TabBar::tabSizeHint(int index) const
} }
} }
if (index == count() - 1) { if (index == currentIndex()) {
int xForAddTabButton = (PINNED_TAB_WIDTH * m_pinnedTabsCount) + (count() - m_pinnedTabsCount) * (m_normalTabWidth); int xForAddTabButton = (PINNED_TAB_WIDTH * m_pinnedTabsCount) + (count() - m_pinnedTabsCount) * (m_normalTabWidth);
if (adjustingLastTab) { if (adjustingActiveTab) {
xForAddTabButton += m_lastTabWidth - m_normalTabWidth; xForAddTabButton += m_activeTabWidth - m_normalTabWidth;
} }
// RTL Support // RTL Support

View File

@ -109,7 +109,7 @@ private:
int m_pinnedTabsCount; int m_pinnedTabsCount;
mutable int m_normalTabWidth; mutable int m_normalTabWidth;
mutable int m_lastTabWidth; mutable int m_activeTabWidth;
QPoint m_dragStartPosition; QPoint m_dragStartPosition;
}; };