mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
[TabBar] Position of add tab button was incorrect sometimes.
Fixed showing add tab button always at correct position. Also removed duplicate code in tabSize.
This commit is contained in:
parent
320f0d20cc
commit
1f5df24a44
@ -208,47 +208,33 @@ QSize TabBar::tabSizeHint(int index) const
|
|||||||
m_normalTabWidth = MAXIMUM_TAB_WIDTH;
|
m_normalTabWidth = MAXIMUM_TAB_WIDTH;
|
||||||
size.setWidth(m_normalTabWidth);
|
size.setWidth(m_normalTabWidth);
|
||||||
}
|
}
|
||||||
else if (availableWidth < MINIMUM_TAB_WIDTH * normalTabsCount) {
|
else {
|
||||||
// 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;
|
int maxWidthForTab = availableWidth / normalTabsCount;
|
||||||
m_activeTabWidth = maxWidthForTab;
|
int realTabWidth = maxWidthForTab;
|
||||||
if (m_activeTabWidth < MINIMUM_ACTIVE_TAB_WIDTH) {
|
if (realTabWidth < MINIMUM_ACTIVE_TAB_WIDTH) {
|
||||||
maxWidthForTab = (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH) / (normalTabsCount - 1);
|
maxWidthForTab = (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH) / (normalTabsCount - 1);
|
||||||
m_activeTabWidth = MINIMUM_ACTIVE_TAB_WIDTH;
|
realTabWidth = MINIMUM_ACTIVE_TAB_WIDTH;
|
||||||
adjustingActiveTab = true;
|
adjustingActiveTab = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool tryAdjusting = false;
|
||||||
|
|
||||||
|
if (availableWidth < MINIMUM_TAB_WIDTH * normalTabsCount) {
|
||||||
|
// 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
|
||||||
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;
|
||||||
if (index == currentIndex()) {
|
if (index == currentIndex()) {
|
||||||
size.setWidth(m_activeTabWidth);
|
size.setWidth(realTabWidth);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
size.setWidth(m_normalTabWidth);
|
size.setWidth(m_normalTabWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_normalTabWidth = maxWidthForTab;
|
tryAdjusting = true;
|
||||||
|
|
||||||
// Fill any empty space (we've got from rounding) with active tab
|
|
||||||
if (index == currentIndex()) {
|
|
||||||
if (adjustingActiveTab) {
|
|
||||||
m_activeTabWidth = (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH
|
|
||||||
- maxWidthForTab * (normalTabsCount - 1)) + m_activeTabWidth;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_activeTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab;
|
|
||||||
}
|
|
||||||
adjustingActiveTab = true;
|
|
||||||
size.setWidth(m_activeTabWidth);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
size.setWidth(m_normalTabWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tabsClosable()) {
|
if (tabsClosable()) {
|
||||||
// Hiding close buttons to save some space
|
// Hiding close buttons to save some space
|
||||||
@ -259,30 +245,9 @@ QSize TabBar::tabSizeHint(int index) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int maxWidthForTab = availableWidth / normalTabsCount;
|
// Tabs fit into tabbar with size between MAXIMUM_TAB_WIDTH and MINIMUM_TAB_WIDTH
|
||||||
m_activeTabWidth = maxWidthForTab;
|
// There won't be any empty space in tabbar
|
||||||
if (m_activeTabWidth < MINIMUM_ACTIVE_TAB_WIDTH) {
|
tryAdjusting = true;
|
||||||
maxWidthForTab = (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH) / (normalTabsCount - 1);
|
|
||||||
m_activeTabWidth = MINIMUM_ACTIVE_TAB_WIDTH;
|
|
||||||
adjustingActiveTab = true;
|
|
||||||
}
|
|
||||||
m_normalTabWidth = maxWidthForTab;
|
|
||||||
|
|
||||||
// Fill any empty space (we've got from rounding) with active tab
|
|
||||||
if (index == currentIndex()) {
|
|
||||||
if (adjustingActiveTab) {
|
|
||||||
m_activeTabWidth = (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH
|
|
||||||
- maxWidthForTab * (normalTabsCount - 1)) + m_activeTabWidth;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_activeTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab;
|
|
||||||
}
|
|
||||||
adjustingActiveTab = true;
|
|
||||||
size.setWidth(m_activeTabWidth);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
size.setWidth(m_normalTabWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore close buttons according to preferences
|
// Restore close buttons according to preferences
|
||||||
if (!tabsClosable()) {
|
if (!tabsClosable()) {
|
||||||
@ -294,11 +259,34 @@ QSize TabBar::tabSizeHint(int index) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tryAdjusting) {
|
||||||
|
m_normalTabWidth = maxWidthForTab;
|
||||||
|
|
||||||
|
// Fill any empty space (we've got from rounding) with active tab
|
||||||
|
if (index == currentIndex()) {
|
||||||
|
if (adjustingActiveTab) {
|
||||||
|
m_activeTabWidth += (availableWidth - MINIMUM_ACTIVE_TAB_WIDTH
|
||||||
|
- maxWidthForTab * (normalTabsCount - 1));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_activeTabWidth = (availableWidth - maxWidthForTab * normalTabsCount) + maxWidthForTab;
|
||||||
|
}
|
||||||
|
adjustingActiveTab = true;
|
||||||
|
size.setWidth(m_activeTabWidth);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
size.setWidth(m_normalTabWidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == currentIndex()) {
|
if (index == count() - 1) {
|
||||||
|
WebTab* currentTab = qobject_cast<WebTab*>(m_tabWidget->widget(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 (adjustingActiveTab) {
|
|
||||||
|
if (currentTab && !currentTab->isPinned() && m_activeTabWidth > m_normalTabWidth) {
|
||||||
xForAddTabButton += m_activeTabWidth - m_normalTabWidth;
|
xForAddTabButton += m_activeTabWidth - m_normalTabWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,6 +294,7 @@ QSize TabBar::tabSizeHint(int index) const
|
|||||||
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
||||||
xForAddTabButton = width() - xForAddTabButton;
|
xForAddTabButton = width() - xForAddTabButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit tabBar->moveAddTabButton(xForAddTabButton);
|
emit tabBar->moveAddTabButton(xForAddTabButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user