Use lightSource to decide how to render shadow on items

wilder-pre-rebase
Hugo Pereira Da Costa 12 years ago
parent 73555014e6
commit 1f571ed2f1
  1. 61
      kstyle/breezehelper.cpp
  2. 5
      kstyle/breezehelper.h

@ -447,24 +447,19 @@ namespace Breeze
// copy rect
QRectF frameRect( rect );
frameRect.adjust( 1, 1, -1, -1 );
qreal radius( frameRadius() );
// shadow
if( shadow.isValid() && !sunken )
{
QRectF shadowRect( frameRect.adjusted( 1.5, 1.5, -1.5, -1.5 ).translated( 0, 0.5 ) );
const qreal radius( frameRadius() );
painter->setPen( QPen( shadow, 2 ) );
painter->setBrush( Qt::NoBrush );
painter->drawRoundedRect( shadowRect, radius, radius );
painter->drawRoundedRect( shadowRect( frameRect ), radius, radius );
}
// outline
qreal radius( frameRadius() );
frameRect.adjust( 1, 1, -1, -1 );
if( outline.isValid() && !hasFocus )
{
@ -660,30 +655,29 @@ namespace Breeze
// setup painter
painter->setRenderHint( QPainter::Antialiasing, true );
// copy rect
QRectF baseRect( rect );
// copy rect and radius
QRectF frameRect( rect );
frameRect.adjust( 1, 1, -1, -1 );
const qreal radius( frameRadius() );
// shadow
if( !sunken )
{
const qreal radius( frameRadius() );
painter->setPen( QPen( shadow, 2 ) );
painter->setBrush( Qt::NoBrush );
const QRectF shadowRect( baseRect.adjusted( 1.5, 1.5, -1.5, -1.5 ).translated( 0, 0.5 ) );
painter->drawRoundedRect( shadowRect, radius, radius );
painter->drawRoundedRect( shadowRect( frameRect ), radius, radius );
}
// content
{
const qreal radius( frameRadius() );
painter->setPen( QPen( color, 2 ) );
painter->setBrush( Qt::NoBrush );
const QRectF contentRect( baseRect.adjusted( 2, 2, -2, -2 ) );
const QRectF contentRect( frameRect.adjusted( 1, 1, -1, -1 ) );
painter->drawRoundedRect( contentRect, radius, radius );
}
@ -695,7 +689,7 @@ namespace Breeze
painter->setBrush( color );
painter->setPen( Qt::NoPen );
const QRectF markerRect( baseRect.adjusted( 5, 5, -5, -5 ) );
const QRectF markerRect( frameRect.adjusted( 4, 4, -4, -4 ) );
painter->drawRect( markerRect );
} else if( state == CheckPartial ) {
@ -704,7 +698,7 @@ namespace Breeze
pen.setJoinStyle( Qt::MiterJoin );
painter->setPen( pen );
const QRectF markerRect( baseRect.adjusted( 6, 6, -6, -6 ) );
const QRectF markerRect( frameRect.adjusted( 5, 5, -5, -5 ) );
painter->drawRect( markerRect );
painter->setPen( Qt::NoPen );
@ -731,7 +725,9 @@ namespace Breeze
// setup painter
painter->setRenderHint( QPainter::Antialiasing, true );
QRectF baseRect( rect );
// copy rect
QRectF frameRect( rect );
frameRect.adjust( 1, 1, -1, -1 );
// shadow
if( !sunken )
@ -739,9 +735,7 @@ namespace Breeze
painter->setPen( QPen( shadow, 2 ) );
painter->setBrush( Qt::NoBrush );
const QRectF shadowRect( baseRect.adjusted( 1.5, 1.5, -1.5, -1.5 ).translated( 0, 0.5 ) );
painter->drawEllipse( shadowRect );
painter->drawEllipse( shadowRect( frameRect ) );
}
@ -751,7 +745,7 @@ namespace Breeze
painter->setPen( QPen( color, 2 ) );
painter->setBrush( Qt::NoBrush );
const QRectF contentRect( baseRect.adjusted( 2, 2, -2, -2 ) );
const QRectF contentRect( frameRect.adjusted( 1, 1, -1, -1 ) );
painter->drawEllipse( contentRect );
}
@ -763,7 +757,7 @@ namespace Breeze
painter->setBrush( color );
painter->setPen( Qt::NoPen );
const QRectF markerRect( baseRect.adjusted( 5, 5, -5, -5 ) );
const QRectF markerRect( frameRect.adjusted( 4, 4, -4, -4 ) );
painter->drawEllipse( markerRect );
}
@ -873,7 +867,9 @@ namespace Breeze
// setup painter
painter->setRenderHint( QPainter::Antialiasing, true );
// copy rect
QRectF frameRect( rect );
frameRect.adjust( 1, 1, -1, -1 );
// shadow
if( shadow.isValid() && !sunken )
@ -881,14 +877,10 @@ namespace Breeze
painter->setPen( QPen( shadow, 2 ) );
painter->setBrush( Qt::NoBrush );
const QRectF shadowRect( frameRect.adjusted( 1.5, 1.5, -1.5, -1.5 ).translated( 0, 0.5 ) );
painter->drawEllipse( shadowRect );
painter->drawEllipse( shadowRect( frameRect ) );
}
frameRect.adjust( 1, 1, -1, -1 );
// set pen
if( outline.isValid() )
{
@ -1183,6 +1175,19 @@ namespace Breeze
}
//______________________________________________________________________________
QRectF Helper::shadowRect( const QRectF& rect ) const
{
switch( StyleConfigData::lightSource() )
{
case StyleConfigData::LS_TOP: return rect.adjusted( 0.5, 0.5, -0.5, -0.5 ).translated( 0, 0.5 );
case StyleConfigData::LS_TOPLEFT: return rect.adjusted( 0.5, 0.5, -0.5, -0.5 ).translated( 0.5, 0.5 );
case StyleConfigData::LS_TOPRIGHT: return rect.adjusted( 0.5, 0.5, -0.5, -0.5 ).translated( -0.5, 0.5 );
default: return rect;
}
}
//______________________________________________________________________________
QPainterPath Helper::roundedPath( const QRectF& rect, qreal radius, Corners corners ) const
{

@ -230,9 +230,8 @@ namespace Breeze
qreal frameRadius( void ) const
{ return qreal( Metrics::Frame_FrameRadius )-0.5; }
//! return color key for a given color, properly accounting for invalid colors
quint64 colorKey( const QColor& color ) const
{ return color.isValid() ? color.rgba():0; }
//! return rectangle for widgets shadow, offset depending on light source
QRectF shadowRect( const QRectF& ) const;
//! return rounded path in a given rect, with only selected corners rounded, and for a given radius
QPainterPath roundedPath( const QRectF&, qreal, Corners ) const;

Loading…
Cancel
Save