From bd6653ef598bbb3a776a0c9cef9e621f00e32c0c Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Thu, 15 Sep 2011 21:55:52 +0200 Subject: [PATCH] Moved painting of windeco buttons to own cache in Style and deco helper; Simplified decoration windeco buttons painting to use only one cache; Renamed windeco button painting to dockWidgetButton painting for style. --- clients/oxygen/oxygenbutton.cpp | 5 +- clients/oxygen/oxygendecohelper.cpp | 159 +++++++++++++--------------- clients/oxygen/oxygendecohelper.h | 7 +- 3 files changed, 78 insertions(+), 93 deletions(-) diff --git a/clients/oxygen/oxygenbutton.cpp b/clients/oxygen/oxygenbutton.cpp index f382ccb8ff..6e0921538f 100644 --- a/clients/oxygen/oxygenbutton.cpp +++ b/clients/oxygen/oxygenbutton.cpp @@ -267,9 +267,6 @@ namespace Oxygen qreal scale( (21.0*_client.configuration().buttonSize())/22.0 ); - // draw shadow - painter.drawPixmap( 0, 0, _helper.windecoButtonGlow( shadow, scale ) ); - // decide on pressed state const bool pressed( (_status == Oxygen::Pressed) || @@ -278,7 +275,7 @@ namespace Oxygen ( _type == ButtonBelow && _client.keepBelow() ) ); // draw button shape - painter.drawPixmap(0, 0, _helper.windecoButton( base, pressed, scale ) ); + painter.drawPixmap(0, 0, _helper.windecoButton( base, shadow, pressed, scale ) ); } diff --git a/clients/oxygen/oxygendecohelper.cpp b/clients/oxygen/oxygendecohelper.cpp index 3a91b7de25..ae6b982d3f 100644 --- a/clients/oxygen/oxygendecohelper.cpp +++ b/clients/oxygen/oxygendecohelper.cpp @@ -43,123 +43,110 @@ namespace Oxygen Helper::invalidateCaches(); // local caches + _windecoButtonCache.clear(); _titleBarTextColorCache.clear(); _buttonTextColorCache.clear(); } //______________________________________________________________________________ - QPixmap DecoHelper::windecoButton(const QColor &color, bool pressed, int size) + QPixmap DecoHelper::windecoButton(const QColor &color, const QColor& glow, bool sunken, int size) { - const quint64 key( (quint64(color.rgba()) << 32) | (size << 1) | (int)pressed ); - QPixmap *pixmap( windecoButtonCache().object(key) ); + + Oxygen::Cache::Value* cache( _windecoButtonCache.get( color ) ); + + const quint64 key( ( quint64( glow.rgba() ) << 32 ) | (sunken << 23 ) | size ); + QPixmap *pixmap = cache->object( key ); if( !pixmap ) { pixmap = new QPixmap(size, size); pixmap->fill(Qt::transparent); - const QColor light( calcLightColor(color) ); - const QColor dark( calcDarkColor(color) ); - QPainter p( pixmap ); p.setRenderHints(QPainter::Antialiasing); p.setPen(Qt::NoPen); qreal u = size/18.0; p.translate( 0.5*u, (0.5-0.668)*u ); + // button glow + if( glow.isValid() ) { - //plain background - QLinearGradient lg( 0, u*1.665, 0, u*(12.33+1.665) ); - if( pressed ) + { - lg.setColorAt( 1, light ); - lg.setColorAt( 0, dark ); - } else { - lg.setColorAt( 0, light ); - lg.setColorAt( 1, dark ); + // outer shadow + QRadialGradient rg( u*8.5, u*8.5, u*8.5 ); + + static const int nPoints(5); + const qreal x[5] = { 0.61, 0.72, 0.81, 0.9, 1}; + const qreal values[5] = { 255-172, 255-178, 255-210, 255-250, 0 }; + QColor c = glow; + for( int i = 0; irect() ); + p.setBrush( rg ); + p.drawRect( r ); + } + + { + // inner shadow + QRadialGradient rg( u*8.5, u*8.5, u*8.5 ); + + static const int nPoints(6); + const qreal x[6] = { 0.61, 0.67, 0.7, 0.74, 0.78, 1 }; + const qreal values[6] = { 255-92, 255-100, 255-135, 255-205, 255-250, 0 }; + QColor c = glow; + for( int i = 0; irect() ); + p.setBrush( rg ); + p.drawRect( r ); } - const QRectF r( u*0.5*(17-12.33), u*1.665, u*12.33, u*12.33 ); - p.setBrush( lg ); - p.drawEllipse( r ); } - { - // outline circle - const qreal penWidth( 0.7 ); - QLinearGradient lg( 0, u*1.665, 0, u*(2.0*12.33+1.665) ); - lg.setColorAt( 0, light ); - lg.setColorAt( 1, dark ); - const QRectF r( u*0.5*(17-12.33+penWidth), u*(1.665+penWidth), u*(12.33-penWidth), u*(12.33-penWidth) ); - p.setPen( QPen( lg, penWidth*u ) ); - p.setBrush( Qt::NoBrush ); - p.drawEllipse( r ); - p.end(); - } - - windecoButtonCache().insert( key, pixmap ); - } - - return *pixmap; - } - - //_______________________________________________________________________ - QPixmap DecoHelper::windecoButtonGlow(const QColor &color, int size) - { - const quint64 key( (quint64(color.rgba()) << 32) | size ); - QPixmap *pixmap( windecoButtonGlowCache().object(key) ); - - if( !pixmap ) - { - pixmap = new QPixmap(size, size); - pixmap->fill(Qt::transparent); - - // right now the same color is used for the two shadows - const QColor& light( color ); - const QColor& dark( color ); - - QPainter p(pixmap); - p.setRenderHints(QPainter::Antialiasing); - p.setPen(Qt::NoPen); - qreal u = size/18.0; - p.translate( 0.5*u, (0.5-0.668)*u ); - + // button slab + if( color.isValid() ) { - // outer shadow - QRadialGradient rg( u*8.5, u*8.5, u*8.5 ); + const QColor light( calcLightColor(color) ); + const QColor dark( calcDarkColor(color) ); - static const int nPoints(5); - const qreal x[5] = { 0.61, 0.72, 0.81, 0.9, 1}; - const qreal values[5] = { 255-172, 255-178, 255-210, 255-250, 0 }; - QColor c = dark; - for( int i = 0; irect() ); - p.setBrush( rg ); - p.drawRect( r ); } - { - // inner shadow - QRadialGradient rg( u*8.5, u*8.5, u*8.5 ); - - static const int nPoints(6); - const qreal x[6] = { 0.61, 0.67, 0.7, 0.74, 0.78, 1 }; - const qreal values[6] = { 255-92, 255-100, 255-135, 255-205, 255-250, 0 }; - QColor c = light; - for( int i = 0; irect() ); - p.setBrush( rg ); - p.drawRect( r ); - } - - windecoButtonGlowCache().insert( key, pixmap ); - + p.end(); + cache->insert( key, pixmap ); } return *pixmap; diff --git a/clients/oxygen/oxygendecohelper.h b/clients/oxygen/oxygendecohelper.h index 8d22486958..e86687254c 100644 --- a/clients/oxygen/oxygendecohelper.h +++ b/clients/oxygen/oxygendecohelper.h @@ -50,8 +50,7 @@ namespace Oxygen //!@name decoration specific helper functions //! //@{ - virtual QPixmap windecoButton(const QColor &color, bool pressed, int size = 21); - virtual QPixmap windecoButtonGlow(const QColor &color, int size = 21); + virtual QPixmap windecoButton(const QColor &color, const QColor& glow, bool sunken, int size = 21); //@} // @@ -73,13 +72,15 @@ namespace Oxygen //! dynamically allocated debug area int _debugArea; + //! windeco buttons + Cache _windecoButtonCache; + //! titleBar text color cache ColorCache _titleBarTextColorCache; //! button text color cache ColorCache _buttonTextColorCache; - }; }