From 430cf3193f907c1fcf7ee1b6f4e567735106f6aa Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Wed, 6 Aug 2014 21:42:43 +0200 Subject: [PATCH] Render 'named' separators as sunken, flat toolbuttons --- kstyle/breezestyle.cpp | 48 +++++++++++++++++++++++++++++++----------- kstyle/breezestyle.h | 11 ++++++++-- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 4c91fbfb..a104bccd 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -2111,14 +2111,15 @@ namespace Breeze } else { - // separator can have a title and an icon - // in that case they are rendered as menubar 'title', which - // corresponds to checked toolbuttons. - // a rectangle identical to the one of normal items is returned. - QStyleOptionMenuItem copy( *menuItemOption ); - copy.menuItemType = QStyleOptionMenuItem::Normal; - return menuItemSizeFromContents( ©, contentsSize, widget ); + // build toolbutton option + const QStyleOptionToolButton toolButtonOption( separatorMenuItemOption( menuItemOption, widget ) ); + // make sure height is large enough for icon + const int iconWidth( qMax( menuItemOption->maxIconWidth, pixelMetric( PM_SmallIconSize, option, widget ) ) ); + size.setHeight( qMax( size.height(), (int) iconWidth ) ); + + // return size from CT_ToolButton + return sizeFromContents( CT_ToolButton, &toolButtonOption, size, widget ); } } @@ -3401,11 +3402,10 @@ namespace Breeze } else { // separator can have a title and an icon - // in that case they are rendered as normal, disabled items - QStyleOptionMenuItem copy( *menuItemOption ); - copy.menuItemType = QStyleOptionMenuItem::Normal; - copy.state &= ~(State_Selected|State_Enabled|State_HasFocus|State_MouseOver); - return drawMenuItemControl( ©, painter, widget ); + // in that case they are rendered as sunken flat toolbuttons + QStyleOptionToolButton toolButtonOption( separatorMenuItemOption( menuItemOption, widget ) ); + drawComplexControl( CC_ToolButton, &toolButtonOption, painter, widget ); + return true; } @@ -5387,6 +5387,30 @@ namespace Breeze } + //____________________________________________________________________________________ + QStyleOptionToolButton Style::separatorMenuItemOption( const QStyleOptionMenuItem* menuItemOption, const QWidget* widget ) const + { + + // separator can have a title and an icon + // in that case they are rendered as sunken flat toolbuttons + QStyleOptionToolButton toolButtonOption; + toolButtonOption.initFrom( widget ); + toolButtonOption.rect = menuItemOption->rect; + toolButtonOption.features = QStyleOptionToolButton::None; + toolButtonOption.state = State_On|State_Sunken|State_Enabled|State_AutoRaise; + toolButtonOption.subControls = SC_ToolButton; + toolButtonOption.icon = menuItemOption->icon; + + int iconWidth( pixelMetric( PM_SmallIconSize, menuItemOption, widget ) ); + toolButtonOption.iconSize = QSize( iconWidth, iconWidth ); + toolButtonOption.text = menuItemOption->text; + + toolButtonOption.toolButtonStyle = Qt::ToolButtonTextBesideIcon; + + return toolButtonOption; + + } + //____________________________________________________________________________________ QIcon Style::iconFromResource( const QString& name ) const { diff --git a/kstyle/breezestyle.h b/kstyle/breezestyle.h index 754b57ca..d0461f56 100644 --- a/kstyle/breezestyle.h +++ b/kstyle/breezestyle.h @@ -460,10 +460,17 @@ namespace Breeze //@} - // translucent background + //! translucent background void setTranslucentBackground( QWidget* ) const; - // load icon from svg resource + /*! + separator can have a title and an icon + in that case they are rendered as sunken flat toolbuttons + return toolbutton option that matches named separator menu items + */ + QStyleOptionToolButton separatorMenuItemOption( const QStyleOptionMenuItem*, const QWidget* ) const; + + //! load icon from svg resource QIcon iconFromResource( const QString& ) const; private: