diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -4671,6 +4671,52 @@ const bool reverseLayout( option->direction == Qt::RightToLeft ); const bool useStrongFocus( StyleConfigData::menuItemDrawStrongFocus() ); + // define relevant rectangles + auto contentsRect( insideMargin( rect, Metrics::MenuItem_MarginWidth ) ); + + QRect 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 ); + + 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 indicator + int dx = showIcon && menuItemOption->maxIconWidth > 0 + ? iconRect.left() + : textRect.left(); + dx = (dx - checkBoxRect.width()) / 2; + checkBoxRect.moveLeft( dx ); + // render hover and focus if( useStrongFocus && ( selected || sunken ) ) { @@ -4691,15 +4737,6 @@ } - // 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 if( menuItemOption->checkType == QStyleOptionMenuItem::NonExclusive ) { @@ -4731,19 +4768,9 @@ } - // 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 ); - 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 @@ -4761,9 +4788,6 @@ } // 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 ) { @@ -4785,9 +4809,7 @@ } - // text - auto textRect = contentsRect; if( !menuItemOption->text.isEmpty() ) {