Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port item blend mode support to layouts
- Loading branch information
1 parent
0143d0b
commit 4e8878d
Showing
9 changed files
with
255 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/*************************************************************************** | ||
qgslayouteffect.cpp | ||
------------------- | ||
begin : October 2017 | ||
copyright : (C) 2017 by Nyall Dawson | ||
email : nyall.dawson@gmail.com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include <QPainter> | ||
|
||
#include "qgslayouteffect.h" | ||
|
||
void QgsLayoutEffect::draw( QPainter *painter ) | ||
{ | ||
QPoint offset; | ||
QPixmap pixmap; | ||
|
||
// Set desired composition mode then draw source | ||
painter->setCompositionMode( mCompositionMode ); | ||
|
||
if ( mCompositionMode == QPainter::CompositionMode_SourceOver ) | ||
{ | ||
// Normal (sourceover) blending, do faster drawSource operation | ||
drawSource( painter ); | ||
return; | ||
} | ||
|
||
// Otherwise, draw using pixmap so QPrinter output works as expected | ||
if ( sourceIsPixmap() ) | ||
{ | ||
// No point in drawing in device coordinates (pixmap will be scaled anyways). | ||
pixmap = sourcePixmap( Qt::LogicalCoordinates, &offset ); | ||
} | ||
else | ||
{ | ||
// Draw pixmap in device coordinates to avoid pixmap scaling; | ||
pixmap = sourcePixmap( Qt::DeviceCoordinates, &offset ); | ||
painter->setWorldTransform( QTransform() ); | ||
} | ||
|
||
painter->drawPixmap( offset, pixmap ); | ||
} | ||
|
||
void QgsLayoutEffect::setCompositionMode( QPainter::CompositionMode compositionMode ) | ||
{ | ||
mCompositionMode = compositionMode; | ||
|
||
// force redraw with new composition mode | ||
update(); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*************************************************************************** | ||
qgslayouteffect.h | ||
------------------- | ||
begin : October 2017 | ||
copyright : (C) 2017 by Nyall Dawson | ||
email : nyall.dawson@gmail.com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSLAYOUTEFFECT_H | ||
#define QGSLAYOUTEFFECT_H | ||
|
||
#include <QGraphicsEffect> | ||
#include <QPainter> | ||
|
||
#include "qgis_core.h" | ||
|
||
/** | ||
* \ingroup core | ||
* \class QgsLayoutEffect | ||
* | ||
* A QGraphicsEffect subclass used for rendering layout items | ||
* onto a scene with custom composition modes. | ||
* | ||
* \since QGIS 3.0 | ||
*/ | ||
class CORE_EXPORT QgsLayoutEffect : public QGraphicsEffect | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** | ||
* Constructor for QgsLayoutEffect. | ||
*/ | ||
QgsLayoutEffect() = default; | ||
|
||
/** | ||
* Sets the composition (blending) \a mode used for rendering | ||
* the item. | ||
* \see compositionMode() | ||
*/ | ||
void setCompositionMode( QPainter::CompositionMode mode ); | ||
|
||
/** | ||
* Returns the composition (blending) mode used for rendering | ||
* the item. | ||
* \see setCompositionMode() | ||
*/ | ||
QPainter::CompositionMode compositionMode() const { return mCompositionMode; } | ||
|
||
protected: | ||
|
||
virtual void draw( QPainter *painter ) override; | ||
|
||
private: | ||
|
||
QPainter::CompositionMode mCompositionMode = QPainter::CompositionMode_SourceOver; | ||
}; | ||
|
||
#endif // QGSLAYOUTEFFECT_H | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.