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 @@ -4671,6 +4671,55 @@ 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 + if( showIcon && !menuItemOption->icon.isNull() ) + { + int dx = (iconRect.left() - Metrics::CheckBox_Size) / 2; + checkBoxRect.moveLeft( dx ); + } else if( !menuItemOption->text.isEmpty() ) { + int dx = (textRect.left() - Metrics::CheckBox_Size) / 2; + checkBoxRect.moveLeft( dx ); + } + // render hover and focus if( useStrongFocus && ( selected || sunken ) ) { @@ -4691,15 +4740,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 +4771,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 +4791,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 +4812,7 @@ } - // text - auto textRect = contentsRect; if( !menuItemOption->text.isEmpty() ) {