Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use rounded rectangles for preview icons in QgsColorButtonV2
  • Loading branch information
nyalldawson committed Aug 11, 2014
1 parent a30ddaa commit dd1fe45
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/gui/qgscolorbuttonv2.cpp
Expand Up @@ -528,30 +528,26 @@ void QgsColorButtonV2::setButtonBackground( const QColor color )
}
//create an icon pixmap
QPixmap pixmap( mIconSize );
pixmap.fill( Qt::transparent );

QRect rect( 0, 0, mIconSize.width(), mIconSize.height() );
QPainter p;
p.begin( &pixmap );
p.setRenderHint( QPainter::Antialiasing );
p.setPen( Qt::NoPen );
if ( useAlpha && backgroundColor.alpha() < 255 )
{
QRect rect( 0, 0, mIconSize.width(), mIconSize.height() );
QPainter p;
p.begin( &pixmap );

//start with checkboard pattern
QBrush checkBrush = QBrush( transparentBackground() );
p.setPen( Qt::NoPen );
p.setBrush( checkBrush );
p.drawRect( rect );

//draw semi-transparent color on top
p.setRenderHint( QPainter::Antialiasing );
p.setBrush( backgroundColor );
p.drawRect( rect );
p.end();
}
else
{
//no transparency, nice and easy
pixmap.fill( backgroundColor );
p.drawRoundedRect( rect, 3, 3 );
}

//draw semi-transparent color on top
p.setBrush( backgroundColor );
p.drawRoundedRect( rect, 3, 3 );
p.end();

setIconSize( mIconSize );
setIcon( pixmap );
}
Expand Down

0 comments on commit dd1fe45

Please sign in to comment.