Commit 75bee8ed authored by Hugo Pereira Da Costa's avatar Hugo Pereira Da Costa
Browse files

properly deal with invalid colors when calculating cache keys.

using color.rgba() for an invalid color corresponds to solid black, which in turns conflicts with the cache
value for such color. We use "transparent black" instead.
CCBUG: 304868
parent 333f037f
......@@ -168,7 +168,7 @@ namespace Oxygen
//______________________________________________________________________________
QPixmap StyleHelper::dockWidgetButton( const QColor& color, bool pressed, int size )
{
const quint64 key( ( quint64( color.rgba() ) << 32 ) | ( size << 1 ) | quint64( pressed ) );
const quint64 key( ( colorKey(color) << 32 ) | ( size << 1 ) | quint64( pressed ) );
QPixmap *pixmap = _dockWidgetButtonCache.object( key );
if ( !pixmap )
......@@ -206,7 +206,7 @@ namespace Oxygen
//________________________________________________________________________________________________________
TileSet *StyleHelper::roundCorner( const QColor& color, int size )
{
const quint64 key( ( quint64( color.rgba() ) << 32 )|size );
const quint64 key( ( colorKey(color) << 32 )|size );
TileSet *tileSet = _cornerCache.object( key );
if ( !tileSet )
......@@ -243,7 +243,7 @@ namespace Oxygen
//________________________________________________________________________________________________________
TileSet *StyleHelper::slope( const QColor& color, qreal shade, int size )
{
const quint64 key( ( quint64( color.rgba() ) << 32 )|( quint64( 256.0*shade )<<24 )|size );
const quint64 key( ( colorKey(color) << 32 )|( quint64( 256.0*shade )<<24 )|size );
TileSet *tileSet = _slopeCache.object( key );
if ( !tileSet )
......@@ -294,7 +294,7 @@ namespace Oxygen
{
const QColor highlight( pal.color( QPalette::Highlight ) );
const quint64 key( ( quint64( highlight.rgba() ) << 32 ) | dimension );
const quint64 key( ( colorKey(highlight) << 32 ) | dimension );
TileSet *tileSet = _progressBarCache.object( key );
if ( !tileSet )
......@@ -398,7 +398,7 @@ namespace Oxygen
{
Oxygen::Cache<QPixmap>::Value* cache = _dialSlabCache.get( color );
const quint64 key( ( quint64( glow.rgba() ) << 32 ) | ( quint64( 256.0 * shade ) << 24 ) | size );
const quint64 key( ( colorKey(glow) << 32 ) | ( quint64( 256.0 * shade ) << 24 ) | size );
QPixmap *pixmap = cache->object( key );
if ( !pixmap )
{
......@@ -463,7 +463,7 @@ namespace Oxygen
Oxygen::Cache<QPixmap>::Value* cache( _roundSlabCache.get( color ) );
const quint64 key( ( quint64( glow.rgba() ) << 32 ) | ( quint64( 256.0 * shade ) << 24 ) | size );
const quint64 key( ( colorKey(glow) << 32 ) | ( quint64( 256.0 * shade ) << 24 ) | size );
QPixmap *pixmap = cache->object( key );
if ( !pixmap )
......@@ -498,7 +498,7 @@ namespace Oxygen
Oxygen::Cache<QPixmap>::Value* cache( _sliderSlabCache.get( color ) );
const quint64 key( ( quint64( glow.rgba() ) << 32 ) | ( quint64( 256.0 * shade ) << 24 ) | (sunken << 23 ) | size );
const quint64 key( ( colorKey(glow) << 32 ) | ( quint64( 256.0 * shade ) << 24 ) | (sunken << 23 ) | size );
QPixmap *pixmap = cache->object( key );
if ( !pixmap )
......@@ -714,7 +714,7 @@ namespace Oxygen
//________________________________________________________________________________________________________
TileSet *StyleHelper::holeFlat( const QColor& color, qreal shade, bool fill, int size )
{
const quint64 key( ( quint64( color.rgba() ) << 32 ) | ( quint64( 256.0 * shade ) << 24 ) | size << 1 | fill );
const quint64 key( ( colorKey(color) << 32 ) | ( quint64( 256.0 * shade ) << 24 ) | size << 1 | fill );
TileSet *tileSet = _holeFlatCache.object( key );
if ( !tileSet )
......@@ -807,7 +807,7 @@ namespace Oxygen
// get key
Oxygen::Cache<TileSet>::Value* cache( _holeCache.get( glow ) );
const quint64 key( ( quint64( color.rgba() ) << 32 ) | (size << 4) | options );
const quint64 key( ( colorKey(color) << 32 ) | (size << 4) | options );
TileSet *tileSet = cache->object( key );
if ( !tileSet )
......@@ -908,7 +908,7 @@ namespace Oxygen
TileSet *StyleHelper::scrollHole( const QColor& color, Qt::Orientation orientation, bool smallShadow )
{
const quint64 key( quint64( color.rgba() ) << 32 | ( orientation == Qt::Horizontal ? 2 : 0 ) | ( smallShadow ? 1 : 0 ) );
const quint64 key( colorKey(color) << 32 | ( orientation == Qt::Horizontal ? 2 : 0 ) | ( smallShadow ? 1 : 0 ) );
TileSet *tileSet = _scrollHoleCache.object( key );
if ( !tileSet )
{
......@@ -1008,7 +1008,7 @@ namespace Oxygen
// get key
Oxygen::Cache<TileSet>::Value* cache( _scrollHandleCache.get( glow ) );
const quint64 key( ( quint64( color.rgba() ) << 32 ) | size );
const quint64 key( ( colorKey(color) << 32 ) | size );
TileSet *tileSet = cache->object( key );
if ( !tileSet )
......@@ -1073,7 +1073,7 @@ namespace Oxygen
//______________________________________________________________________________
TileSet *StyleHelper::groove( const QColor& color, int size )
{
const quint64 key( ( quint64( color.rgba() ) << 32 ) | size );
const quint64 key( ( colorKey(color) << 32 ) | size );
TileSet *tileSet = _grooveCache.object( key );
if ( !tileSet )
......@@ -1110,7 +1110,7 @@ namespace Oxygen
//________________________________________________________________________________________________________
TileSet *StyleHelper::slitFocused( const QColor& glow )
{
const quint64 key( ( quint64( glow.rgba() ) << 32 ) );
const quint64 key( ( colorKey(glow) << 32 ) );
TileSet *tileSet = _slitCache.object( key );
if ( !tileSet )
......@@ -1143,7 +1143,7 @@ namespace Oxygen
//____________________________________________________________________
TileSet *StyleHelper::dockFrame( const QColor& top, const QColor& bottom )
{
const quint64 key( quint64( top.rgba() ) << 32 | quint64( bottom.rgba() ) );
const quint64 key( colorKey(top) << 32 | colorKey(bottom) );
TileSet *tileSet = _dockFrameCache.object( key );
if ( !tileSet )
{
......@@ -1201,7 +1201,7 @@ namespace Oxygen
TileSet *StyleHelper::selection( const QColor& color, int height, bool custom )
{
const quint64 key( ( quint64( color.rgba() ) << 32 ) | ( height << 1 ) | custom );
const quint64 key( ( colorKey(color) << 32 ) | ( height << 1 ) | custom );
TileSet *tileSet = _selectionCache.object( key );
if ( !tileSet )
{
......
......@@ -55,7 +55,7 @@ namespace Oxygen
Oxygen::Cache<QPixmap>::Value* cache( _windecoButtonCache.get( color ) );
const quint64 key( ( quint64( glow.rgba() ) << 32 ) | (sunken << 23 ) | size );
const quint64 key( ( colorKey(glow) << 32 ) | (sunken << 23 ) | size );
QPixmap *pixmap = cache->object( key );
if( !pixmap )
......@@ -151,7 +151,7 @@ namespace Oxygen
const QColor& DecoHelper::inactiveTitleBarTextColor( const QPalette& palette )
{
const quint32 key( palette.color(QPalette::Active, QPalette::Window).rgba() );
const quint32 key( colorKey( palette.color(QPalette::Active, QPalette::Window) ) );
QColor* out( _titleBarTextColorCache.object( key ) );
if( !out )
{
......@@ -173,7 +173,7 @@ namespace Oxygen
const QColor& DecoHelper::inactiveButtonTextColor( const QPalette& palette )
{
const quint32 key( palette.color(QPalette::Active, QPalette::Window).rgba() );
const quint32 key( colorKey( palette.color(QPalette::Active, QPalette::Window) ) );
QColor* out( _buttonTextColorCache.object( key ) );
if( !out )
{
......
......@@ -242,7 +242,7 @@ namespace Oxygen
void Helper::renderDot( QPainter* p, const QPoint& point, const QColor& baseColor )
{
const quint64 key( baseColor.rgba() );
const quint64 key( colorKey(baseColor) );
QPixmap* pixmap( _dotCache.object( key ) );
if( !pixmap )
......@@ -282,7 +282,7 @@ namespace Oxygen
//____________________________________________________________________
bool Helper::lowThreshold( const QColor& color )
{
const quint32 key( color.rgba() );
const quint32 key( colorKey(color) );
ColorMap::iterator iter( _lowThreshold.find( key ) );
if( iter != _lowThreshold.end() ) return iter.value();
else {
......@@ -299,7 +299,7 @@ namespace Oxygen
//____________________________________________________________________
bool Helper::highThreshold( const QColor& color )
{
const quint32 key( color.rgba() );
const quint32 key( colorKey(color) );
ColorMap::iterator iter( _highThreshold.find( key ) );
if( iter != _highThreshold.end() ) return iter.value();
else {
......@@ -323,7 +323,7 @@ namespace Oxygen
//____________________________________________________________________
const QColor& Helper::backgroundRadialColor( const QColor& color )
{
const quint64 key( color.rgba() );
const quint64 key( colorKey(color) );
QColor* out( _backgroundRadialColorCache.object( key ) );
if( !out )
{
......@@ -339,7 +339,7 @@ namespace Oxygen
//_________________________________________________________________________
const QColor& Helper::backgroundTopColor( const QColor& color )
{
const quint64 key( color.rgba() );
const quint64 key( colorKey(color) );
QColor* out( _backgroundTopColorCache.object( key ) );
if( !out )
{
......@@ -360,7 +360,7 @@ namespace Oxygen
//_________________________________________________________________________
const QColor& Helper::backgroundBottomColor( const QColor& color )
{
const quint64 key( color.rgba() );
const quint64 key( colorKey(color) );
QColor* out( _backgroundBottomColorCache.object( key ) );
if( !out )
{
......@@ -384,7 +384,7 @@ namespace Oxygen
//____________________________________________________________________
const QColor& Helper::calcLightColor( const QColor& color )
{
const quint64 key( color.rgba() );
const quint64 key( colorKey(color) );
QColor* out( _lightColorCache.object( key ) );
if( !out )
{
......@@ -399,7 +399,7 @@ namespace Oxygen
//____________________________________________________________________
const QColor& Helper::calcDarkColor( const QColor& color )
{
const quint64 key( color.rgba() );
const quint64 key( colorKey(color) );
QColor* out( _darkColorCache.object( key ) );
if( !out )
{
......@@ -416,7 +416,7 @@ namespace Oxygen
const QColor& Helper::calcShadowColor( const QColor& color )
{
const quint64 key( color.rgba() );
const quint64 key( colorKey(color) );
QColor* out( _shadowColorCache.object( key ) );
if( !out )
{
......@@ -442,7 +442,7 @@ namespace Oxygen
const QColor& Helper::backgroundColor( const QColor& color, qreal ratio )
{
const quint64 key( ( quint64( color.rgba() ) << 32 ) | int( ratio*512 ) );
const quint64 key( ( colorKey(color) << 32 ) | int( ratio*512 ) );
QColor *out( _backgroundColorCache.object( key ) );
if( !out )
{
......@@ -471,7 +471,7 @@ namespace Oxygen
//____________________________________________________________________
QPixmap Helper::verticalGradient( const QColor& color, int height, int offset )
{
const quint64 key( ( quint64( color.rgba() ) << 32 ) | height | 0x8000 );
const quint64 key( ( colorKey(color) << 32 ) | height | 0x8000 );
QPixmap* pixmap( _backgroundCache.object( key ) );
if ( !pixmap )
......@@ -499,7 +499,7 @@ namespace Oxygen
//____________________________________________________________________
QPixmap Helper::radialGradient( const QColor& color, int width, int height )
{
const quint64 key( ( quint64( color.rgba() ) << 32 ) | width | 0xb000 );
const quint64 key( ( colorKey(color) << 32 ) | width | 0xb000 );
QPixmap* pixmap( _backgroundCache.object( key ) );
if ( !pixmap )
......@@ -529,7 +529,7 @@ namespace Oxygen
//____________________________________________________________________________________
const QColor& Helper::decoColor( const QColor& background, const QColor& color )
{
const quint64 key( ( quint64( background.rgba() ) << 32 ) | color.rgba() );
const quint64 key( ( colorKey(background) << 32 ) | colorKey(color) );
QColor* out( _decoColorCache.object( key ) );
if( !out )
{
......@@ -730,7 +730,7 @@ namespace Oxygen
{
Oxygen::Cache<TileSet>::Value* cache( _slabCache.get( color ) );
const quint64 key( ( quint64( glow.rgba() ) << 32 ) | ( quint64( 256.0 * shade ) << 24 ) | size );
const quint64 key( ( colorKey(glow) << 32 ) | ( quint64( 256.0 * shade ) << 24 ) | size );
TileSet *tileSet = cache->object( key );
const qreal hScale( 1 );
......@@ -766,7 +766,7 @@ namespace Oxygen
//________________________________________________________________________________________________________
TileSet *Helper::slabSunken( const QColor& color, int size )
{
const quint64 key( quint64( color.rgba() ) << 32 | size );
const quint64 key( colorKey(color) << 32 | size );
TileSet *tileSet = _slabSunkenCache.object( key );
if ( !tileSet )
......
......@@ -116,7 +116,7 @@ namespace Oxygen
typedef BaseCache<T> Value;
Value* get( const QColor& color )
{
quint64 key = ( quint64( color.rgba() ) << 32 );
const quint64 key = ( color.isValid() ? color.rgba():0 );
Value* cache = data_.object( key );
if ( !cache )
......@@ -337,6 +337,10 @@ namespace Oxygen
protected:
//! return color key for a given color, properly accounting for invalid colors
quint64 colorKey( const QColor& color ) const
{ return color.isValid() ? color.rgba():0; }
//! generic slab painting (to be stored in tilesets)
virtual void drawSlab( QPainter&, const QColor&, qreal shade );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment