From 24e01d0e7bdf0ea8faa8384490ef3d896e1422d9 Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Wed, 12 May 2010 23:34:31 +0000 Subject: [PATCH] Removed dependency of Oxygen::ShadowCache upon Oxygen::Client. svn path=/trunk/KDE/kdebase/workspace/; revision=1126021 --- clients/oxygen/oxygenclient.cpp | 7 +++-- clients/oxygen/oxygenclient.h | 13 +++++++++ clients/oxygen/oxygenshadowcache.cpp | 43 ++++------------------------ clients/oxygen/oxygenshadowcache.h | 25 ++++++---------- 4 files changed, 33 insertions(+), 55 deletions(-) diff --git a/clients/oxygen/oxygenclient.cpp b/clients/oxygen/oxygenclient.cpp index 90d2ebd19b..5b673e47ed 100644 --- a/clients/oxygen/oxygenclient.cpp +++ b/clients/oxygen/oxygenclient.cpp @@ -1351,12 +1351,15 @@ namespace Oxygen { TileSet *tileSet( 0 ); + QColor background( backgroundPalette( widget(), palette ).window().color() ); + ShadowCache::Key key( Client::key() ); if( configuration().useOxygenShadows() && glowIsAnimated() && !isForcedActive() ) { - tileSet = shadowCache().tileSet( this, glowIntensity() ); + //tileSet = shadowCache().tileSet( this, glowIntensity() ); + tileSet = shadowCache().tileSet( background, key, glowIntensity() ); - } else tileSet = shadowCache().tileSet( this ); + } else tileSet = shadowCache().tileSet( background, key ); if( !isMaximized() ) tileSet->render( frame.adjusted( 4, 4, -4, -4), &painter, TileSet::Ring); else if( isShade() ) tileSet->render( frame.adjusted( 0, 4, 0, -4), &painter, TileSet::Bottom); diff --git a/clients/oxygen/oxygenclient.h b/clients/oxygen/oxygenclient.h index d35dfbc87b..afa7d237b4 100644 --- a/clients/oxygen/oxygenclient.h +++ b/clients/oxygen/oxygenclient.h @@ -33,6 +33,7 @@ #include "oxygenconfiguration.h" #include "oxygendecohelper.h" #include "oxygenfactory.h" +#include "oxygenshadowcache.h" #include "oxygentitleanimationdata.h" #include @@ -206,6 +207,18 @@ namespace Oxygen protected: + //! return shadow cache key associated to this client + ShadowCache::Key key( void ) const + { + ShadowCache::Key key; + key.active = isActive() || isForcedActive(); + key.useOxygenShadows = configuration().useOxygenShadows(); + key.isShade = isShade(); + key.hasTitleOutline = configuration().drawTitleOutline(); + key.hasBorder = ( configuration().frameBorder() > Configuration::BorderNone ); + return key; + } + //! true when decoration is forced active void setForceActive( bool value ) { forceActive_ = value; } diff --git a/clients/oxygen/oxygenshadowcache.cpp b/clients/oxygen/oxygenshadowcache.cpp index c37ae94eec..1b1859c831 100644 --- a/clients/oxygen/oxygenshadowcache.cpp +++ b/clients/oxygen/oxygenshadowcache.cpp @@ -25,7 +25,6 @@ ////////////////////////////////////////////////////////////////////////////// #include "oxygenshadowcache.h" -#include "oxygenclient.h" #include "oxygenhelper.h" #include @@ -68,33 +67,29 @@ namespace Oxygen } //_______________________________________________________ - TileSet* ShadowCache::tileSet( const Client* client ) + TileSet* ShadowCache::tileSet( const QColor& color, const Key& key ) { - // construct key - Key key( client ); - // check if tileset already in cache int hash( key.hash() ); if( shadowCache_.contains(hash) ) return shadowCache_.object(hash); // create tileset otherwise qreal size( shadowSize() ); - TileSet* tileSet = new TileSet( shadowPixmap( client, key.active ), size, size, 1, 1); + TileSet* tileSet = new TileSet( shadowPixmap( color, key, key.active ), size, size, 1, 1); shadowCache_.insert( hash, tileSet ); return tileSet; } //_______________________________________________________ - TileSet* ShadowCache::tileSet( const Client* client, qreal opacity ) + TileSet* ShadowCache::tileSet( const QColor& color, Key key, qreal opacity ) { int index( opacity*maxIndex_ ); assert( index <= maxIndex_ ); // construct key - Key key( client ); key.index = index; // check if tileset already in cache @@ -109,7 +104,7 @@ namespace Oxygen QPainter p( &shadow ); p.setRenderHint( QPainter::Antialiasing ); - QPixmap inactiveShadow( shadowPixmap( client, false ) ); + QPixmap inactiveShadow( shadowPixmap( color, key, false ) ); { QPainter pp( &inactiveShadow ); pp.setRenderHint( QPainter::Antialiasing ); @@ -117,7 +112,7 @@ namespace Oxygen pp.fillRect( inactiveShadow.rect(), QColor( 0, 0, 0, 255*(1.0-opacity ) ) ); } - QPixmap activeShadow( shadowPixmap( client, true ) ); + QPixmap activeShadow( shadowPixmap( color, key, true ) ); { QPainter pp( &activeShadow ); pp.setRenderHint( QPainter::Antialiasing ); @@ -135,20 +130,8 @@ namespace Oxygen } - //_________________________________________________________________ - QPixmap ShadowCache::shadowPixmap(const Client* client, bool active ) const - { - - // get window color - Key key( client ); - QPalette palette( client->backgroundPalette( client->widget(), client->widget()->palette() ) ); - QColor color( palette.color( client->widget()->backgroundRole() ) ); - return simpleShadowPixmap( color, key, active ); - - } - //_______________________________________________________ - QPixmap ShadowCache::simpleShadowPixmap( const QColor& color, const Key& key, bool active ) const + QPixmap ShadowCache::shadowPixmap( const QColor& color, const Key& key, bool active ) const { // local reference to relevant shadow configuration @@ -447,18 +430,4 @@ namespace Oxygen } - //__________________________________________________________ - ShadowCache::Key::Key( const Client* client): - index(0) - { - - active = client->isActive() || client->isForcedActive(); - useOxygenShadows = client->configuration().useOxygenShadows(); - isShade = client->isShade(); - hasTitleOutline = client->configuration().drawTitleOutline(); - hasBorder = ( client->configuration().frameBorder() > Configuration::BorderNone ); - - } - - } diff --git a/clients/oxygen/oxygenshadowcache.h b/clients/oxygen/oxygenshadowcache.h index a71bc313b0..ed729fb4b6 100644 --- a/clients/oxygen/oxygenshadowcache.h +++ b/clients/oxygen/oxygenshadowcache.h @@ -38,7 +38,6 @@ namespace Oxygen { - class Client; class ShadowCache { public: @@ -119,12 +118,6 @@ namespace Oxygen return qMax( size, qreal(5.0) ); } - //! get shadow matching client - TileSet* tileSet( const Client* ); - - //! get shadow matching client and opacity - TileSet* tileSet( const Client*, qreal ); - //! Key class to be used into QCache /*! class is entirely inline for optimization */ class Key @@ -142,9 +135,6 @@ namespace Oxygen hasBorder( true ) {} - //! constructor from client - Key( const Client* ); - //! constructor from int Key( int hash ): index( hash>>5 ), @@ -180,15 +170,18 @@ namespace Oxygen }; - //! complex pixmap (when needed) - QPixmap shadowPixmap( const Client*, bool active ) const; + //! get shadow matching client + TileSet* tileSet( const QColor&, const Key& ); + + //! get shadow matching client and opacity + TileSet* tileSet( const QColor&, Key, qreal ); //! simple pixmap - QPixmap simpleShadowPixmap( const QColor& color, const Key& key ) const - { return simpleShadowPixmap( color, key, key.active ); } + QPixmap shadowPixmap( const QColor& color, const Key& key ) const + { return shadowPixmap( color, key, key.active ); } //! simple pixmap - QPixmap simpleShadowPixmap( const QColor&, const Key&, bool active ) const; + QPixmap shadowPixmap( const QColor&, const Key&, bool active ) const; protected: @@ -242,7 +235,7 @@ namespace Oxygen //! value virtual qreal operator() ( qreal x ) const - { return amplitude_*std::exp( -square(x/width_) ); } + { return qMax( 0.0, amplitude_*(std::exp( -square(x/width_) -0.05 ) ) ); } private: