QGIS API Documentation  2.99.0-Master (19b062c)
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 
22 void QgsComposerEffect::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 
54 void QgsComposerEffect::setCompositionMode( QPainter::CompositionMode compositionMode )
55 {
56  mCompositionMode = compositionMode;
57 
58  // force redraw with new composition mode
59  update();
60 }
61 
62 
63 
void setCompositionMode(QPainter::CompositionMode compositionMode)
virtual void draw(QPainter *painter) override
Called whenever source needs to be drawn.