QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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_sip.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 
72  void setBlurLevel( const double level ) { mBlurLevel = level; }
73 
83  double blurLevel() const { return mBlurLevel; }
84 
93  void setBlurUnit( const QgsUnitTypes::RenderUnit unit ) { mBlurUnit = unit; }
94 
103  QgsUnitTypes::RenderUnit blurUnit() const { return mBlurUnit; }
104 
113  void setBlurMapUnitScale( const QgsMapUnitScale &scale ) { mBlurMapUnitScale = scale; }
114 
123  const QgsMapUnitScale &blurMapUnitScale() const { return mBlurMapUnitScale; }
124 
130  void setBlurMethod( const BlurMethod method ) { mBlurMethod = method; }
131 
137  BlurMethod blurMethod() const { return mBlurMethod; }
138 
145  void setOpacity( const double opacity ) { mOpacity = opacity; }
146 
153  double opacity() const { return mOpacity; }
154 
161  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
162 
169  QPainter::CompositionMode blendMode() const { return mBlendMode; }
170 
171  protected:
172 
173  void draw( QgsRenderContext &context ) override;
174  QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const override;
175 
176  private:
177 
178  double mBlurLevel = 2.645;
180  QgsMapUnitScale mBlurMapUnitScale;
181  BlurMethod mBlurMethod = StackBlur;
182  double mOpacity = 1.0;
183  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
184 
185  void drawStackBlur( QgsRenderContext &context );
186  void drawGaussianBlur( QgsRenderContext &context );
187  void drawBlurredImage( QgsRenderContext &context, QImage &image );
188 };
189 
190 #endif // QGSBLUREFFECT_H
191 
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:93
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the blur strength (radius).
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 double level)
Sets blur level (radius)
Definition: qgsblureffect.h:72
QgsUnitTypes::RenderUnit blurUnit() const
Returns the units used for the blur level (radius).
QMap< QString, QString > QgsStringMap
Definition: qgis.h:587
BlurMethod blurMethod() const
Returns the blur method (algorithm) used for performing the blur.
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
#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.
Struct for storing maximum and minimum scales for measurements in map units.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
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.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
double blurLevel() const
Returns the blur level (radius)
Definition: qgsblureffect.h:83
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:111