From 4fe1675c223e80a9842737877a4f1b2779f164d5 Mon Sep 17 00:00:00 2001 From: Jan Blackquill Date: Thu, 9 Sep 2021 18:30:38 -0400 Subject: [PATCH] kstyle: add sunken state for checkbuttons and radiobuttons back --- kstyle/breezehelper.cpp | 23 +++++++++++++++-------- kstyle/breezehelper.h | 8 ++++---- kstyle/breezestyle.cpp | 20 +++++++++++--------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/kstyle/breezehelper.cpp b/kstyle/breezehelper.cpp index 5ff3ed57..1192f38f 100644 --- a/kstyle/breezehelper.cpp +++ b/kstyle/breezehelper.cpp @@ -37,6 +37,8 @@ namespace Breeze //* contrast for arrow and treeline rendering static const qreal arrowShade = 0.15; + static const auto radioCheckSunkenDarkeningFactor = 110; + //____________________________________________________________________ Helper::Helper( KSharedConfig::Ptr config, QObject *parent ) : QObject ( parent ), @@ -847,7 +849,8 @@ namespace Breeze void Helper::renderCheckBoxBackground( QPainter* painter, const QRect& rect, const QPalette& palette, - CheckBoxState state, bool neutalHighlight, qreal animation ) const + CheckBoxState state, bool neutalHighlight, + bool sunken, qreal animation ) const { // setup painter painter->setRenderHint( QPainter::Antialiasing, true ); @@ -869,7 +872,7 @@ namespace Breeze switch (state) { case CheckOff: - painter->setBrush( palette.base() ); + painter->setBrush( palette.base().color().darker(sunken ? radioCheckSunkenDarkeningFactor : 100) ); painter->drawRoundedRect( frameRect, radius, radius ); break; @@ -880,7 +883,7 @@ namespace Breeze break; case CheckAnimated: - painter->setBrush( palette.base() ); + painter->setBrush( palette.base().color().darker(sunken ? radioCheckSunkenDarkeningFactor : 100) ); painter->drawRoundedRect( frameRect, radius, radius ); painter->setBrush( transparent ); painter->setOpacity( animation ); @@ -895,9 +898,11 @@ namespace Breeze QPainter* painter, const QRect& rect, const QPalette& palette, bool mouseOver, CheckBoxState state, CheckBoxState target, - bool neutalHighlight, + bool neutalHighlight, bool sunken, qreal animation, qreal hoverAnimation ) const { + Q_UNUSED(sunken) + // setup painter painter->setRenderHint( QPainter::Antialiasing, true ); @@ -985,7 +990,7 @@ namespace Breeze } //______________________________________________________________________________ - void Helper::renderRadioButtonBackground( QPainter* painter, const QRect& rect, const QPalette& palette, RadioButtonState state, bool neutalHighlight, qreal animation ) const + void Helper::renderRadioButtonBackground( QPainter* painter, const QRect& rect, const QPalette& palette, RadioButtonState state, bool neutalHighlight, bool sunken, qreal animation ) const { // setup painter @@ -1006,7 +1011,7 @@ namespace Breeze switch (state) { case RadioOff: - painter->setBrush( palette.base() ); + painter->setBrush( palette.base().color().darker(sunken ? radioCheckSunkenDarkeningFactor : 100) ); painter->drawEllipse( frameRect ); break; case RadioOn: @@ -1014,7 +1019,7 @@ namespace Breeze painter->drawEllipse( frameRect ); break; case RadioAnimated: - painter->setBrush( palette.base() ); + painter->setBrush( palette.base().color().darker(sunken ? radioCheckSunkenDarkeningFactor : 100) ); painter->drawEllipse( frameRect ); painter->setBrush( transparent ); painter->setOpacity( animation ); @@ -1027,8 +1032,10 @@ namespace Breeze void Helper::renderRadioButton( QPainter* painter, const QRect& rect, const QPalette& palette, bool mouseOver, - RadioButtonState state, bool neutralHighlight, qreal animation, qreal animationHover ) const + RadioButtonState state, bool neutralHighlight, bool sunken, qreal animation, qreal animationHover ) const { + Q_UNUSED(sunken) + // setup painter painter->setRenderHint( QPainter::Antialiasing, true ); diff --git a/kstyle/breezehelper.h b/kstyle/breezehelper.h index b6a1509e..86dd65ab 100644 --- a/kstyle/breezehelper.h +++ b/kstyle/breezehelper.h @@ -192,16 +192,16 @@ namespace Breeze void renderSeparator( QPainter*, const QRect&, const QColor&, bool vertical = false ) const; //* checkbox - void renderCheckBoxBackground( QPainter*, const QRect&, const QPalette& palette, CheckBoxState state, bool neutalHighlight, qreal animation = AnimationData::OpacityInvalid ) const; + void renderCheckBoxBackground( QPainter*, const QRect&, const QPalette& palette, CheckBoxState state, bool neutalHighlight, bool sunken, qreal animation = AnimationData::OpacityInvalid ) const; //* checkbox - void renderCheckBox( QPainter*, const QRect&, const QPalette& palette, bool mouseOver, CheckBoxState state, CheckBoxState target, bool neutalHighlight, qreal animation = AnimationData::OpacityInvalid, qreal hoverAnimation = AnimationData::OpacityInvalid ) const; + void renderCheckBox( QPainter*, const QRect&, const QPalette& palette, bool mouseOver, CheckBoxState state, CheckBoxState target, bool neutalHighlight, bool sunken, qreal animation = AnimationData::OpacityInvalid, qreal hoverAnimation = AnimationData::OpacityInvalid ) const; //* radio button - void renderRadioButtonBackground( QPainter*, const QRect&, const QPalette& palette, RadioButtonState state, bool neutalHighlight, qreal animation = AnimationData::OpacityInvalid ) const; + void renderRadioButtonBackground( QPainter*, const QRect&, const QPalette& palette, RadioButtonState state, bool neutalHighlight, bool sunken, qreal animation = AnimationData::OpacityInvalid ) const; //* radio button - void renderRadioButton( QPainter*, const QRect&, const QPalette& palette, bool mouseOver, RadioButtonState state, bool neutalHighlight, qreal animation = AnimationData::OpacityInvalid, qreal hoverAnimation = AnimationData::OpacityInvalid ) const; + void renderRadioButton( QPainter*, const QRect&, const QPalette& palette, bool mouseOver, RadioButtonState state, bool neutalHighlight, bool sunken, qreal animation = AnimationData::OpacityInvalid, qreal hoverAnimation = AnimationData::OpacityInvalid ) const; //* slider groove void renderSliderGroove( QPainter*, const QRect&, const QColor& ) const; diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 520469d3..12ccc377 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -3898,6 +3898,7 @@ namespace Breeze // store flags const State& state( option->state ); const bool enabled( state & State_Enabled ); + const bool sunken( state & State_Sunken ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); // checkbox state @@ -3915,8 +3916,8 @@ namespace Breeze const qreal opacity( _animations->widgetStateEngine().opacity( widget, AnimationHover ) ); // render - _helper->renderCheckBoxBackground( painter, rect, palette, checkBoxState, hasHighlightNeutral( widget, option, mouseOver), animation ); - _helper->renderCheckBox( painter, rect, palette, mouseOver, checkBoxState, target, hasHighlightNeutral( widget, option, mouseOver), animation, opacity ); + _helper->renderCheckBoxBackground( painter, rect, palette, checkBoxState, hasHighlightNeutral( widget, option, mouseOver), sunken, animation ); + _helper->renderCheckBox( painter, rect, palette, mouseOver, checkBoxState, target, hasHighlightNeutral( widget, option, mouseOver), sunken, animation, opacity ); return true; } @@ -3932,6 +3933,7 @@ namespace Breeze // store flags const State& state( option->state ); const bool enabled( state & State_Enabled ); + const bool sunken( state & State_Sunken ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); // radio button state @@ -3947,8 +3949,8 @@ namespace Breeze const qreal opacity( _animations->widgetStateEngine().opacity( widget, AnimationHover ) ); // render - _helper->renderRadioButtonBackground( painter, rect, palette, radioButtonState, hasHighlightNeutral( widget, option, mouseOver), animation ); - _helper->renderRadioButton( painter, rect, palette, mouseOver, radioButtonState, hasHighlightNeutral( widget, option, mouseOver), animation, opacity ); + _helper->renderRadioButtonBackground( painter, rect, palette, radioButtonState, hasHighlightNeutral( widget, option, mouseOver), sunken, animation ); + _helper->renderRadioButton( painter, rect, palette, mouseOver, radioButtonState, hasHighlightNeutral( widget, option, mouseOver), sunken, animation, opacity ); return true; @@ -4811,7 +4813,7 @@ namespace Breeze const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool selected( enabled && (state & State_Selected) ); - const bool sunken( enabled && (state & (State_On|State_Sunken) ) ); + const bool sunken( enabled && (state & (State_Sunken) ) ); const bool reverseLayout( option->direction == Qt::RightToLeft ); const bool useStrongFocus( StyleConfigData::menuItemDrawStrongFocus() ); @@ -4860,16 +4862,16 @@ namespace Breeze const bool active( menuItemOption->checked ); const auto shadow( _helper->shadowColor( palette ) ); const auto color( _helper->checkBoxIndicatorColor( palette, false, enabled && active ) ); - _helper->renderCheckBoxBackground( painter, checkBoxRect, palette, state, false, AnimationData::OpacityInvalid ); - _helper->renderCheckBox( painter, checkBoxRect, palette, false, state, state, false ); + _helper->renderCheckBoxBackground( painter, checkBoxRect, palette, state, false, sunken ); + _helper->renderCheckBox( painter, checkBoxRect, palette, false, state, state, false, sunken ); } else if( menuItemOption->checkType == QStyleOptionMenuItem::Exclusive ) { checkBoxRect = visualRect( option, checkBoxRect ); const bool active( menuItemOption->checked ); - _helper->renderRadioButtonBackground( painter, checkBoxRect, palette, active ? RadioOn : RadioOff, false, AnimationData::OpacityInvalid ); - _helper->renderRadioButton( painter, checkBoxRect, palette, false, active ? RadioOn:RadioOff, false ); + _helper->renderRadioButtonBackground( painter, checkBoxRect, palette, active ? RadioOn : RadioOff, false, sunken ); + _helper->renderRadioButton( painter, checkBoxRect, palette, false, active ? RadioOn:RadioOff, false, sunken ); }