Skip to content
Permalink
Browse files

[layouts] Fix incorrectly rendered item background and frame when ite…

…m is

non-opaque

Fixes #20909
  • Loading branch information
nyalldawson committed Jan 8, 2019
1 parent 4da0796 commit 0de94dd1fe1f62df3547ca8e664489073807dd5e
@@ -325,11 +325,16 @@ void QgsLayoutItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *it
// painter is already scaled to dots
// need to translate so that item origin is at 0,0 in painter coordinates (not bounding rect origin)
p.translate( -boundingRect().x() * context.scaleFactor(), -boundingRect().y() * context.scaleFactor() );
// scale to layout units for background and frame rendering
p.scale( context.scaleFactor(), context.scaleFactor() );
drawBackground( context );
p.scale( 1 / context.scaleFactor(), 1 / context.scaleFactor() );
double viewScale = QgsLayoutUtils::scaleFactorFromItemStyle( itemStyle );
QgsLayoutItemRenderContext itemRenderContext( context, viewScale );
draw( itemRenderContext );
p.scale( context.scaleFactor(), context.scaleFactor() );
drawFrame( context );
p.scale( 1 / context.scaleFactor(), 1 / context.scaleFactor() );
p.end();

QgsImageOperation::multiplyOpacity( image, mEvaluatedOpacity );
@@ -24,6 +24,7 @@
#include "qgsreadwritecontext.h"
#include "qgslayoutitemundocommand.h"
#include "qgslayoutitemmap.h"
#include "qgslayoutitemlabel.h"
#include "qgslayoutitemshape.h"
#include "qgslayouteffect.h"
#include "qgsfillsymbollayer.h"
@@ -1979,6 +1980,21 @@ void TestQgsLayoutItem::opacity()
checker.setControlPathPrefix( QStringLiteral( "composer_effects" ) );
QVERIFY( checker.testLayout( mReport ) );

// with background and frame
l.removeLayoutItem( item );

QgsLayoutItemLabel *labelItem = new QgsLayoutItemLabel( &l );
l.addLayoutItem( labelItem );
labelItem->attemptSetSceneRect( QRectF( 50, 50, 150, 100 ) );
labelItem->setBackgroundEnabled( true );
labelItem->setBackgroundColor( QColor( 40, 140, 240 ) );
labelItem->setFrameEnabled( true );
labelItem->setFrameStrokeColor( QColor( 40, 30, 20 ) );
labelItem->setItemOpacity( 0.5 );
checker = QgsLayoutChecker( QStringLiteral( "composereffects_transparency_bgframe" ), &l );
checker.setControlPathPrefix( QStringLiteral( "composer_effects" ) );
QVERIFY( checker.testLayout( mReport ) );

QgsLayout l2( QgsProject::instance() );
l2.initializeDefaults();
QgsLayoutItemShape *mComposerRect1 = new QgsLayoutItemShape( &l2 );
Binary file not shown.

0 comments on commit 0de94dd

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