Skip to content

Commit

Permalink
[layouts] Fix incorrectly rendered item background and frame when ite…
Browse files Browse the repository at this point in the history
…m is

non-opaque

Fixes #20909

(cherry picked from commit 0de94dd)
  • Loading branch information
nyalldawson committed Jan 11, 2019
1 parent 2dd2488 commit 680f2be
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/layout/qgslayoutitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
16 changes: 16 additions & 0 deletions tests/src/core/testqgslayoutitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 );
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 680f2be

Please sign in to comment.