Skip to content

Commit

Permalink
Eye candy overload: Make background rectangle on text format preview
Browse files Browse the repository at this point in the history
icons a very subtle gradient, make outline a variant of the actual
background color instead of always a grey.

 Please enter the commit message for your changes. Lines starting
  • Loading branch information
nyalldawson committed Jun 21, 2019
1 parent 823d630 commit 8100966
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
27 changes: 23 additions & 4 deletions src/core/qgstextrenderer.cpp
Expand Up @@ -1729,15 +1729,22 @@ QPixmap QgsTextFormat::textFormatPreviewPixmap( const QgsTextFormat &format, QSi

QRect rect( 0, 0, size.width(), size.height() );

if ( ( tempFormat.previewBackgroundColor().lightnessF() < 0.7 ) )
// shameless eye candy - use a subtle gradient when drawing background
painter.setPen( Qt::NoPen );
QColor background1 = tempFormat.previewBackgroundColor();
if ( ( background1.lightnessF() < 0.7 ) )
{
painter.setPen( QPen( QColor( 150, 150, 150 ), 0 ) );
background1 = background1.darker( 125 );
}
else
{
painter.setPen( QPen( QColor( 100, 100, 100 ), 0 ) );
background1 = background1.lighter( 125 );
}
painter.setBrush( tempFormat.previewBackgroundColor() );
QColor background2 = tempFormat.previewBackgroundColor();
QLinearGradient linearGrad( QPointF( 0, 0 ), QPointF( 0, rect.height() ) );
linearGrad.setColorAt( 0, background1 );
linearGrad.setColorAt( 1, background2 );
painter.setBrush( QBrush( linearGrad ) );
if ( size.width() > 30 )
{
painter.drawRoundedRect( rect, 6, 6 );
Expand Down Expand Up @@ -1788,6 +1795,18 @@ QPixmap QgsTextFormat::textFormatPreviewPixmap( const QgsTextFormat &format, QSi

QgsTextRenderer::drawText( textRect, 0, QgsTextRenderer::AlignCenter, text, context, tempFormat );

// draw border on top of text
painter.setBrush( Qt::NoBrush );
painter.setPen( QPen( tempFormat.previewBackgroundColor().darker( 150 ), 0 ) );
if ( size.width() > 30 )
{
painter.drawRoundedRect( rect, 6, 6 );
}
else
{
// don't use rounded rect for small previews
painter.drawRect( rect );
}
painter.end();
return pixmap;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgstextrenderer_p.h
Expand Up @@ -238,7 +238,7 @@ class QgsTextSettingsPrivate : public QSharedData
double opacity = 1.0;
QPainter::CompositionMode blendMode = QPainter::CompositionMode_SourceOver;
double multilineHeight = 1.0 ; //0.0 to 10.0, leading between lines as multiplyer of line height
QColor previewBackgroundColor;
QColor previewBackgroundColor = Qt::white;

};

Expand Down

0 comments on commit 8100966

Please sign in to comment.