QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 
35 {
36 
37  public:
38 
41  {
43  GaussianBlur
44  };
45 
51  static QgsPaintEffect *create( const QVariantMap &map ) SIP_FACTORY;
52 
56  QgsBlurEffect() = default;
57 
58  QString type() const override { return QStringLiteral( "blur" ); }
59  QVariantMap properties() const override;
60  void readProperties( const QVariantMap &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 
A paint effect which blurs a source picture, using a number of different blur methods.
Definition: qgsblureffect.h:35
QgsUnitTypes::RenderUnit blurUnit() const
Returns the units used for the blur level (radius).
void setBlurMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the blur strength (radius).
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
QgsBlurEffect()=default
Constructor for QgsBlurEffect.
BlurMethod
Available blur methods (algorithms)
Definition: qgsblureffect.h:41
@ StackBlur
Stack blur, a fast but low quality blur. Valid blur level values are between 0 - 16.
Definition: qgsblureffect.h:42
double opacity() const
Returns the opacity for the effect.
QString type() const override
Returns the effect type.
Definition: qgsblureffect.h:58
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
BlurMethod blurMethod() const
Returns the blur method (algorithm) used for performing the blur.
void setBlurUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the blur level (radius).
Definition: qgsblureffect.h:93
double blurLevel() const
Returns the blur level (radius)
Definition: qgsblureffect.h:83
void setBlurMethod(const BlurMethod method)
Sets the blur method (algorithm) to use for performing the blur.
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the blur strength (radius).
void setOpacity(const double opacity)
Sets the opacity for the effect.
Struct for storing maximum and minimum scales for measurements in map units.
Base class for visual effects which can be applied to QPicture drawings.
virtual void readProperties(const QVariantMap &props)=0
Reads a string map of an effect's properties and restores the effect to the state described by the pr...
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
virtual QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const
Returns the bounding rect required for drawing the effect.
virtual QVariantMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect's result on to the specified render context.
Contains information about the context of a rendering operation.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_NODEFAULTCTORS
Definition: qgis_sip.h:101