QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgslayouteffect.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayouteffect.cpp
3  -------------------
4  begin : October 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include <QPainter>
19 
20 #include "qgslayouteffect.h"
21 
22 void QgsLayoutEffect::draw( QPainter *painter )
23 {
24  QPoint offset;
25  QPixmap pixmap;
26 
27  // Set desired composition mode then draw source
28  painter->setCompositionMode( mCompositionMode );
29 
30  if ( mCompositionMode == QPainter::CompositionMode_SourceOver )
31  {
32  // Normal (sourceover) blending, do faster drawSource operation
33  drawSource( painter );
34  return;
35  }
36 
37  // Otherwise, draw using pixmap so QPrinter output works as expected
38  if ( sourceIsPixmap() )
39  {
40  // No point in drawing in device coordinates (pixmap will be scaled anyways).
41  pixmap = sourcePixmap( Qt::LogicalCoordinates, &offset );
42  }
43  else
44  {
45  // Draw pixmap in device coordinates to avoid pixmap scaling;
46  pixmap = sourcePixmap( Qt::DeviceCoordinates, &offset );
47  painter->setWorldTransform( QTransform() );
48  }
49 
50  painter->drawPixmap( offset, pixmap );
51 }
52 
53 void QgsLayoutEffect::setCompositionMode( QPainter::CompositionMode compositionMode )
54 {
55  mCompositionMode = compositionMode;
56 
57  // force redraw with new composition mode
58  update();
59 }
60 
61 
62 
QgsLayoutEffect::setCompositionMode
void setCompositionMode(QPainter::CompositionMode mode)
Sets the composition (blending) mode used for rendering the item.
Definition: qgslayouteffect.cpp:53
qgslayouteffect.h
QgsLayoutEffect::draw
void draw(QPainter *painter) override
Definition: qgslayouteffect.cpp:22
QgsLayoutEffect::compositionMode
QPainter::CompositionMode compositionMode() const
Returns the composition (blending) mode used for rendering the item.
Definition: qgslayouteffect.h:58