QGIS API Documentation  2.99.0-Master (d55fa22)
qgscomposereffect.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposereffect.cpp
3  -------------------
4  begin : March 2013
5  copyright : (C) 2013 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 "qgscomposereffect.h"
21 
23  : mCompositionMode( QPainter::CompositionMode_SourceOver )
24 {
25 }
26 
27 void QgsComposerEffect::draw( QPainter *painter )
28 {
29  QPoint offset;
30  QPixmap pixmap;
31 
32  // Set desired composition mode then draw source
33  painter->setCompositionMode( mCompositionMode );
34 
35  if ( mCompositionMode == QPainter::CompositionMode_SourceOver )
36  {
37  // Normal (sourceover) blending, do faster drawSource operation
38  drawSource( painter );
39  return;
40  }
41 
42  // Otherwise, draw using pixmap so QPrinter output works as expected
43  if ( sourceIsPixmap() )
44  {
45  // No point in drawing in device coordinates (pixmap will be scaled anyways).
46  pixmap = sourcePixmap( Qt::LogicalCoordinates, &offset );
47  }
48  else
49  {
50  // Draw pixmap in device coordinates to avoid pixmap scaling;
51  pixmap = sourcePixmap( Qt::DeviceCoordinates, &offset );
52  painter->setWorldTransform( QTransform() );
53  }
54 
55  painter->drawPixmap( offset, pixmap );
56 
57 }
58 
59 void QgsComposerEffect::setCompositionMode( QPainter::CompositionMode compositionMode )
60 {
61  mCompositionMode = compositionMode;
62 
63  // force redraw with new composition mode
64  update();
65 }
66 
67 
68 
void setCompositionMode(QPainter::CompositionMode compositionMode)
virtual void draw(QPainter *painter) override
Called whenever source needs to be drawn.