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 @@ -84,6 +85,10 @@ //* negative text color (used for close button) QColor negativeText( const QPalette& palette ) const { return _viewNegativeTextBrush.brush( palette ).color(); } + + //* button alternate background color + QColor buttonAltBackgroundColor( const QPalette& palette ) const + { return _buttonAltBackgroundBrush.brush( palette ).color(); } //* shadow QColor shadowColor( const QPalette& palette ) const @@ -133,7 +138,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, 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 +185,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; @@ -350,6 +355,8 @@ KStatefulBrush _viewFocusBrush; KStatefulBrush _viewHoverBrush; KStatefulBrush _viewNegativeTextBrush; + + KStatefulBrush _buttonAltBackgroundBrush; //@} //*@name windeco colors diff --git a/kstyle/breezehelper.cpp b/kstyle/breezehelper.cpp --- a/kstyle/breezehelper.cpp +++ b/kstyle/breezehelper.cpp @@ -63,6 +63,8 @@ _viewFocusBrush = KStatefulBrush( KColorScheme::View, KColorScheme::FocusColor ); _viewHoverBrush = KStatefulBrush( KColorScheme::View, KColorScheme::HoverColor ); _viewNegativeTextBrush = KStatefulBrush( KColorScheme::View, KColorScheme::NegativeText ); + + _buttonAltBackgroundBrush = KStatefulBrush( KColorScheme::Button, KColorScheme::AlternateBackground ); const QPalette palette( QApplication::palette() ); const KConfigGroup group( _config->group( "WM" ) ); @@ -195,40 +197,25 @@ } //____________________________________________________________________ - 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 { 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 ); - - } - - } else if( mouseOver ) { - - if( hasFocus ) outline = buttonHoverOutlineColor( palette ); - else outline = hoverColor( palette ); - - } else if( mode == AnimationFocus ) { + const QColor focus( focusColor( palette ) ); + const QColor sunkenHover = KColorUtils::mix( buttonAltBackgroundColor( palette ), palette.color( QPalette::ButtonText ), 0.3 ); + + if( mode == AnimationFocus ) { - const QColor focus( buttonFocusOutlineColor( palette ) ); outline = KColorUtils::mix( outline, focus, opacity ); } else if( hasFocus ) { - outline = buttonFocusOutlineColor( palette ); + outline = focus; + } else if( sunken && mode == AnimationHover ) { + outline = KColorUtils::mix( outline, sunkenHover, opacity ); + } else if( sunken && mouseOver ) { + outline = sunkenHover; } return outline; @@ -239,29 +226,33 @@ 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 ) ); - - if( mode == AnimationHover ) - { + QColor background = 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.4) : KColorUtils::darken(background, 0.4); + const QColor focus = KColorUtils::tint( background, focusColor( palette), 0.4); + const QColor hoverFocus = KColorUtils::tint( hover, focusColor( palette), 0.4 ); + //FIXME: For some reason, the background color still changes on focus when all the logic for changing the background on focus is removed + if( mode == AnimationPressed ) { + background = KColorUtils::mix( background, buttonAltBackgroundColor( palette ), opacity ); + } else if (sunken) { + background = buttonAltBackgroundColor( palette ); + } else if( mode == AnimationHover ) { - const QColor focus( focusColor( palette ) ); - const QColor hover( hoverColor( palette ) ); - if( hasFocus ) background = KColorUtils::mix( focus, hover, opacity ); + if( hasFocus && !sunken) 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 ) { + } else if( mode == AnimationFocus && !sunken) { - const QColor focus( focusColor( palette ) ); background = KColorUtils::mix( background, focus, opacity ); - } else if( hasFocus ) { + } else if( hasFocus) { - background = focusColor( palette ); + background = focus; } @@ -620,7 +611,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 @@ -662,10 +653,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 ); @@ -3546,11 +3543,11 @@ } const auto shadow( _helper->shadowColor( palette ) ); - const auto outline( _helper->buttonOutlineColor( palette, mouseOver, hasFocus, opacity, mode ) ); + const auto outline( _helper->buttonOutlineColor( palette, mouseOver, hasFocus, sunken, opacity, mode ) ); 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 ); } @@ -3590,7 +3587,7 @@ // render as push button const auto shadow( _helper->shadowColor( palette ) ); - const auto outline( _helper->buttonOutlineColor( palette, mouseOver, hasFocus, opacity, mode ) ); + const auto outline( _helper->buttonOutlineColor( palette, mouseOver, hasFocus, sunken, opacity, mode ) ); const auto background( _helper->buttonBackgroundColor( palette, mouseOver, hasFocus, sunken, opacity, mode ) ); // adjust frame in case of menu @@ -3602,7 +3599,7 @@ } // render - _helper->renderButtonFrame( painter, rect, background, outline, shadow, hasFocus, sunken ); + _helper->renderButton( painter, rect, background, outline, shadow, hasFocus, sunken ); } else { @@ -3938,22 +3935,21 @@ // render as push button const auto shadow( _helper->shadowColor( palette ) ); - const auto outline( _helper->buttonOutlineColor( palette, mouseOver, hasFocus, opacity, mode ) ); + const auto outline( _helper->buttonOutlineColor( palette, mouseOver, hasFocus, sunken, opacity, mode ) ); const auto background( _helper->buttonBackgroundColor( palette, mouseOver, hasFocus, false, opacity, mode ) ); auto frameRect( rect ); painter->setClipRect( rect ); frameRect.adjust( -Metrics::Frame_FrameRadius - 1, 0, 0, 0 ); 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; @@ -4229,18 +4225,15 @@ // contents auto contentsRect( rect ); - if( sunken && !flat ) contentsRect.translate( 1, 1 ); // color role QPalette::ColorRole textRole; - if( flat ) - { + if( flat ) { if( hasFocus && sunken ) textRole = QPalette::HighlightedText; else textRole = QPalette::WindowText; - } else if( hasFocus ) textRole = QPalette::HighlightedText; - else textRole = QPalette::ButtonText; + } else textRole = QPalette::ButtonText; // menu arrow if( buttonOption->features & QStyleOptionButton::HasMenu ) @@ -4306,7 +4299,7 @@ const QIcon::State iconState( sunken ? QIcon::On : QIcon::Off ); QIcon::Mode iconMode; if( !enabled ) iconMode = QIcon::Disabled; - else if( !flat && hasFocus ) iconMode = QIcon::Selected; +// else if( !flat && hasFocus ) iconMode = QIcon::Selected; else if( mouseOver && flat ) iconMode = QIcon::Active; else iconMode = QIcon::Normal; @@ -4352,7 +4345,6 @@ // contents auto contentsRect( rect ); - if( sunken && !flat ) contentsRect.translate( 1, 1 ); // icon size const QSize iconSize( toolButtonOption->iconSize ); @@ -4432,7 +4424,7 @@ const QIcon::State iconState( sunken ? QIcon::On : QIcon::Off ); QIcon::Mode iconMode; if( !enabled ) iconMode = QIcon::Disabled; - else if( (!flat && hasFocus) || (flat && (state & State_Sunken) && !mouseOver) ) iconMode = QIcon::Selected; +// else if( (!flat && hasFocus) || (flat && (state & State_Sunken) && !mouseOver) ) iconMode = QIcon::Selected; else if( mouseOver && flat ) iconMode = QIcon::Active; else iconMode = QIcon::Normal; @@ -4446,8 +4438,8 @@ { QPalette::ColorRole textRole( QPalette::ButtonText ); - if( flat ) textRole = ( ((hasFocus&&sunken) || (state & State_Sunken))&&!mouseOver) ? QPalette::HighlightedText: QPalette::WindowText; - else if( hasFocus&&!mouseOver ) textRole = QPalette::HighlightedText; + if( flat ) textRole = ( ((hasFocus&&sunken) || (state & State_Sunken))&&!mouseOver) ? + QPalette::HighlightedText : QPalette::WindowText; painter->setFont(toolButtonOption->font); drawItemText( painter, textRect, textFlags, palette, enabled, toolButtonOption->text, textRole ); @@ -4544,16 +4536,11 @@ if( hasFocus && sunken ) textRole = QPalette::HighlightedText; else textRole = QPalette::WindowText; - } else if( hasFocus ) textRole = QPalette::HighlightedText; - else textRole = QPalette::ButtonText; + } else textRole = QPalette::ButtonText; // 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)) { @@ -4563,9 +4550,9 @@ if (!cb->currentIcon.isNull()) { QIcon::Mode mode; - if ((cb->state & QStyle::State_Selected) && (cb->state & QStyle::State_Active)) { + /*if ((cb->state & QStyle::State_Selected) && (cb->state & QStyle::State_Active)) { mode = QIcon::Selected; - } else if (cb->state & QStyle::State_Enabled) { + } else */if (cb->state & QStyle::State_Enabled) { mode = QIcon::Normal; } else { mode = QIcon::Disabled; @@ -6084,7 +6071,6 @@ 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 ) { @@ -6197,11 +6183,11 @@ // define colors const auto shadow( _helper->shadowColor( palette ) ); - const auto outline( _helper->buttonOutlineColor( palette, mouseOver, hasFocus, opacity, mode ) ); + const auto outline( _helper->buttonOutlineColor( palette, mouseOver, hasFocus, sunken, opacity, mode ) ); 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 ); } @@ -6261,9 +6247,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 );