From ca61bd99bc2284dc4566bea8443ef6a540b424ba Mon Sep 17 00:00:00 2001 From: Kurt Hindenburg Date: Sat, 17 Apr 2010 21:38:14 +0000 Subject: [PATCH] Change the way the tab widths are calcuated and their text to allow better space usage. Patches/comments to make this better welcomed. I wanted something committed for KDE 4.5. CCBUG: 157201 svn path=/trunk/KDE/kdebase/apps/konsole/; revision=1115895 --- src/ViewContainer.cpp | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/ViewContainer.cpp b/src/ViewContainer.cpp index cbcbcfa3..e1d696f1 100644 --- a/src/ViewContainer.cpp +++ b/src/ViewContainer.cpp @@ -260,6 +260,7 @@ ViewContainerTabBar::ViewContainerTabBar(QWidget* parent,TabbedViewContainer* co , _dropIndicatorIndex(-1) , _drawIndicatorDisabled(false) { + setElideMode(Qt::ElideLeft); } void ViewContainerTabBar::setDropIndicator(int index, bool drawDisabled) { @@ -395,9 +396,31 @@ void ViewContainerTabBar::dropEvent(QDropEvent* event) event->ignore(); } +/* Try to provide a reasonable tab width: + * If there are less than 5 tabs, let the tabs fill out the tabbar. + * Otherwise, check the tab text size and the minimumTabWidth value. + * The minimumTabWidth is to prevent the tabs from getting too + * small such that no scroll indicators will appear. +*/ QSize ViewContainerTabBar::tabSizeHint(int index) const { - return QTabBar::tabSizeHint(index); + const int fillTabCount = 5; + const int minimumTabWidth = 150; // Arbitrary value + int tabBarWidth = rect().width(); + int tabCount = count(); + int tabMaxWidth; + if (tabCount <= fillTabCount) + tabMaxWidth = tabBarWidth / (tabCount + 0.5); + else + tabMaxWidth = tabBarWidth / (fillTabCount + 0.5); + + int tabTextWidth = fontMetrics().width(tabText(index)); + // qBound ( minimum, value, max ) + kDebug()< iter(widgetsForItem(item)); while ( iter.hasNext() ) { const int index = _stackWidget->indexOf( iter.next() ); - QString tabText = item->title(); - if (tabText.count() > MAX_TAB_TEXT_LENGTH) - tabText = tabText.right(MAX_TAB_TEXT_LENGTH).prepend("..."); _tabBar->setTabText( index , tabText ); } -- GitLab