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 = 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 +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; @@ -334,6 +339,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,39 +197,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 ); - - } - - } else if( mouseOver ) { - - if( hasFocus ) outline = buttonHoverOutlineColor( palette ); - else outline = hoverColor( palette ); + if( mode == AnimationFocus ) { - } 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 +220,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 ) ); + QColor background = sunken ? + buttonAltBackgroundColor( palette ) : + 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::mix( hover, focus, 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 == 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 && !sunken) 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 && !sunken) { - background = focusColor( palette ); + background = focus; } @@ -622,7 +607,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 +622,7 @@ qreal radius( frameRadius() ); // shadow - if( sunken ) { - - frameRect.translate( 1, 1 ); - - } else if( shadow.isValid() ) { + if( shadow.isValid() && !sunken ) { const qreal shadowRadius = qMax( radius - 1, qreal( 0.0 ) ); painter->setPen( QPen( shadow, 2 ) ); @@ -652,25 +633,23 @@ 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 ) ); - - frameRect.adjust( 0.5, 0.5, -0.5, -0.5 ); - radius = qMax( radius - 1, qreal( 0.0 ) ); + QPen pen(outline); +// if( hasFocus ) { +// pen.setWidth(2); +// } +// else { + frameRect.adjust( 0.5, 0.5, -0.5, -0.5 ); + radius = qMax( radius - 1, qreal( 0.0 ) ); +// } + painter->setPen( pen ); } else painter->setPen( Qt::NoPen ); // content 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 ); @@ -1438,7 +1417,7 @@ //______________________________________________________________________________ QRectF Helper::shadowRect( const QRectF& rect ) const - { return rect.adjusted( 0.5, 0.5, -0.5, -0.5 ).translated( 0.5, 0.5 ); } + { return rect.adjusted( 0.5, 0.5, -0.5, -0.5 ).translated( 0, 0.5 ); } //______________________________________________________________________________ QPainterPath Helper::roundedPath( const QRectF& rect, Corners corners, qreal radius ) const 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 ); @@ -3550,7 +3547,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 ); } @@ -3602,7 +3599,7 @@ } // render - _helper->renderButtonFrame( painter, rect, background, outline, shadow, hasFocus, sunken ); + _helper->renderButton( painter, rect, background, outline, shadow, hasFocus, sunken ); } else { @@ -3969,13 +3966,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; @@ -4251,18 +4247,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 ) @@ -4328,7 +4321,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; @@ -4374,7 +4367,6 @@ // contents auto contentsRect( rect ); - if( sunken && !flat ) contentsRect.translate( 1, 1 ); // icon size const QSize iconSize( toolButtonOption->iconSize ); @@ -4454,7 +4446,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; @@ -4468,8 +4460,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 ); @@ -4566,16 +4558,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)) { @@ -4585,9 +4572,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; @@ -6111,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 ); } @@ -6229,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 ); } @@ -6289,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 );