QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 "qgsunittypes.h"
23 #include "qgsmapunitscale.h"
24 #include "qgis.h"
25 #include <QPainter>
26 
36 class CORE_EXPORT QgsBlurEffect : public QgsPaintEffect
37 {
38 
39  public:
40 
43  {
45  GaussianBlur
46  };
47 
53  static QgsPaintEffect *create( const QgsStringMap &map ) SIP_FACTORY;
54 
58  QgsBlurEffect() = default;
59 
60  QString type() const override { return QStringLiteral( "blur" ); }
61  QgsStringMap properties() const override;
62  void readProperties( const QgsStringMap &props ) override;
63  QgsBlurEffect *clone() const override SIP_FACTORY;
64 
74  void setBlurLevel( const double level ) { mBlurLevel = level; }
75 
85  double blurLevel() const { return mBlurLevel; }
86 
95  void setBlurUnit( const QgsUnitTypes::RenderUnit unit ) { mBlurUnit = unit; }
96 
105  QgsUnitTypes::RenderUnit blurUnit() const { return mBlurUnit; }
106 
115  void setBlurMapUnitScale( const QgsMapUnitScale &scale ) { mBlurMapUnitScale = scale; }
116 
125  const QgsMapUnitScale &blurMapUnitScale() const { return mBlurMapUnitScale; }
126 
132  void setBlurMethod( const BlurMethod method ) { mBlurMethod = method; }
133 
139  BlurMethod blurMethod() const { return mBlurMethod; }
140 
147  void setOpacity( const double opacity ) { mOpacity = opacity; }
148 
155  double opacity() const { return mOpacity; }
156 
163  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
164 
171  QPainter::CompositionMode blendMode() const { return mBlendMode; }
172 
173  protected:
174 
175  void draw( QgsRenderContext &context ) override;
176  QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const override;
177 
178  private:
179 
180  double mBlurLevel = 2.645;
182  QgsMapUnitScale mBlurMapUnitScale;
183  BlurMethod mBlurMethod = StackBlur;
184  double mOpacity = 1.0;
185  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
186 
187  void drawStackBlur( QgsRenderContext &context );
188  void drawGaussianBlur( QgsRenderContext &context );
189  void drawBlurredImage( QgsRenderContext &context, QImage &image );
190 };
191 
192 #endif // QGSBLUREFFECT_H
193 
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.
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.
void setBlurUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the blur level (radius).
Definition: qgsblureffect.h:95
virtual QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const
Returns the bounding rect required for drawing 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:60
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
void setBlurLevel(const double level)
Sets blur level (radius)
Definition: qgsblureffect.h:74
QMap< QString, QString > QgsStringMap
Definition: qgis.h:577
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:44
BlurMethod
Available blur methods (algorithms)
Definition: qgsblureffect.h:42
BlurMethod blurMethod() const
Returns the blur method (algorithm) used for performing the blur.
#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:36
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the blur strength (radius).
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...
QgsUnitTypes::RenderUnit blurUnit() const
Returns the units used for the blur level (radius).
Contains information about the context of a rendering operation.
Struct for storing maximum and minimum scales for measurements in map units.
void setBlurMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the blur strength (radius).
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect&#39;s result on to the specified render context.
double blurLevel() const
Returns the blur level (radius)
Definition: qgsblureffect.h:85
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:110