From 6c55cb458f4b4c3b66a49cadb6c7318d9ede1d64 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Thu, 13 Sep 2012 14:49:14 +0200 Subject: [PATCH] Hide the Mode Tab Icons when they become too small When resizing the Qt Creator main window to a smaller size, at some point the mode tab icons will shrink to fit all tabs into the window. The icon size will if necessary shrink to tiny sizes below 8px, which is pointless. Let's add some code that hides the icons when a tab becomes smaller than a certain size. Task-Number: QTCREATORBUG-7879 Change-Id: I590379a2ec52a8a86e998c08b29d54aca800e542 Reviewed-by: Thomas Hartmann --- src/plugins/coreplugin/fancytabwidget.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/plugins/coreplugin/fancytabwidget.cpp b/src/plugins/coreplugin/fancytabwidget.cpp index 2bed5a079af..cf2d98fe6cf 100644 --- a/src/plugins/coreplugin/fancytabwidget.cpp +++ b/src/plugins/coreplugin/fancytabwidget.cpp @@ -275,15 +275,16 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const } QString tabText(this->tabText(tabIndex)); - QRect tabTextRect(tabRect(tabIndex)); + QRect tabTextRect(rect); + const bool drawIcon = rect.height() > 36; QRect tabIconRect(tabTextRect); - tabTextRect.translate(0, -2); + tabTextRect.translate(0, drawIcon ? -2 : 1); QFont boldFont(painter->font()); boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize()); boldFont.setBold(true); painter->setFont(boldFont); painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110)); - int textFlags = Qt::AlignCenter | Qt::AlignBottom | Qt::TextWordWrap; + const int textFlags = Qt::AlignCenter | (drawIcon ? Qt::AlignBottom : Qt::AlignVCenter) | Qt::TextWordWrap; if (enabled) { painter->drawText(tabTextRect, textFlags, tabText); painter->setPen(selected ? QColor(60, 60, 60) : Utils::StyleHelper::panelTextColor()); @@ -307,9 +308,11 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const if (!enabled) painter->setOpacity(0.7); - int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height(); - tabIconRect.adjust(0, 4, 0, -textHeight); - Utils::StyleHelper::drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, enabled ? QIcon::Normal : QIcon::Disabled); + if (drawIcon) { + int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height(); + tabIconRect.adjust(0, 4, 0, -textHeight); + Utils::StyleHelper::drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, enabled ? QIcon::Normal : QIcon::Disabled); + } painter->translate(0, -1); painter->drawText(tabTextRect, textFlags, tabText);