centralize outline color handling

wilder-pre-rebase
Hugo Pereira Da Costa 12 years ago
parent c1a22aca20
commit c4564aba6a
  1. 20
      kstyle/animations/breezewidgetstateengine.h
  2. 28
      kstyle/breezeframeshadow.cpp
  3. 34
      kstyle/breezehelper.cpp
  4. 9
      kstyle/breezehelper.h
  5. 92
      kstyle/breezestyle.cpp

@ -70,6 +70,26 @@ namespace Breeze
virtual qreal opacity( const QObject* object, AnimationMode mode )
{ return isAnimated( object, mode ) ? data( object, mode ).data()->opacity(): AnimationData::OpacityInvalid; }
//! animation mode
/*! precedence on focus */
virtual AnimationMode frameAnimationMode( const QObject* object )
{
if( isAnimated( object, AnimationFocus ) ) return AnimationFocus;
else if( isAnimated( object, AnimationHover ) ) return AnimationHover;
else if( isAnimated( object, AnimationEnable ) ) return AnimationEnable;
else return AnimationNone;
}
//! animation opacity
/*! precedence on focus */
virtual qreal frameOpacity( const QObject* object )
{
if( isAnimated( object, AnimationFocus ) ) return data( object, AnimationFocus ).data()->opacity();
else if( isAnimated( object, AnimationHover ) ) return data( object, AnimationFocus ).data()->opacity();
else if( isAnimated( object, AnimationEnable ) ) return data( object, AnimationEnable ).data()->opacity();
else return AnimationData::OpacityInvalid;
}
//! duration
virtual void setEnabled( bool value )
{

@ -447,36 +447,12 @@ namespace Breeze
default: return;
}
// colors
const QPalette& palette( this->palette() );
const QColor focus( _helper.viewFocusBrush().brush( palette.currentColorGroup() ).color() );
const QColor hover( _helper.viewHoverBrush().brush( palette.currentColorGroup() ).color() );
const QColor defaultOutline( KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 ) );
QColor outline;
if( _mode == AnimationFocus )
{
if( _mouseOver ) outline = KColorUtils::mix( hover, focus, _opacity );
else outline = KColorUtils::mix( defaultOutline, focus, _opacity );
} else if( _hasFocus ) {
outline = focus;
} else if( _mode == AnimationHover ) {
outline = KColorUtils::mix( defaultOutline, hover, _opacity );
} else if( _mouseOver ) {
outline = hover;
} else outline = defaultOutline;
// render
QPainter painter(this);
painter.setClipRegion( event->region() );
painter.setRenderHint( QPainter::Antialiasing );
const QColor outline( _helper.frameOutlineColor( palette(), _mouseOver, _hasFocus, _opacity, _mode ) );
_helper.renderFrame( &painter, rect, QColor(), outline, _hasFocus );
return;

