Properly center both icons and text in the toolbutton, with correct spacing added, disregarding the available size

wilder-pre-rebase
Hugo Pereira Da Costa 12 years ago
parent 9b508bb20d
commit 79a1808ca4
  1. 21
      kstyle/breezestyle.cpp

@ -3850,10 +3850,13 @@ namespace Breeze
}
// text size
int textFlags( _mnemonics->textFlags() );
const QSize textSize( option->fontMetrics.size( textFlags, toolButtonOption->text ) );
// adjust text and icon rect based on options
QRect iconRect;
QRect textRect;
int textFlags( _mnemonics->textFlags() );
if( hasText && ( !(hasArrow||hasIcon) || toolButtonOption->toolButtonStyle == Qt::ToolButtonTextOnly ) )
{
@ -3869,20 +3872,16 @@ namespace Breeze
} else if( toolButtonOption->toolButtonStyle == Qt::ToolButtonTextUnderIcon ) {
iconRect = rect;
iconRect.setHeight( iconSize.height() + 10 );
textRect = rect;
textRect.adjust( 0, iconRect.height() - 1, 0, -1 );
const int contentsHeight( iconSize.height() + textSize.height() + Metrics::ToolButton_ItemSpacing );
iconRect = QRect( QPoint( rect.left() + (rect.width() - iconSize.width())/2, rect.top() + (rect.height() - contentsHeight)/2 ), iconSize );
textRect = QRect( QPoint( rect.left() + (rect.width() - textSize.width())/2, iconRect.bottom() + Metrics::ToolButton_ItemSpacing + 1 ), textSize );
textFlags |= Qt::AlignCenter;
} else {
iconRect = rect;
iconRect.setWidth( iconSize.width() + 8 );
textRect = rect;
textRect.adjust( iconRect.width(), 0, 0, 0);
const int contentsWidth( iconSize.width() + textSize.width() + Metrics::ToolButton_ItemSpacing );
iconRect = QRect( QPoint( rect.left() + (rect.width() - contentsWidth )/2, rect.top() + (rect.height() - iconSize.height())/2 ), iconSize );
textRect = QRect( QPoint( iconRect.right() + Metrics::ToolButton_ItemSpacing + 1, rect.top() + (rect.height() - textSize.height())/2 ), textSize );
// handle right to left layouts
iconRect = visualRect( option, iconRect );

Loading…
Cancel
Save