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 <Thomas.Hartmann@nokia.com>
This commit is contained in:
Alessandro Portale
2012-09-13 14:49:14 +02:00
parent edab369be8
commit 6c55cb458f

View File

@@ -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);
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);