QGIS API Documentation 3.37.0-Master (fa0c88a90b0)
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
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
22void 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
53void QgsLayoutEffect::setCompositionMode( QPainter::CompositionMode compositionMode )
54{
55 mCompositionMode = compositionMode;
56
57 // force redraw with new composition mode
58 update();
59}
60
61
62
Q_DECL_DEPRECATED QPainter::CompositionMode compositionMode() const
Returns the composition (blending) mode used for rendering the item.
void draw(QPainter *painter) override
Q_DECL_DEPRECATED void setCompositionMode(QPainter::CompositionMode mode)
Sets the composition (blending) mode used for rendering the item.