QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
28 {
29 }
30 
31 void QgsComposerEffect::draw( QPainter *painter )
32 {
33  QPoint offset;
34  QPixmap pixmap;
35 
36  // Set desired composition mode then draw source
37  painter->setCompositionMode( mCompositionMode );
38 
39  if ( mCompositionMode == QPainter::CompositionMode_SourceOver )
40  {
41  // Normal (sourceover) blending, do faster drawSource operation
42  drawSource( painter );
43  return;
44  }
45 
46  // Otherwise, draw using pixmap so QPrinter output works as expected
47  if ( sourceIsPixmap() )
48  {
49  // No point in drawing in device coordinates (pixmap will be scaled anyways).
50  pixmap = sourcePixmap( Qt::LogicalCoordinates, &offset );
51  }
52  else
53  {
54  // Draw pixmap in device coordinates to avoid pixmap scaling;
55  pixmap = sourcePixmap( Qt::DeviceCoordinates, &offset );
56  painter->setWorldTransform( QTransform() );
57  }
58 
59  painter->drawPixmap( offset, pixmap );
60 
61 }
62 
63 void QgsComposerEffect::setCompositionMode( const QPainter::CompositionMode &compositionMode )
64 {
65  mCompositionMode = compositionMode;
66 
67  // force redraw with new composition mode
68  update();
69 }
70 
71 
72