diff --git a/kstyle/breezehelper.h b/kstyle/breezehelper.h --- a/kstyle/breezehelper.h +++ b/kstyle/breezehelper.h @@ -38,6 +38,7 @@ #if BREEZE_HAVE_X11 #include #include +#include #endif namespace Breeze @@ -78,8 +79,8 @@ { return _viewHoverBrush.brush( palette ).color(); } //* focus color - QColor focusColor( const QPalette& palette ) const - { return _viewFocusBrush.brush( palette ).color(); } + QColor focusColor( const QPalette& palette, const QColor base = "black", const qreal amount = 1.0 ) const + { return amount < 1 ? KColorUtils::tint(base, _viewFocusBrush.brush( palette ).color(), amount) : _viewFocusBrush.brush( palette ).color(); } //* negative text color (used for close button) QColor negativeText( const QPalette& palette ) const @@ -133,7 +134,7 @@ QColor arrowColor( const QPalette&, bool mouseOver, bool hasFocus, qreal opacity = AnimationData::OpacityInvalid, AnimationMode = AnimationNone ) const; //* button outline color, using animations - QColor buttonOutlineColor( const QPalette&, bool mouseOver, bool hasFocus, qreal opacity = AnimationData::OpacityInvalid, AnimationMode = AnimationNone ) const; + QColor buttonOutlineColor( const QPalette&, bool mouseOver, bool hasFocus, bool sunken = false, qreal opacity = AnimationData::OpacityInvalid, AnimationMode = AnimationNone ) const; //* button panel color, using animations QColor buttonBackgroundColor( const QPalette&, bool mouseOver, bool hasFocus, bool sunken, qreal opacity = AnimationData::OpacityInvalid, AnimationMode = AnimationNone ) const; @@ -180,7 +181,7 @@ void renderMenuFrame( QPainter*, const QRect&, const QColor& color, const QColor& outline, bool roundCorners = true ) const; //* button frame - void renderButtonFrame( QPainter*, const QRect&, const QColor& color, const QColor& outline, const QColor& shadow, bool focus, bool sunken ) const; + void renderButton( QPainter*, const QRect&, const QColor& color, const QColor& outline, const QColor& shadow, bool focus, bool sunken ) const; //* toolbutton frame void renderToolButtonFrame( QPainter*, const QRect&, const QColor& color, bool sunken ) const; diff --git a/kstyle/breezehelper.cpp b/kstyle/breezehelper.cpp --- a/kstyle/breezehelper.cpp +++ b/kstyle/breezehelper.cpp @@ -195,39 +195,18 @@ } //____________________________________________________________________ - QColor Helper::buttonOutlineColor( const QPalette& palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode ) const + QColor Helper::buttonOutlineColor( const QPalette& palette, bool mouseOver, bool hasFocus, bool sunken, qreal opacity, AnimationMode mode ) const { + const QColor focus( focusColor( palette ) ); QColor outline( KColorUtils::mix( palette.color( QPalette::Button ), palette.color( QPalette::ButtonText ), 0.3 ) ); - if( mode == AnimationHover ) - { - - if( hasFocus ) - { - const QColor focus( buttonFocusOutlineColor( palette ) ); - const QColor hover( buttonHoverOutlineColor( palette ) ); - outline = KColorUtils::mix( focus, hover, opacity ); - - } else { - - const QColor hover( hoverColor( palette ) ); - outline = KColorUtils::mix( outline, hover, opacity ); + if( mode == AnimationFocus ) { - } - - } else if( mouseOver ) { - - if( hasFocus ) outline = buttonHoverOutlineColor( palette ); - else outline = hoverColor( palette ); - - } else if( mode == AnimationFocus ) { - - const QColor focus( buttonFocusOutlineColor( palette ) ); outline = KColorUtils::mix( outline, focus, opacity ); } else if( hasFocus ) { - outline = buttonFocusOutlineColor( palette ); + outline = focus; } @@ -239,29 +218,32 @@ QColor Helper::buttonBackgroundColor( const QPalette& palette, bool mouseOver, bool hasFocus, bool sunken, qreal opacity, AnimationMode mode ) const { - QColor background( sunken ? - KColorUtils::mix( palette.color( QPalette::Button ), palette.color( QPalette::ButtonText ), 0.2 ): - palette.color( QPalette::Button ) ); + QColor background = sunken ? + KColorUtils::mix( palette.color( QPalette::Button ), palette.color( QPalette::ButtonText ), 0.2 ) : + palette.color( QPalette::Button ); + const bool hasLightBg = palette.color( QPalette::Button ).lightness() > palette.color( QPalette::ButtonText ).lightness(); + const QColor hover = hasLightBg ? KColorUtils::lighten(background, 0.5) : KColorUtils::darken(background, 0.5); + const QColor focus( focusColor( palette, background, 0.4 ) ); + const QColor hoverFocus( KColorUtils::mix( hover, focus, 0.4 ) ); if( mode == AnimationHover ) { - const QColor focus( focusColor( palette ) ); - const QColor hover( hoverColor( palette ) ); - if( hasFocus ) background = KColorUtils::mix( focus, hover, opacity ); + if( hasFocus ) background = KColorUtils::mix( focus, hoverFocus, opacity ); + else background = KColorUtils::mix( background, hover, opacity ); - } else if( mouseOver && hasFocus ) { + } else if( mouseOver ) { - background = hoverColor( palette ); + if( hasFocus ) background = hoverFocus; + else background = hover; } else if( mode == AnimationFocus ) { - const QColor focus( focusColor( palette ) ); background = KColorUtils::mix( background, focus, opacity ); } else if( hasFocus ) { - background = focusColor( palette ); + background = focus; } @@ -622,7 +604,7 @@ } //______________________________________________________________________________ - void Helper::renderButtonFrame( + void Helper::renderButton( QPainter* painter, const QRect& rect, const QColor& color, const QColor& outline, const QColor& shadow, bool hasFocus, bool sunken ) const @@ -637,11 +619,7 @@ qreal radius( frameRadius() ); // shadow - if( sunken ) { - - frameRect.translate( 1, 1 ); - - } else if( shadow.isValid() ) { + if( shadow.isValid() ) { const qreal shadowRadius = qMax( radius - 1, qreal( 0.0 ) ); painter->setPen( QPen( shadow, 2 ) ); @@ -653,10 +631,7 @@ if( outline.isValid() ) { - QLinearGradient gradient( frameRect.topLeft(), frameRect.bottomLeft() ); - gradient.setColorAt( 0, outline.lighter( hasFocus ? 103:101 ) ); - gradient.setColorAt( 1, outline.darker( hasFocus ? 110:103 ) ); - painter->setPen( QPen( QBrush( gradient ), 1.0 ) ); + painter->setPen( outline ); frameRect.adjust( 0.5, 0.5, -0.5, -0.5 ); radius = qMax( radius - 1, qreal( 0.0 ) ); @@ -667,10 +642,7 @@ if( color.isValid() ) { - QLinearGradient gradient( frameRect.topLeft(), frameRect.bottomLeft() ); - gradient.setColorAt( 0, color.lighter( hasFocus ? 103:101 ) ); - gradient.setColorAt( 1, color.darker( hasFocus ? 110:103 ) ); - painter->setBrush( gradient ); + painter->setBrush( color ); } else painter->setBrush( Qt::NoBrush ); diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -1289,9 +1289,6 @@ const int margin( Metrics::Button_MarginWidth + Metrics::Frame_FrameWidth ); QPoint offset( margin, margin ); - if( button->isDown() && !isFlat ) painter.translate( 1, 1 ); - { offset += QPoint( 1, 1 ); } - // state const State& state( option.state ); const bool enabled( state & State_Enabled ); @@ -3547,7 +3544,7 @@ const auto background( _helper->buttonBackgroundColor( palette, mouseOver, hasFocus, sunken, opacity, mode ) ); // render - _helper->renderButtonFrame( painter, rect, background, outline, shadow, hasFocus, sunken ); + _helper->renderButton( painter, rect, background, outline, shadow, hasFocus, sunken ); } @@ -3599,7 +3596,7 @@ } // render - _helper->renderButtonFrame( painter, rect, background, outline, shadow, hasFocus, sunken ); + _helper->renderButton( painter, rect, background, outline, shadow, hasFocus, sunken ); } else { @@ -3966,13 +3963,12 @@ frameRect = visualRect( option, frameRect ); // render - _helper->renderButtonFrame( painter, frameRect, background, outline, shadow, hasFocus, sunken ); + _helper->renderButton( painter, frameRect, background, outline, shadow, hasFocus, sunken ); // also render separator auto separatorRect( rect.adjusted( 0, 2, -2, -2 ) ); separatorRect.setWidth( 1 ); separatorRect = visualRect( option, separatorRect ); - if( sunken ) separatorRect.translate( 1, 1 ); _helper->renderSeparator( painter, separatorRect, outline, true ); return true; @@ -4248,7 +4244,6 @@ // contents auto contentsRect( rect ); - if( sunken && !flat ) contentsRect.translate( 1, 1 ); // color role QPalette::ColorRole textRole; @@ -4371,7 +4366,6 @@ // contents auto contentsRect( rect ); - if( sunken && !flat ) contentsRect.translate( 1, 1 ); // icon size const QSize iconSize( toolButtonOption->iconSize ); @@ -4569,10 +4563,6 @@ // change pen color directly painter->setPen( QPen( option->palette.color( textRole ), 1 ) ); - // translate painter for pressed down comboboxes - if( sunken && !flat ) - { painter->translate( 1, 1 ); } - #if QT_VERSION >= 0x050000 if (const auto cb = qstyleoption_cast(option)) { @@ -6108,14 +6098,12 @@ copy.rect = menuRect; if( !flat ) drawPrimitive( PE_IndicatorButtonDropDown, ©, painter, widget ); - if( sunken && !flat ) copy.rect.translate( 1, 1 ); drawPrimitive( PE_IndicatorArrowDown, ©, painter, widget ); } else if( hasInlineIndicator ) { copy.rect = menuRect; - if( sunken && !flat ) copy.rect.translate( 1, 1 ); drawPrimitive( PE_IndicatorArrowDown, ©, painter, widget ); } @@ -6226,7 +6214,7 @@ const auto background( _helper->buttonBackgroundColor( palette, mouseOver, hasFocus, false, opacity, mode ) ); // render - _helper->renderButtonFrame( painter, rect, background, outline, shadow, hasFocus, sunken ); + _helper->renderButton( painter, rect, background, outline, shadow, hasFocus, sunken ); } @@ -6286,9 +6274,6 @@ // arrow rect auto arrowRect( subControlRect( CC_ComboBox, option, SC_ComboBoxArrow, widget ) ); - // translate for non editable, non flat, sunken comboboxes - if( sunken && !flat && !editable ) arrowRect.translate( 1, 1 ); - // render _helper->renderArrow( painter, arrowRect, arrowColor, ArrowDown );