- calculate pushbutton size from scratch rather than relying on the contentsSize calculated from Qt

- honour showIconsOnPushButtons from kde globals
wilder-pre-rebase
Hugo Pereira Da Costa 10 years ago
parent 22c1ded25f
commit 5367cb88f0
  1. 69
      kstyle/breezestyle.cpp
  2. 3
      kstyle/breezestyle.h

@ -2592,39 +2592,47 @@ namespace Breeze
const QStyleOptionButton* buttonOption( qstyleoption_cast<const QStyleOptionButton*>( option ) );
if( !buttonOption ) return contentsSize;
QSize size( contentsSize );
// add space for arrow
if( buttonOption->features & QStyleOptionButton::HasMenu )
{
size.rheight() += 2*Metrics::Button_MarginWidth;
size.setHeight( qMax( size.height(), int( Metrics::MenuButton_IndicatorWidth ) ) );
size.rwidth() += Metrics::Button_MarginWidth;
if( !( buttonOption->icon.isNull() && buttonOption->text.isEmpty() ) )
{ size.rwidth() += Metrics::Button_ItemSpacing; }
/*
rather than trying to guess what Qt puts into its contents size calculation,
we recompute the button size entirely, based on button option
this ensures consistency with the rendering stage
*/
QSize size;
} else size = expandSize( size, Metrics::Button_MarginWidth );
// text
const bool hasText( !buttonOption->text.isEmpty() );
if( hasText ) size = buttonOption->fontMetrics.size( Qt::TextShowMnemonic, buttonOption->text );
// add space for icon
if( !buttonOption->icon.isNull() )
// icon
const bool flat( buttonOption->features & QStyleOptionButton::Flat );
const bool hasIcon( (showIconsOnPushButtons() || flat || !hasText ) && !buttonOption->icon.isNull() );
if( hasIcon )
{
QSize iconSize = buttonOption->iconSize;
if( !iconSize.isValid() ) iconSize = QSize( pixelMetric( PM_SmallIconSize, option, widget ), pixelMetric( PM_SmallIconSize, option, widget ) );
size.setHeight( qMax( size.height(), iconSize.height() ) );
size.rwidth() += iconSize.width();
if( !buttonOption->text.isEmpty() )
{ size.rwidth() += Metrics::Button_ItemSpacing; }
if( hasText ) size.rwidth() += Metrics::Button_ItemSpacing;
}
// menu
const bool hasMenu( buttonOption->features & QStyleOptionButton::HasMenu );
if( hasMenu )
{
size.rwidth() += Metrics::MenuButton_IndicatorWidth;
if( hasText||hasIcon ) size.rwidth() += Metrics::Button_ItemSpacing;
}
// expand with buttons margin
size = expandSize( size, Metrics::Button_MarginWidth );
// make sure buttons have a minimum width
if( !buttonOption->text.isEmpty() )
{ size.rwidth() = qMax( size.rwidth(), int( Metrics::Button_MinWidth ) ); }
if( hasText )
{ size.setWidth( qMax( size.width(), int( Metrics::Button_MinWidth ) ) ); }
// finally add margins
// finally add frame margins
return expandSize( size, Metrics::Frame_FrameWidth );
}
@ -4069,8 +4077,8 @@ namespace Breeze
const bool flat( buttonOption->features & QStyleOptionButton::Flat );
// content
const bool hasIcon( !buttonOption->icon.isNull() );
const bool hasText( !buttonOption->text.isEmpty() );
const bool hasIcon( (showIconsOnPushButtons() || flat || !hasText ) && !buttonOption->icon.isNull() );
// contents
QRect contentsRect( rect );
@ -4108,11 +4116,15 @@ namespace Breeze
}
// icon size
QSize iconSize( buttonOption->iconSize );
if( !iconSize.isValid() )
QSize iconSize;
if( hasIcon )
{
const int metric( pixelMetric( PM_SmallIconSize, option, widget ) );
iconSize = QSize( metric, metric );
iconSize = buttonOption->iconSize;
if( !iconSize.isValid() )
{
const int metric( pixelMetric( PM_SmallIconSize, option, widget ) );
iconSize = QSize( metric, metric );
}
}
// text size
@ -6823,6 +6835,13 @@ namespace Breeze
#endif
}
//____________________________________________________________________
bool Style::showIconsOnPushButtons( void ) const
{
const KConfigGroup g(KSharedConfig::openConfig(), "KDE");
return g.readEntry("ShowIconsOnPushButtons", true);
}
//____________________________________________________________________
bool Style::isMenuTitle( const QWidget* widget ) const
{

@ -457,6 +457,9 @@ namespace Breeze
//* return true if one of the widget's parent inherits requested type
template<typename T> bool hasParent( const QWidget* ) const;
//* return true if icons should be shown on buttons
bool showIconsOnPushButtons( void ) const;
//* return true if passed widget is a menu title (KMenu::addTitle)
bool isMenuTitle( const QWidget* ) const;

Loading…
Cancel
Save