QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 "qgsunittypes.h"
24 #include "qgsmapunitscale.h"
25 
26 #include <QPainter>
27 
38 {
39 
40  public:
41 
44  {
46  GaussianBlur
47  };
48 
54  static QgsPaintEffect *create( const QVariantMap &map ) SIP_FACTORY;
55 
59  QgsBlurEffect() = default;
60 
61  QString type() const override { return QStringLiteral( "blur" ); }
62  QVariantMap properties() const override;
63  void readProperties( const QVariantMap &props ) override;
64  QgsBlurEffect *clone() const override SIP_FACTORY;
65 
75  void setBlurLevel( const double level ) { mBlurLevel = level; }
76 
86  double blurLevel() const { return mBlurLevel; }
87 
96  void setBlurUnit( const QgsUnitTypes::RenderUnit unit ) { mBlurUnit = unit; }
97 
106  QgsUnitTypes::RenderUnit blurUnit() const { return mBlurUnit; }
107 
116  void setBlurMapUnitScale( const QgsMapUnitScale &scale ) { mBlurMapUnitScale = scale; }
117 
126  const QgsMapUnitScale &blurMapUnitScale() const { return mBlurMapUnitScale; }
127 
133  void setBlurMethod( const BlurMethod method ) { mBlurMethod = method; }
134 
140  BlurMethod blurMethod() const { return mBlurMethod; }
141 
148  void setOpacity( const double opacity ) { mOpacity = opacity; }
149 
156  double opacity() const { return mOpacity; }
157 
164  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
165 
172  QPainter::CompositionMode blendMode() const { return mBlendMode; }
173 
174  protected:
175 
176  void draw( QgsRenderContext &context ) override;
177  QRectF boundingRect( const QRectF &rect, const QgsRenderContext &context ) const override;
178 
179  private:
180 
181  double mBlurLevel = 2.645;
183  QgsMapUnitScale mBlurMapUnitScale;
184  BlurMethod mBlurMethod = StackBlur;
185  double mOpacity = 1.0;
186  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
187 
188  void drawStackBlur( QgsRenderContext &context );
189  void drawGaussianBlur( QgsRenderContext &context );
190  void drawBlurredImage( QgsRenderContext &context, QImage &image );
191 };
192 
193 #endif // QGSBLUREFFECT_H
194 
A paint effect which blurs a source picture, using a number of different blur methods.
Definition: qgsblureffect.h:38
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:44
@ StackBlur
Stack blur, a fast but low quality blur. Valid blur level values are between 0 - 16.
Definition: qgsblureffect.h:45
double opacity() const
Returns the opacity for the effect.
QString type() const override
Returns the effect type.
Definition: qgsblureffect.h:61
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:96
double blurLevel() const
Returns the blur level (radius)
Definition: qgsblureffect.h:86
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:168
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_NODEFAULTCTORS
Definition: qgis_sip.h:101