From 0de94dd1fe1f62df3547ca8e664489073807dd5e Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 8 Jan 2019 15:18:10 +1000 Subject: [PATCH] [layouts] Fix incorrectly rendered item background and frame when item is non-opaque Fixes #20909 --- src/core/layout/qgslayoutitem.cpp | 5 +++++ tests/src/core/testqgslayoutitem.cpp | 16 ++++++++++++++++ ...ted_composereffects_transparency_bgframe.png | Bin 0 -> 4288 bytes 3 files changed, 21 insertions(+) create mode 100644 tests/testdata/control_images/composer_effects/expected_composereffects_transparency_bgframe/expected_composereffects_transparency_bgframe.png diff --git a/src/core/layout/qgslayoutitem.cpp b/src/core/layout/qgslayoutitem.cpp index 704e7455b7e..b2fe2578b0a 100644 --- a/src/core/layout/qgslayoutitem.cpp +++ b/src/core/layout/qgslayoutitem.cpp @@ -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 ); diff --git a/tests/src/core/testqgslayoutitem.cpp b/tests/src/core/testqgslayoutitem.cpp index fdaf826d9dd..55cc9a0c3ca 100644 --- a/tests/src/core/testqgslayoutitem.cpp +++ b/tests/src/core/testqgslayoutitem.cpp @@ -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 ); diff --git a/tests/testdata/control_images/composer_effects/expected_composereffects_transparency_bgframe/expected_composereffects_transparency_bgframe.png b/tests/testdata/control_images/composer_effects/expected_composereffects_transparency_bgframe/expected_composereffects_transparency_bgframe.png new file mode 100644 index 0000000000000000000000000000000000000000..171e9e914ae5d53e9869c8c29e10488ebad0062b GIT binary patch literal 4288 zcmeAS@N?(olHy`uVBq!ia0y~yU`b+NV3y)w0*W}bm%jp1oCO|{#S9F5he4R}c>anM z1_ps5PZ!6KiaBp@8|t|vGPDLNa|yY*>gpU?r{k8dDRgnAPLfNrfY^tSF8yVWPrg5y zBYNkX_PeB6%XonX+U4}g0jUq$PpB|3G)(XWvK1!-2`4p128I?Npw%2RS%7vJaWXI{ zqzExEIE*SB4W7|NF?h1VM$;;W&!4~iD5&2qwU>$EnzfbP&FFXiag1kX`#d`R?tR$x z@ac=g84gtKKE2e3sm?>~W9;(u#o`PH)Xkp*ssD}nqq%yt&>Jo4M=Q9|`hT?5GuqZ0 zfEI4_Vs?Y*?c%`NnBl5oknE5n-df`T1;Hyc;68svkU;WeWT o^wDm~XlHD+uR2gY^hdI5Wt49pI+;}p>