QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsblureffect.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsblureffect.h
3  ---------------
4  begin : December 2014
5  copyright : (C) 2014 Nyall Dawson
6  email : nyall dot dawson at gmail dot com
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 #ifndef QGSBLUREFFECT_H
18 #define QGSBLUREFFECT_H
19 
20 #include "qgis_core.h"
21 #include "qgspainteffect.h"
22 #include "qgis.h"
23 #include <QPainter>
24 
34 class CORE_EXPORT QgsBlurEffect : public QgsPaintEffect
35 {
36 
37  public:
38 
41  {
43  GaussianBlur
44  };
45 
51  static QgsPaintEffect *create( const QgsStringMap &map ) SIP_FACTORY;
52 
56  QgsBlurEffect() = default;
57 
58  QString type() const override { return QStringLiteral( "blur" ); }
59  QgsStringMap properties() const override;
60  void readProperties( const QgsStringMap &props ) override;
61  QgsBlurEffect *clone() const override SIP_FACTORY;
62 
70  void setBlurLevel( const int level ) { mBlurLevel = level; }
71 
79  int blurLevel() const { return mBlurLevel; }
80 
86  void setBlurMethod( const BlurMethod method ) { mBlurMethod = method; }
87 
93  BlurMethod blurMethod() const { return mBlurMethod; }
94 
101  void setOpacity( const double opacity ) { mOpacity = opacity; }
102 
109  double opacity() const { return mOpacity; }
110 
117  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
118 
125  QPainter::CompositionMode blendMode() const { return mBlendMode; }
126 
127  protected:
128 
129  void draw( QgsRenderContext &context ) override;
130  QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const override;
131 
132  private:
133 
134  int mBlurLevel = 10;
135  BlurMethod mBlurMethod = StackBlur;
136  double mOpacity = 1.0;
137  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
138 
139  void drawStackBlur( QgsRenderContext &context );
140  void drawGaussianBlur( QgsRenderContext &context );
141  void drawBlurredImage( QgsRenderContext &context, QImage &image );
142 };
143 
144 #endif // QGSBLUREFFECT_H
145 
double opacity() const
Returns the opacity for the effect.
void setBlurMethod(const BlurMethod method)
Sets the blur method (algorithm) to use for performing the blur.
Definition: qgsblureffect.h:86
virtual QgsStringMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
void setOpacity(const double opacity)
Sets the opacity for the effect.
Base class for visual effects which can be applied to QPicture drawings.
QString type() const override
Returns the effect type.
Definition: qgsblureffect.h:58
void setBlurLevel(const int level)
Sets blur level (strength)
Definition: qgsblureffect.h:70
QMap< QString, QString > QgsStringMap
Definition: qgis.h:501
BlurMethod blurMethod() const
Returns the blur method (algorithm) used for performing the blur.
Definition: qgsblureffect.h:93
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
Stack blur, a fast but low quality blur. Valid blur level values are between 0 - 16.
Definition: qgsblureffect.h:42
BlurMethod
Available blur methods (algorithms)
Definition: qgsblureffect.h:40
int blurLevel() const
Returns the blur level (strength)
Definition: qgsblureffect.h:79
#define SIP_FACTORY
Definition: qgis_sip.h:69
A paint effect which blurs a source picture, using a number of different blur methods.
Definition: qgsblureffect.h:34
virtual void readProperties(const QgsStringMap &props)=0
Reads a string map of an effect&#39;s properties and restores the effect to the state described by the pr...
Contains information about the context of a rendering operation.
virtual QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const
Returns the bounding rect required for drawing the effect.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect&#39;s result on to the specified render context.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.