@ -60,6 +60,40 @@ namespace Breeze
return out;
}
//____________________________________________________________________
QColor Helper::frameOutlineColor( const QPalette& palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode ) const
{
// colors
const QColor focus( _viewFocusBrush.brush( palette.currentColorGroup() ).color() );
const QColor hover( _viewHoverBrush.brush( palette.currentColorGroup() ).color() );
const QColor defaultOutline( KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 ) );
QColor outline;
if( mode == AnimationFocus )
{
if( mouseOver ) outline = KColorUtils::mix( hover, focus, opacity );
else outline = KColorUtils::mix( defaultOutline, focus, opacity );
} else if( hasFocus ) {
outline = focus;
} else if( mode == AnimationHover ) {
outline = KColorUtils::mix( defaultOutline, hover, opacity );
} else if( mouseOver ) {
outline = hover;
} else outline = defaultOutline;
return outline;
}
//____________________________________________________________________
QColor Helper::alphaColor( QColor color, qreal alpha )
{

@ -23,6 +23,8 @@
* Boston, MA 02110-1301, USA.
*/
#include "breezeanimationmodes.h"
#include <KSharedConfig>
#include <KColorScheme>
@ -74,6 +76,13 @@ namespace Breeze
//@}
//!@name color utilities
//! frame outline color, using animations
QColor frameOutlineColor( const QPalette&, bool mouseOver, bool hasFocus, qreal opacity = -1, AnimationMode = AnimationNone ) const;
//@}
//!@name rendering utilities
//@{

@ -1178,53 +1178,15 @@ namespace Breeze
if( !( flags & (State_Sunken | State_Raised ) ) ) return true;
// retrieve animation mode and opacity
qreal opacity( -1 );
AnimationMode mode = AnimationNone;
if( enabled && _animations->lineEditEngine().isAnimated( widget, AnimationFocus ) )
{
opacity = _animations->lineEditEngine().opacity( widget, AnimationFocus );
mode = AnimationFocus;
} else if( enabled && _animations->lineEditEngine().isAnimated( widget, AnimationHover ) ) {
opacity = _animations->lineEditEngine().opacity( widget, AnimationHover );
mode = AnimationHover;
}
const AnimationMode mode( _animations->lineEditEngine().frameAnimationMode( widget ) );
const qreal opacity( _animations->lineEditEngine().frameOpacity( widget ) );
// update frame shadow factory
if( _frameShadowFactory->isRegistered( widget ) )
{ _frameShadowFactory->updateState( widget, hasFocus, mouseOver, opacity, mode ); }
// colors
const QPalette& palette( option->palette );
const QColor focus( _helper->viewFocusBrush().brush( palette.currentColorGroup() ).color() );
const QColor hover( _helper->viewHoverBrush().brush( palette.currentColorGroup() ).color() );
const QColor defaultOutline( KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 ) );
QColor outline;
if( mode == AnimationFocus )
{
if( mouseOver ) outline = KColorUtils::mix( hover, focus, opacity );
else outline = KColorUtils::mix( defaultOutline, focus, opacity );
} else if( hasFocus ) {
outline = focus;
} else if( mode == AnimationHover ) {
outline = KColorUtils::mix( defaultOutline, hover, opacity );
} else if( mouseOver ) {
outline = hover;
} else outline = defaultOutline;
// render
const QColor outline( _helper->frameOutlineColor( option->palette, mouseOver, hasFocus, opacity, mode ) );
_helper->renderFrame( painter, option->rect, QColor(), outline, hasFocus );
return true;
@ -1995,36 +1957,15 @@ namespace Breeze
{
// editable combobox. Make it look like a LineEdit
// update animation state
// focus takes precedence over hover
_animations->lineEditEngine().updateState( widget, AnimationFocus, hasFocus );
_animations->lineEditEngine().updateState( widget, AnimationHover, mouseOver && !hasFocus );
// colors
const QColor focus( _helper->viewFocusBrush().brush( palette.currentColorGroup() ).color() );
const QColor hover( _helper->viewHoverBrush().brush( palette.currentColorGroup() ).color() );
const QColor defaultOutline( KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 ) );
QColor outline;
if( enabled && _animations->lineEditEngine().isAnimated( widget, AnimationFocus ) )
{
const qreal opacity( _animations->lineEditEngine().opacity( widget, AnimationFocus ) );
if( mouseOver ) outline = KColorUtils::mix( hover, focus, opacity );
else outline = KColorUtils::mix( defaultOutline, focus, opacity );
} else if( hasFocus ) {
outline = _helper->viewFocusBrush().brush( palette ).color();
} else if( enabled && _animations->lineEditEngine().isAnimated( widget, AnimationHover ) ) {
const qreal opacity( _animations->lineEditEngine().opacity( widget, AnimationHover ) );
outline = KColorUtils::mix( defaultOutline, hover, opacity );
} else if( mouseOver ) {
outline = _helper->viewHoverBrush().brush( palette ).color();
} else outline = KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 );
// outline color
const QColor outline( _helper->frameOutlineColor( palette, mouseOver, hasFocus,
_animations->lineEditEngine().frameOpacity( widget ),
_animations->lineEditEngine().frameAnimationMode( widget ) ) );
// render
_helper->renderFrame( painter, option->rect, palette.color( QPalette::Base ), outline, hasFocus );
@ -2112,10 +2053,19 @@ namespace Breeze
if( option->subControls & SC_SpinBoxFrame )
{
QColor outline;
if( mouseOver ) outline = _helper->viewHoverBrush().brush( palette ).color();
else if( hasFocus ) outline = _helper->viewHoverBrush().brush( palette ).color();
else outline = KColorUtils::mix( palette.color( QPalette::Window ), palette.color( QPalette::WindowText ), 0.25 );
// update animation state
// focus takes precedence over hover
_animations->lineEditEngine().updateState( widget, AnimationFocus, hasFocus );
_animations->lineEditEngine().updateState( widget, AnimationHover, mouseOver && !hasFocus );
// outline color
const QColor outline( _helper->frameOutlineColor( palette, mouseOver, hasFocus,
_animations->lineEditEngine().frameOpacity( widget ),
_animations->lineEditEngine().frameAnimationMode( widget ) ) );
// render
_helper->renderFrame( painter, option->rect, palette.color( QPalette::Base ), outline, hasFocus );
// render
_helper->renderFrame( painter, option->rect, palette.color( QPalette::Base ), outline, hasFocus );

Loading…
Cancel
Save