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.
This commit is contained in:
parent
c5365e287a
commit
bd6653ef59
3 changed files with 78 additions and 93 deletions
|
@ -267,9 +267,6 @@ namespace Oxygen
|
||||||
|
|
||||||
qreal scale( (21.0*_client.configuration().buttonSize())/22.0 );
|
qreal scale( (21.0*_client.configuration().buttonSize())/22.0 );
|
||||||
|
|
||||||
// draw shadow
|
|
||||||
painter.drawPixmap( 0, 0, _helper.windecoButtonGlow( shadow, scale ) );
|
|
||||||
|
|
||||||
// decide on pressed state
|
// decide on pressed state
|
||||||
const bool pressed(
|
const bool pressed(
|
||||||
(_status == Oxygen::Pressed) ||
|
(_status == Oxygen::Pressed) ||
|
||||||
|
@ -278,7 +275,7 @@ namespace Oxygen
|
||||||
( _type == ButtonBelow && _client.keepBelow() ) );
|
( _type == ButtonBelow && _client.keepBelow() ) );
|
||||||
|
|
||||||
// draw button shape
|
// draw button shape
|
||||||
painter.drawPixmap(0, 0, _helper.windecoButton( base, pressed, scale ) );
|
painter.drawPixmap(0, 0, _helper.windecoButton( base, shadow, pressed, scale ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,123 +43,110 @@ namespace Oxygen
|
||||||
Helper::invalidateCaches();
|
Helper::invalidateCaches();
|
||||||
|
|
||||||
// local caches
|
// local caches
|
||||||
|
_windecoButtonCache.clear();
|
||||||
_titleBarTextColorCache.clear();
|
_titleBarTextColorCache.clear();
|
||||||
_buttonTextColorCache.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<QPixmap>::Value* cache( _windecoButtonCache.get( color ) );
|
||||||
|
|
||||||
|
const quint64 key( ( quint64( glow.rgba() ) << 32 ) | (sunken << 23 ) | size );
|
||||||
|
QPixmap *pixmap = cache->object( key );
|
||||||
|
|
||||||
if( !pixmap )
|
if( !pixmap )
|
||||||
{
|
{
|
||||||
pixmap = new QPixmap(size, size);
|
pixmap = new QPixmap(size, size);
|
||||||
pixmap->fill(Qt::transparent);
|
pixmap->fill(Qt::transparent);
|
||||||
|
|
||||||
const QColor light( calcLightColor(color) );
|
|
||||||
const QColor dark( calcDarkColor(color) );
|
|
||||||
|
|
||||||
QPainter p( pixmap );
|
QPainter p( pixmap );
|
||||||
p.setRenderHints(QPainter::Antialiasing);
|
p.setRenderHints(QPainter::Antialiasing);
|
||||||
p.setPen(Qt::NoPen);
|
p.setPen(Qt::NoPen);
|
||||||
qreal u = size/18.0;
|
qreal u = size/18.0;
|
||||||
p.translate( 0.5*u, (0.5-0.668)*u );
|
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 );
|
// outer shadow
|
||||||
lg.setColorAt( 0, dark );
|
QRadialGradient rg( u*8.5, u*8.5, u*8.5 );
|
||||||
} else {
|
|
||||||
lg.setColorAt( 0, light );
|
static const int nPoints(5);
|
||||||
lg.setColorAt( 1, dark );
|
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; i<nPoints; i++ )
|
||||||
|
{ c.setAlpha( values[i] ); rg.setColorAt( x[i], c ); }
|
||||||
|
|
||||||
|
QRectF r( pixmap->rect() );
|
||||||
|
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; i<nPoints; i++ )
|
||||||
|
{ c.setAlpha( values[i] ); rg.setColorAt( x[i], c ); }
|
||||||
|
|
||||||
|
QRectF r( pixmap->rect() );
|
||||||
|
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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
// button slab
|
||||||
// outline circle
|
if( color.isValid() )
|
||||||
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 );
|
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
// outer shadow
|
const QColor light( calcLightColor(color) );
|
||||||
QRadialGradient rg( u*8.5, u*8.5, u*8.5 );
|
const QColor dark( calcDarkColor(color) );
|
||||||
|
|
||||||
static const int nPoints(5);
|
{
|
||||||
const qreal x[5] = { 0.61, 0.72, 0.81, 0.9, 1};
|
//plain background
|
||||||
const qreal values[5] = { 255-172, 255-178, 255-210, 255-250, 0 };
|
QLinearGradient lg( 0, u*1.665, 0, u*(12.33+1.665) );
|
||||||
QColor c = dark;
|
if( sunken )
|
||||||
for( int i = 0; i<nPoints; i++ )
|
{
|
||||||
{ c.setAlpha( values[i] ); rg.setColorAt( x[i], c ); }
|
lg.setColorAt( 1, light );
|
||||||
|
lg.setColorAt( 0, dark );
|
||||||
|
} else {
|
||||||
|
lg.setColorAt( 0, light );
|
||||||
|
lg.setColorAt( 1, dark );
|
||||||
|
}
|
||||||
|
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
QRectF r( pixmap->rect() );
|
|
||||||
p.setBrush( rg );
|
|
||||||
p.drawRect( r );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
p.end();
|
||||||
// inner shadow
|
cache->insert( key, pixmap );
|
||||||
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; i<nPoints; i++ )
|
|
||||||
{ c.setAlpha( values[i] ); rg.setColorAt( x[i], c ); }
|
|
||||||
|
|
||||||
QRectF r( pixmap->rect() );
|
|
||||||
p.setBrush( rg );
|
|
||||||
p.drawRect( r );
|
|
||||||
}
|
|
||||||
|
|
||||||
windecoButtonGlowCache().insert( key, pixmap );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return *pixmap;
|
return *pixmap;
|
||||||
|
|
|
@ -50,8 +50,7 @@ namespace Oxygen
|
||||||
//!@name decoration specific helper functions
|
//!@name decoration specific helper functions
|
||||||
//!
|
//!
|
||||||
//@{
|
//@{
|
||||||
virtual QPixmap windecoButton(const QColor &color, bool pressed, int size = 21);
|
virtual QPixmap windecoButton(const QColor &color, const QColor& glow, bool sunken, int size = 21);
|
||||||
virtual QPixmap windecoButtonGlow(const QColor &color, int size = 21);
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -73,13 +72,15 @@ namespace Oxygen
|
||||||
//! dynamically allocated debug area
|
//! dynamically allocated debug area
|
||||||
int _debugArea;
|
int _debugArea;
|
||||||
|
|
||||||
|
//! windeco buttons
|
||||||
|
Cache<QPixmap> _windecoButtonCache;
|
||||||
|
|
||||||
//! titleBar text color cache
|
//! titleBar text color cache
|
||||||
ColorCache _titleBarTextColorCache;
|
ColorCache _titleBarTextColorCache;
|
||||||
|
|
||||||
//! button text color cache
|
//! button text color cache
|
||||||
ColorCache _buttonTextColorCache;
|
ColorCache _buttonTextColorCache;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue