diff --git a/kstyle/breezehelper.h b/kstyle/breezehelper.h --- a/kstyle/breezehelper.h +++ b/kstyle/breezehelper.h @@ -25,6 +25,7 @@ #include "breezeanimationdata.h" #include "config-breeze.h" +#include #include #include @@ -59,13 +60,31 @@ //* add alpha channel multiplier to color QColor alphaColor( QColor color, qreal alpha ) const; - //* mouse over color - QColor hoverColor( const QPalette& palette ) const - { return _viewHoverBrush.brush( palette ).color(); } - //* focus color QColor focusColor( const QPalette& palette ) const - { return _viewFocusBrush.brush( palette ).color(); } + { return palette.color( QPalette::Active, QPalette::Highlight ); } + + //* focus/selection background color + QColor focusBackgroundColor( const QPalette& palette ) const + { return palette.color( QPalette::Inactive, QPalette::Highlight ); } + + //* button alternate background color + QColor buttonAltBackgroundColor( const QPalette& palette ) const + { return _buttonAltBackgroundBrush.brush( palette ).color(); } + + //* mouse over color + QColor hoverColor( const QPalette& palette, const QColor& color = nullptr ) const + { + return KColorUtils::tint( color.isValid() ? color : separatorColor( palette ), + focusColor( palette ), 0.5 ); + } + + //* mouse over background color + QColor hoverBackgroundColor( const QPalette& palette, const QColor& color = nullptr ) const + { + return KColorUtils::mix( color.isValid() ? color : palette.color( QPalette::Button ), + buttonAltBackgroundColor( palette ), 0.5 ); + } //* negative text color (used for close button) QColor negativeText( const QPalette& palette ) const @@ -310,9 +329,8 @@ //*@name brushes //@{ - 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 @@ -52,9 +52,8 @@ //____________________________________________________________________ void Helper::loadConfig() { - _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" ) ); @@ -107,14 +106,6 @@ QColor Helper::hoverOutlineColor( const QPalette& palette ) const { return KColorUtils::mix( hoverColor( palette ), palette.color( QPalette::WindowText ), 0.15 ); } - //____________________________________________________________________ - QColor Helper::buttonFocusOutlineColor( const QPalette& palette ) const - { return KColorUtils::mix( focusColor( palette ), palette.color( QPalette::ButtonText ), 0.15 ); } - - //____________________________________________________________________ - QColor Helper::buttonHoverOutlineColor( const QPalette& palette ) const - { return KColorUtils::mix( hoverColor( palette ), palette.color( QPalette::ButtonText ), 0.15 ); } - //____________________________________________________________________ QColor Helper::sidePanelOutlineColor( const QPalette& palette, bool hasFocus, qreal opacity, AnimationMode mode ) const { @@ -191,35 +182,25 @@ { 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 focus = focusColor( palette ); + const QColor hover = hoverColor( palette ); - const QColor hover( hoverColor( palette ) ); - outline = KColorUtils::mix( outline, hover, opacity ); + // Focus has precedence over hover + if( mode == AnimationFocus ) { - } + outline = KColorUtils::mix( outline, focus, opacity ); - } else if( mouseOver ) { + } else if( hasFocus ) { - if( hasFocus ) outline = buttonHoverOutlineColor( palette ); - else outline = hoverColor( palette ); + outline = focus; - } else if( mode == AnimationFocus ) { + } else if( mode == AnimationHover ) { - const QColor focus( buttonFocusOutlineColor( palette ) ); - outline = KColorUtils::mix( outline, focus, opacity ); + outline = KColorUtils::mix( outline, hover, opacity ); - } else if( hasFocus ) { + } else if( mouseOver ) { - outline = buttonFocusOutlineColor( palette ); + outline = hover; } @@ -231,29 +212,37 @@ 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 = palette.color( QPalette::Button ); + const QColor hover = hoverBackgroundColor( palette ); + const QColor focus = focusBackgroundColor( palette ); + const QColor hoverFocus = hoverBackgroundColor( palette, focus ); - if( mode == AnimationHover ) - { + //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 ) { - const QColor focus( focusColor( palette ) ); - const QColor hover( hoverColor( palette ) ); - if( hasFocus ) background = KColorUtils::mix( focus, hover, opacity ); + background = KColorUtils::mix( background, buttonAltBackgroundColor( palette ), opacity ); + + } else if ( sunken ) { + + background = buttonAltBackgroundColor( palette ); + + } else if( mode == AnimationHover ) { + + 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 ) { - const QColor focus( focusColor( palette ) ); background = KColorUtils::mix( background, focus, opacity ); } else if( hasFocus ) { - background = focusColor( palette ); + background = focus; } @@ -627,23 +616,16 @@ qreal radius( frameRadius( PenWidth::NoPen, -1 ) ); // shadow - if( sunken ) { - - frameRect.translate( 1, 1 ); - - } else { + if( !sunken ) { renderRoundedRectShadow( painter, frameRect, shadow, radius ); } 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( QPen( outline, PenWidth::Frame ) ); frameRect = strokedRect( frameRect ); radius = frameRadiusForNewPenWidth( radius, PenWidth::Frame ); @@ -654,10 +636,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 @@ -1261,9 +1261,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 ); @@ -1287,7 +1284,7 @@ // text rect QRect textRect( offset, QSize( button->size().width() - offset.x() - margin, button->size().height() - 2*margin ) ); - const QPalette::ColorRole textRole = (enabled && hasFocus && !mouseOver && !isFlat ) ? QPalette::HighlightedText : QPalette::ButtonText; + const QPalette::ColorRole textRole = QPalette::ButtonText; if( !button->text().isEmpty() ) { @@ -3336,29 +3333,19 @@ if( flat && hasMenu ) { - if( sunken && !mouseOver ) color = palette.color( QPalette::HighlightedText ); - else { - - // for menu arrows in flat toolbutton one uses animations to get the arrow color - // handle arrow over animation - const bool arrowHover( mouseOver && ( toolButtonOption->activeSubControls & SC_ToolButtonMenu ) ); - _animations->toolButtonEngine().updateState( widget, AnimationHover, arrowHover ); - - const bool animated( _animations->toolButtonEngine().isAnimated( widget, AnimationHover ) ); - const qreal opacity( _animations->toolButtonEngine().opacity( widget, AnimationHover ) ); + // for menu arrows in flat toolbutton one uses animations to get the arrow color + // handle arrow over animation + const bool arrowHover( mouseOver && ( toolButtonOption->activeSubControls & SC_ToolButtonMenu ) ); + _animations->toolButtonEngine().updateState( widget, AnimationHover, arrowHover ); - color = _helper->arrowColor( palette, arrowHover, false, opacity, animated ? AnimationHover:AnimationNone ); + const bool animated( _animations->toolButtonEngine().isAnimated( widget, AnimationHover ) ); + const qreal opacity( _animations->toolButtonEngine().opacity( widget, AnimationHover ) ); - } + color = _helper->arrowColor( palette, arrowHover, false, opacity, animated ? AnimationHover:AnimationNone ); } else if( flat ) { - if( sunken && hasFocus && !mouseOver ) color = palette.color( QPalette::HighlightedText ); - else color = _helper->arrowColor( palette, QPalette::WindowText ); - - } else if( hasFocus && !mouseOver ) { - - color = palette.color( QPalette::HighlightedText ); + color = _helper->arrowColor( palette, QPalette::WindowText ); } else { @@ -3846,7 +3833,6 @@ 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; @@ -4122,18 +4108,14 @@ // contents auto contentsRect( rect ); - if( sunken && !flat ) contentsRect.translate( 1, 1 ); // color role QPalette::ColorRole textRole; - if( flat ) - { - - if( hasFocus && sunken ) textRole = QPalette::HighlightedText; - else textRole = QPalette::WindowText; - - } else if( hasFocus ) textRole = QPalette::HighlightedText; - else textRole = QPalette::ButtonText; + if( flat ) { + textRole = QPalette::WindowText; + } else { + textRole = QPalette::ButtonText; + } // menu arrow if( buttonOption->features & QStyleOptionButton::HasMenu ) @@ -4199,7 +4181,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; @@ -4245,7 +4227,6 @@ // contents auto contentsRect( rect ); - if( sunken && !flat ) contentsRect.translate( 1, 1 ); // icon size const QSize iconSize( toolButtonOption->iconSize ); @@ -4325,7 +4306,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; @@ -4339,8 +4320,7 @@ { 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 = QPalette::WindowText; painter->setFont(toolButtonOption->font); drawItemText( painter, textRect, textFlags, palette, enabled, toolButtonOption->text, textRole ); @@ -4434,11 +4414,9 @@ QPalette::ColorRole textRole; if( flat ) { - if( hasFocus && sunken ) textRole = QPalette::HighlightedText; - else textRole = QPalette::WindowText; + 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 ) ); @@ -4455,9 +4433,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; @@ -5961,7 +5939,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 ) { @@ -6128,19 +6105,14 @@ } else if( flat ) { if( empty || !enabled ) arrowColor = _helper->arrowColor( palette, QPalette::Disabled, QPalette::WindowText ); - else if( hasFocus && !mouseOver && sunken ) arrowColor = palette.color( QPalette::HighlightedText ); else arrowColor = _helper->arrowColor( palette, QPalette::WindowText ); } else if( empty || !enabled ) arrowColor = _helper->arrowColor( palette, QPalette::Disabled, QPalette::ButtonText ); - else if( hasFocus && !mouseOver ) arrowColor = palette.color( QPalette::HighlightedText ); else arrowColor = _helper->arrowColor( palette, QPalette::ButtonText ); // 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 );