Changeset View
Standalone View
kstyle/breezestyle.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 4655 Lines • ▼ Show 20 Line(s) | 4651 | } else { | |||
---|---|---|---|---|---|
4656 | */ | 4656 | */ | ||
4657 | QStyleOptionToolButton copy( separatorMenuItemOption( menuItemOption, widget ) ); | 4657 | QStyleOptionToolButton copy( separatorMenuItemOption( menuItemOption, widget ) ); | ||
4658 | renderMenuTitle( ©, painter, widget ); | 4658 | renderMenuTitle( ©, painter, widget ); | ||
4659 | 4659 | | |||
4660 | return true; | 4660 | return true; | ||
4661 | 4661 | | |||
4662 | } | 4662 | } | ||
4663 | 4663 | | |||
4664 | } | 4664 | } | ||
hpereiradacosta: this change is unrelated. Please revert. | |||||
4665 | 4665 | | |||
4666 | // store state | 4666 | // store state | ||
4667 | const State& state( option->state ); | 4667 | const State& state( option->state ); | ||
4668 | const bool enabled( state & State_Enabled ); | 4668 | const bool enabled( state & State_Enabled ); | ||
4669 | const bool selected( enabled && (state & State_Selected) ); | 4669 | const bool selected( enabled && (state & State_Selected) ); | ||
4670 | const bool sunken( enabled && (state & (State_On|State_Sunken) ) ); | 4670 | const bool sunken( enabled && (state & (State_On|State_Sunken) ) ); | ||
4671 | const bool reverseLayout( option->direction == Qt::RightToLeft ); | 4671 | const bool reverseLayout( option->direction == Qt::RightToLeft ); | ||
4672 | const bool useStrongFocus( StyleConfigData::menuItemDrawStrongFocus() ); | 4672 | const bool useStrongFocus( StyleConfigData::menuItemDrawStrongFocus() ); | ||
4673 | 4673 | | |||
4674 | // define relevant rectangles | ||||
4675 | auto contentsRect( insideMargin( rect, Metrics::MenuItem_MarginWidth ) ); | ||||
4676 | | ||||
4677 | QRect checkBoxRect = QRect( | ||||
4678 | contentsRect.left(), | ||||
4679 | contentsRect.top() + (contentsRect.height() - Metrics::CheckBox_Size) / 2, | ||||
4680 | Metrics::CheckBox_Size, | ||||
4681 | Metrics::CheckBox_Size ); | ||||
4682 | contentsRect.setLeft( checkBoxRect.right() + Metrics::MenuItem_ItemSpacing + 1 ); | ||||
4683 | | ||||
4684 | QRect iconRect; | ||||
4685 | const bool showIcon = showIconsInMenuItems(); | ||||
4686 | if( showIcon ) | ||||
4687 | { | ||||
4688 | const int iconWidth = isQtQuickControl( option, widget ) | ||||
4689 | ? qMax( pixelMetric( PM_SmallIconSize, option, widget ), menuItemOption->maxIconWidth ) | ||||
4690 | : menuItemOption->maxIconWidth; | ||||
4691 | | ||||
4692 | iconRect = QRect( | ||||
4693 | contentsRect.left(), | ||||
4694 | contentsRect.top() + (contentsRect.height() - iconWidth) / 2, | ||||
4695 | iconWidth, | ||||
4696 | iconWidth ); | ||||
4697 | contentsRect.setLeft( iconRect.right() + Metrics::MenuItem_ItemSpacing + 1 ); | ||||
4698 | const QSize iconSize( | ||||
4699 | pixelMetric( PM_SmallIconSize, option, widget ), | ||||
4700 | pixelMetric( PM_SmallIconSize, option, widget ) ); | ||||
4701 | iconRect = centerRect( iconRect, iconSize ); | ||||
4702 | } | ||||
4703 | | ||||
4704 | QRect arrowRect( | ||||
why was this chunk of code moved ? This is unrelated to the change. hpereiradacosta: why was this chunk of code moved ? This is unrelated to the change.
Please try keep the diff to… | |||||
To keep it consistent:
Could you please let it stay here? zzag: To keep it consistent:
1. compute required rectangles
2. align checkbox rect
3. paint text… | |||||
4705 | contentsRect.right() - Metrics::MenuButton_IndicatorWidth + 1, | ||||
4706 | contentsRect.top() + (contentsRect.height() - Metrics::MenuButton_IndicatorWidth) / 2, | ||||
4707 | Metrics::MenuButton_IndicatorWidth, | ||||
4708 | Metrics::MenuButton_IndicatorWidth ); | ||||
4709 | contentsRect.setRight( arrowRect.left() - Metrics::MenuItem_ItemSpacing - 1 ); | ||||
4710 | | ||||
4711 | auto textRect = contentsRect; | ||||
4712 | | ||||
4713 | // center checkbox indicator | ||||
4714 | if( showIcon && !menuItemOption->icon.isNull() ) | ||||
4715 | { | ||||
4716 | int dx = (iconRect.left() - Metrics::CheckBox_Size) / 2; | ||||
4717 | checkBoxRect.moveLeft( dx ); | ||||
4718 | } else if( !menuItemOption->text.isEmpty() ) { | ||||
4719 | int dx = (textRect.left() - Metrics::CheckBox_Size) / 2; | ||||
4720 | checkBoxRect.moveLeft( dx ); | ||||
4721 | } | ||||
4722 | | ||||
4674 | // render hover and focus | 4723 | // render hover and focus | ||
4675 | if( useStrongFocus && ( selected || sunken ) ) | 4724 | if( useStrongFocus && ( selected || sunken ) ) | ||
4676 | { | 4725 | { | ||
4677 | 4726 | | |||
4678 | const auto color = _helper->focusColor( palette ); | 4727 | const auto color = _helper->focusColor( palette ); | ||
4679 | const auto outlineColor = _helper->focusOutlineColor( palette ); | 4728 | const auto outlineColor = _helper->focusOutlineColor( palette ); | ||
4680 | 4729 | | |||
4681 | Sides sides = 0; | 4730 | Sides sides = 0; | ||
4682 | if( !menuItemOption->menuRect.isNull() ) | 4731 | if( !menuItemOption->menuRect.isNull() ) | ||
4683 | { | 4732 | { | ||
4684 | if( rect.top() <= menuItemOption->menuRect.top() ) sides |= SideTop; | 4733 | if( rect.top() <= menuItemOption->menuRect.top() ) sides |= SideTop; | ||
4685 | if( rect.bottom() >= menuItemOption->menuRect.bottom() ) sides |= SideBottom; | 4734 | if( rect.bottom() >= menuItemOption->menuRect.bottom() ) sides |= SideBottom; | ||
4686 | if( rect.left() <= menuItemOption->menuRect.left() ) sides |= SideLeft; | 4735 | if( rect.left() <= menuItemOption->menuRect.left() ) sides |= SideLeft; | ||
4687 | if( rect.right() >= menuItemOption->menuRect.right() ) sides |= SideRight; | 4736 | if( rect.right() >= menuItemOption->menuRect.right() ) sides |= SideRight; | ||
4688 | } | 4737 | } | ||
4689 | 4738 | | |||
4690 | _helper->renderFocusRect( painter, rect, color, outlineColor, sides ); | 4739 | _helper->renderFocusRect( painter, rect, color, outlineColor, sides ); | ||
4691 | 4740 | | |||
4692 | } | 4741 | } | ||
4693 | 4742 | | |||
4694 | // get rect available for contents | | |||
4695 | auto contentsRect( insideMargin( rect, Metrics::MenuItem_MarginWidth ) ); | | |||
4696 | | ||||
4697 | // define relevant rectangles | | |||
4698 | // checkbox | | |||
4699 | QRect checkBoxRect; | | |||
4700 | checkBoxRect = QRect( contentsRect.left(), contentsRect.top() + (contentsRect.height()-Metrics::CheckBox_Size)/2, Metrics::CheckBox_Size, Metrics::CheckBox_Size ); | | |||
4701 | contentsRect.setLeft( checkBoxRect.right() + Metrics::MenuItem_ItemSpacing + 1 ); | | |||
4702 | | ||||
4703 | // render checkbox indicator | 4743 | // render checkbox indicator | ||
4704 | if( menuItemOption->checkType == QStyleOptionMenuItem::NonExclusive ) | 4744 | if( menuItemOption->checkType == QStyleOptionMenuItem::NonExclusive ) | ||
4705 | { | 4745 | { | ||
4706 | 4746 | | |||
4707 | checkBoxRect = visualRect( option, checkBoxRect ); | 4747 | checkBoxRect = visualRect( option, checkBoxRect ); | ||
please dont rename variables just for the safe of it, and keep checkboxrect. hpereiradacosta: please dont rename variables just for the safe of it, and keep checkboxrect. | |||||
4708 | 4748 | | |||
4709 | // checkbox state | 4749 | // checkbox state | ||
4710 | 4750 | | |||
4711 | if( useStrongFocus && ( selected || sunken ) ) | 4751 | if( useStrongFocus && ( selected || sunken ) ) | ||
4712 | { _helper->renderCheckBoxBackground( painter, checkBoxRect, palette.color( QPalette::Window ), sunken ); } | 4752 | { _helper->renderCheckBoxBackground( painter, checkBoxRect, palette.color( QPalette::Window ), sunken ); } | ||
4713 | 4753 | | |||
4714 | CheckBoxState state( menuItemOption->checked ? CheckOn : CheckOff ); | 4754 | CheckBoxState state( menuItemOption->checked ? CheckOn : CheckOff ); | ||
4715 | const bool active( menuItemOption->checked ); | 4755 | const bool active( menuItemOption->checked ); | ||
Show All 10 Lines | 4760 | } else if( menuItemOption->checkType == QStyleOptionMenuItem::Exclusive ) { | |||
4726 | 4766 | | |||
4727 | const bool active( menuItemOption->checked ); | 4767 | const bool active( menuItemOption->checked ); | ||
4728 | const auto shadow( _helper->shadowColor( palette ) ); | 4768 | const auto shadow( _helper->shadowColor( palette ) ); | ||
4729 | const auto color( _helper->checkBoxIndicatorColor( palette, false, enabled && active ) ); | 4769 | const auto color( _helper->checkBoxIndicatorColor( palette, false, enabled && active ) ); | ||
4730 | _helper->renderRadioButton( painter, checkBoxRect, color, shadow, sunken, active ? RadioOn:RadioOff ); | 4770 | _helper->renderRadioButton( painter, checkBoxRect, color, shadow, sunken, active ? RadioOn:RadioOff ); | ||
4731 | 4771 | | |||
4732 | } | 4772 | } | ||
4733 | 4773 | | |||
4734 | // icon | | |||
4735 | int iconWidth = 0; | | |||
4736 | const bool showIcon( showIconsInMenuItems() ); | | |||
4737 | if( showIcon ) iconWidth = isQtQuickControl( option, widget ) ? qMax( pixelMetric(PM_SmallIconSize, option, widget ), menuItemOption->maxIconWidth ) : menuItemOption->maxIconWidth; | | |||
4738 | | ||||
4739 | QRect iconRect( contentsRect.left(), contentsRect.top() + (contentsRect.height()-iconWidth)/2, iconWidth, iconWidth ); | | |||
4740 | contentsRect.setLeft( iconRect.right() + Metrics::MenuItem_ItemSpacing + 1 ); | | |||
4741 | | ||||
4742 | if( showIcon && !menuItemOption->icon.isNull() ) | 4774 | if( showIcon && !menuItemOption->icon.isNull() ) | ||
If I understand right, this is the double spacing bug fix. hpereiradacosta: If I understand right, this is the double spacing bug fix.
Correct ? Very nice.
In principle… | |||||
Yes. zzag: > This way, if in the future someone wants to revert the margin change, she/he does not revert… | |||||
4743 | { | 4775 | { | ||
4744 | 4776 | | |||
4745 | const QSize iconSize( pixelMetric( PM_SmallIconSize, option, widget ), pixelMetric( PM_SmallIconSize, option, widget ) ); | | |||
4746 | iconRect = centerRect( iconRect, iconSize ); | | |||
4747 | iconRect = visualRect( option, iconRect ); | 4777 | iconRect = visualRect( option, iconRect ); | ||
4748 | 4778 | | |||
4749 | // icon mode | 4779 | // icon mode | ||
4750 | QIcon::Mode mode; | 4780 | QIcon::Mode mode; | ||
4751 | if( selected && !useStrongFocus) mode = QIcon::Active; | 4781 | if( selected && !useStrongFocus) mode = QIcon::Active; | ||
4752 | else if( selected ) mode = QIcon::Selected; | 4782 | else if( selected ) mode = QIcon::Selected; | ||
4753 | else if( enabled ) mode = QIcon::Normal; | 4783 | else if( enabled ) mode = QIcon::Normal; | ||
4754 | else mode = QIcon::Disabled; | 4784 | else mode = QIcon::Disabled; | ||
4755 | 4785 | | |||
4756 | // icon state | 4786 | // icon state | ||
4757 | const QIcon::State iconState( sunken ? QIcon::On:QIcon::Off ); | 4787 | const QIcon::State iconState( sunken ? QIcon::On:QIcon::Off ); | ||
4758 | const QPixmap icon = menuItemOption->icon.pixmap( iconRect.size(), mode, iconState ); | 4788 | const QPixmap icon = menuItemOption->icon.pixmap( iconRect.size(), mode, iconState ); | ||
4759 | painter->drawPixmap( iconRect, icon ); | 4789 | painter->drawPixmap( iconRect, icon ); | ||
4760 | 4790 | | |||
4761 | } | 4791 | } | ||
4762 | 4792 | | |||
4763 | // arrow | 4793 | // arrow | ||
4764 | QRect arrowRect( contentsRect.right() - Metrics::MenuButton_IndicatorWidth + 1, contentsRect.top() + (contentsRect.height()-Metrics::MenuButton_IndicatorWidth)/2, Metrics::MenuButton_IndicatorWidth, Metrics::MenuButton_IndicatorWidth ); | | |||
4765 | contentsRect.setRight( arrowRect.left() - Metrics::MenuItem_ItemSpacing - 1 ); | | |||
4766 | | ||||
4767 | if( menuItemOption->menuItemType == QStyleOptionMenuItem::SubMenu ) | 4794 | if( menuItemOption->menuItemType == QStyleOptionMenuItem::SubMenu ) | ||
4768 | { | 4795 | { | ||
4769 | 4796 | | |||
4770 | // apply right-to-left layout | 4797 | // apply right-to-left layout | ||
4771 | arrowRect = visualRect( option, arrowRect ); | 4798 | arrowRect = visualRect( option, arrowRect ); | ||
4772 | 4799 | | |||
4773 | // arrow orientation | 4800 | // arrow orientation | ||
4774 | const ArrowOrientation orientation( reverseLayout ? ArrowLeft:ArrowRight ); | 4801 | const ArrowOrientation orientation( reverseLayout ? ArrowLeft:ArrowRight ); | ||
4775 | 4802 | | |||
4776 | // color | 4803 | // color | ||
4777 | QColor arrowColor; | 4804 | QColor arrowColor; | ||
4778 | if( useStrongFocus && ( selected || sunken ) ) arrowColor = palette.color( QPalette::HighlightedText ); | 4805 | if( useStrongFocus && ( selected || sunken ) ) arrowColor = palette.color( QPalette::HighlightedText ); | ||
4779 | else if( sunken ) arrowColor = _helper->focusColor( palette ); | 4806 | else if( sunken ) arrowColor = _helper->focusColor( palette ); | ||
4780 | else if( selected ) arrowColor = _helper->hoverColor( palette ); | 4807 | else if( selected ) arrowColor = _helper->hoverColor( palette ); | ||
4781 | else arrowColor = _helper->arrowColor( palette, QPalette::WindowText ); | 4808 | else arrowColor = _helper->arrowColor( palette, QPalette::WindowText ); | ||
4782 | 4809 | | |||
4783 | // render | 4810 | // render | ||
4784 | _helper->renderArrow( painter, arrowRect, arrowColor, orientation ); | 4811 | _helper->renderArrow( painter, arrowRect, arrowColor, orientation ); | ||
4785 | 4812 | | |||
4786 | } | 4813 | } | ||
4787 | 4814 | | |||
4788 | | ||||
4789 | // text | 4815 | // text | ||
4790 | auto textRect = contentsRect; | | |||
4791 | if( !menuItemOption->text.isEmpty() ) | 4816 | if( !menuItemOption->text.isEmpty() ) | ||
4792 | { | 4817 | { | ||
4793 | 4818 | | |||
4794 | // adjust textRect | 4819 | // adjust textRect | ||
4795 | QString text = menuItemOption->text; | 4820 | QString text = menuItemOption->text; | ||
4796 | textRect = centerRect( textRect, textRect.width(), option->fontMetrics.size( _mnemonics->textFlags(), text ).height() ); | 4821 | textRect = centerRect( textRect, textRect.width(), option->fontMetrics.size( _mnemonics->textFlags(), text ).height() ); | ||
4797 | textRect = visualRect( option, textRect ); | 4822 | textRect = visualRect( option, textRect ); | ||
4798 | 4823 | | |||
▲ Show 20 Lines • Show All 2339 Lines • Show Last 20 Lines |
this change is unrelated. Please revert.