Skip to content

Commit

Permalink
Show checkboard pattern behind semi-transparent colors in swatch grid
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 14, 2014
1 parent 8a2f150 commit 0954789
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/gui/qgscolorswatchgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgscolorswatchgrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};


Expand Down

0 comments on commit 0954789

Please sign in to comment.