Skip to content
Permalink
Browse files

Show checkboard pattern behind semi-transparent colors in swatch grid

  • Loading branch information
nyalldawson committed Aug 14, 2014
1 parent 8a2f150 commit 09547894b2d2dce29165dc0987a00da6eb62bce0
Showing with 29 additions and 0 deletions.
  1. +24 −0 src/gui/qgscolorswatchgrid.cpp
  2. +5 −0 src/gui/qgscolorswatchgrid.h
@@ -279,7 +279,21 @@ void QgsColorSwatchGrid::draw( QPainter &painter )

if ( mCurrentHoverBox == index )
{
//hovered boxes are slightly larger
swatchRect.adjust( -1, -1, 1, 1 );
}

//start with checkboard pattern for semi-transparent colors
if (( *colorIt ).first.alpha() != 255 )
{
QBrush checkBrush = QBrush( transparentBackground() );
painter.setPen( Qt::NoPen );
painter.setBrush( checkBrush );
painter.drawRect( swatchRect );
}

if ( mCurrentHoverBox == index )
{
if ( mDrawBoxDepressed )
{
painter.setPen( QColor( 100, 100, 100 ) );
@@ -306,6 +320,16 @@ void QgsColorSwatchGrid::draw( QPainter &painter )
}
}

const QPixmap& QgsColorSwatchGrid::transparentBackground()
{
static QPixmap transpBkgrd;

if ( transpBkgrd.isNull() )
transpBkgrd = QgsApplication::getThemePixmap( "/transp-background_8x8.png" );

return transpBkgrd;
}

int QgsColorSwatchGrid::swatchForPosition( const QPoint &position ) const
{
//calculate box for position
@@ -140,6 +140,11 @@ class GUI_EXPORT QgsColorSwatchGrid: public QWidget
* @param colorIdx color index to use for calculating tooltip
*/
void updateTooltip( const int colorIdx );

/**Generates a checkboard pattern for transparent color backgrounds
* @returns checkboard pixmap
*/
const QPixmap &transparentBackground();
};


0 comments on commit 0954789

Please sign in to comment.
You can’t perform that action at this time.