diff --git a/kstyle/breeze.h b/kstyle/breeze.h --- a/kstyle/breeze.h +++ b/kstyle/breeze.h @@ -67,7 +67,7 @@ // menu items Menu_FrameWidth = 0, - MenuItem_MarginWidth = 3, + MenuItem_MarginWidth = 4, MenuItem_ItemSpacing = 4, MenuItem_AcceleratorSpace = 16, MenuButton_IndicatorWidth = 20, diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -4646,7 +4646,6 @@ const auto color( _helper->separatorColor( palette ) ); _helper->renderSeparator( painter, rect, color ); - return true; } else { @@ -4656,11 +4655,9 @@ */ QStyleOptionToolButton copy( separatorMenuItemOption( menuItemOption, widget ) ); renderMenuTitle( ©, painter, widget ); - - return true; - } + return true; } // store state @@ -4671,6 +4668,55 @@ const bool reverseLayout( option->direction == Qt::RightToLeft ); const bool useStrongFocus( StyleConfigData::menuItemDrawStrongFocus() ); + // define relevant rectangles + auto contentsRect( insideMargin( rect, Metrics::MenuItem_MarginWidth ) ); + + QRect checkableRect = QRect( + contentsRect.left(), + contentsRect.top() + (contentsRect.height() - Metrics::CheckBox_Size) / 2, + Metrics::CheckBox_Size, + Metrics::CheckBox_Size ); + contentsRect.setLeft( checkableRect.right() + Metrics::MenuItem_ItemSpacing + 1 ); + + QRect iconRect; + const bool showIcon = showIconsInMenuItems(); + if( showIcon ) + { + const int iconWidth = isQtQuickControl( option, widget ) + ? qMax( pixelMetric( PM_SmallIconSize, option, widget ), menuItemOption->maxIconWidth ) + : menuItemOption->maxIconWidth; + + iconRect = QRect( + contentsRect.left(), + contentsRect.top() + (contentsRect.height() - iconWidth) / 2, + iconWidth, + iconWidth ); + contentsRect.setLeft( iconRect.right() + Metrics::MenuItem_ItemSpacing + 1 ); + const QSize iconSize( + pixelMetric( PM_SmallIconSize, option, widget ), + pixelMetric( PM_SmallIconSize, option, widget ) ); + iconRect = centerRect( iconRect, iconSize ); + } + + QRect arrowRect( + contentsRect.right() - Metrics::MenuButton_IndicatorWidth + 1, + contentsRect.top() + (contentsRect.height() - Metrics::MenuButton_IndicatorWidth) / 2, + Metrics::MenuButton_IndicatorWidth, + Metrics::MenuButton_IndicatorWidth ); + contentsRect.setRight( arrowRect.left() - Metrics::MenuItem_ItemSpacing - 1 ); + + auto textRect = contentsRect; + + // center checkbox/radiobutton + if( showIcon && !menuItemOption->icon.isNull() ) + { + int dx = (iconRect.left() - Metrics::CheckBox_Size) / 2; + checkableRect.moveLeft( dx ); + } else if( !menuItemOption->text.isEmpty() ) { + int dx = (textRect.left() - Metrics::CheckBox_Size) / 2; + checkableRect.moveLeft( dx ); + } + // render hover and focus if( useStrongFocus && ( selected || sunken ) ) { @@ -4691,59 +4737,41 @@ } - // get rect available for contents - auto contentsRect( insideMargin( rect, Metrics::MenuItem_MarginWidth ) ); - - // define relevant rectangles - // checkbox - QRect checkBoxRect; - checkBoxRect = QRect( contentsRect.left(), contentsRect.top() + (contentsRect.height()-Metrics::CheckBox_Size)/2, Metrics::CheckBox_Size, Metrics::CheckBox_Size ); - contentsRect.setLeft( checkBoxRect.right() + Metrics::MenuItem_ItemSpacing + 1 ); - - // render checkbox indicator + // render checkbox/radiobutton if( menuItemOption->checkType == QStyleOptionMenuItem::NonExclusive ) { - checkBoxRect = visualRect( option, checkBoxRect ); + checkableRect = visualRect( option, checkableRect ); // checkbox state if( useStrongFocus && ( selected || sunken ) ) - { _helper->renderCheckBoxBackground( painter, checkBoxRect, palette.color( QPalette::Window ), sunken ); } + { _helper->renderCheckBoxBackground( painter, checkableRect, palette.color( QPalette::Window ), sunken ); } CheckBoxState state( menuItemOption->checked ? CheckOn : CheckOff ); const bool active( menuItemOption->checked ); const auto shadow( _helper->shadowColor( palette ) ); const auto color( _helper->checkBoxIndicatorColor( palette, false, enabled && active ) ); - _helper->renderCheckBox( painter, checkBoxRect, color, shadow, sunken, state ); + _helper->renderCheckBox( painter, checkableRect, color, shadow, sunken, state ); } else if( menuItemOption->checkType == QStyleOptionMenuItem::Exclusive ) { - checkBoxRect = visualRect( option, checkBoxRect ); + checkableRect = visualRect( option, checkableRect ); if( useStrongFocus && ( selected || sunken ) ) - { _helper->renderRadioButtonBackground( painter, checkBoxRect, palette.color( QPalette::Window ), sunken ); } + { _helper->renderRadioButtonBackground( painter, checkableRect, palette.color( QPalette::Window ), sunken ); } const bool active( menuItemOption->checked ); const auto shadow( _helper->shadowColor( palette ) ); const auto color( _helper->checkBoxIndicatorColor( palette, false, enabled && active ) ); - _helper->renderRadioButton( painter, checkBoxRect, color, shadow, sunken, active ? RadioOn:RadioOff ); + _helper->renderRadioButton( painter, checkableRect, color, shadow, sunken, active ? RadioOn:RadioOff ); } - // icon - int iconWidth = 0; - const bool showIcon( showIconsInMenuItems() ); - if( showIcon ) iconWidth = isQtQuickControl( option, widget ) ? qMax( pixelMetric(PM_SmallIconSize, option, widget ), menuItemOption->maxIconWidth ) : menuItemOption->maxIconWidth; - - QRect iconRect( contentsRect.left(), contentsRect.top() + (contentsRect.height()-iconWidth)/2, iconWidth, iconWidth ); - contentsRect.setLeft( iconRect.right() + Metrics::MenuItem_ItemSpacing + 1 ); - + // render icon if( showIcon && !menuItemOption->icon.isNull() ) { - const QSize iconSize( pixelMetric( PM_SmallIconSize, option, widget ), pixelMetric( PM_SmallIconSize, option, widget ) ); - iconRect = centerRect( iconRect, iconSize ); iconRect = visualRect( option, iconRect ); // icon mode @@ -4760,34 +4788,7 @@ } - // arrow - QRect arrowRect( contentsRect.right() - Metrics::MenuButton_IndicatorWidth + 1, contentsRect.top() + (contentsRect.height()-Metrics::MenuButton_IndicatorWidth)/2, Metrics::MenuButton_IndicatorWidth, Metrics::MenuButton_IndicatorWidth ); - contentsRect.setRight( arrowRect.left() - Metrics::MenuItem_ItemSpacing - 1 ); - - if( menuItemOption->menuItemType == QStyleOptionMenuItem::SubMenu ) - { - - // apply right-to-left layout - arrowRect = visualRect( option, arrowRect ); - - // arrow orientation - const ArrowOrientation orientation( reverseLayout ? ArrowLeft:ArrowRight ); - - // color - QColor arrowColor; - if( useStrongFocus && ( selected || sunken ) ) arrowColor = palette.color( QPalette::HighlightedText ); - else if( sunken ) arrowColor = _helper->focusColor( palette ); - else if( selected ) arrowColor = _helper->hoverColor( palette ); - else arrowColor = _helper->arrowColor( palette, QPalette::WindowText ); - - // render - _helper->renderArrow( painter, arrowRect, arrowColor, orientation ); - - } - - - // text - auto textRect = contentsRect; + // render text and shortcut hint if( !menuItemOption->text.isEmpty() ) { @@ -4833,6 +4834,28 @@ } + // render arrow + if( menuItemOption->menuItemType == QStyleOptionMenuItem::SubMenu ) + { + + // apply right-to-left layout + arrowRect = visualRect( option, arrowRect ); + + // arrow orientation + const ArrowOrientation orientation( reverseLayout ? ArrowLeft:ArrowRight ); + + // color + QColor arrowColor; + if( useStrongFocus && ( selected || sunken ) ) arrowColor = palette.color( QPalette::HighlightedText ); + else if( sunken ) arrowColor = _helper->focusColor( palette ); + else if( selected ) arrowColor = _helper->hoverColor( palette ); + else arrowColor = _helper->arrowColor( palette, QPalette::WindowText ); + + // render + _helper->renderArrow( painter, arrowRect, arrowColor, orientation ); + + } + return true; }