QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
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( QPainter::CompositionMode compositionMode )
64 {
65  mCompositionMode = compositionMode;
66 
67  // force redraw with new composition mode
68  update();
69 }
70 
71 
72 
void setCompositionMode(QPainter::CompositionMode compositionMode)
void setCompositionMode(CompositionMode mode)
virtual void draw(QPainter *painter) override
Called whenever source needs to be drawn.
QPixmap sourcePixmap(Qt::CoordinateSystem system, QPoint *offset, PixmapPadMode mode) const
void setWorldTransform(const QTransform &matrix, bool combine)
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
void drawSource(QPainter *painter)
bool sourceIsPixmap() const