QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 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 
QgsBlurEffect::blendMode
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
Definition: qgsblureffect.h:169
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:166
QgsBlurEffect
A paint effect which blurs a source picture, using a number of different blur methods.
Definition: qgsblureffect.h:34
QgsBlurEffect::setBlendMode
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
Definition: qgsblureffect.h:161
QgsBlurEffect::setBlurUnit
void setBlurUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the blur level (radius).
Definition: qgsblureffect.h:93
QgsPaintEffect::properties
virtual QgsStringMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
qgspainteffect.h
QgsBlurEffect::type
QString type() const override
Returns the effect type.
Definition: qgsblureffect.h:58
QgsBlurEffect::setOpacity
void setOpacity(const double opacity)
Sets the opacity for the effect.
Definition: qgsblureffect.h:145
QgsBlurEffect::BlurMethod
BlurMethod
Available blur methods (algorithms)
Definition: qgsblureffect.h:40
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsBlurEffect::StackBlur
@ StackBlur
Stack blur, a fast but low quality blur. Valid blur level values are between 0 - 16.
Definition: qgsblureffect.h:42
QgsPaintEffect::clone
virtual QgsPaintEffect * clone() const =0
Duplicates an effect by creating a deep copy of the effect.
qgis_sip.h
QgsPaintEffect::readProperties
virtual void readProperties(const QgsStringMap &props)=0
Reads a string map of an effect's properties and restores the effect to the state described by the pr...
QgsPaintEffect::boundingRect
virtual QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const
Returns the bounding rect required for drawing the effect.
Definition: qgspainteffect.cpp:203
QgsMapUnitScale
Struct for storing maximum and minimum scales for measurements in map units.
Definition: qgsmapunitscale.h:37
QgsBlurEffect::blurLevel
double blurLevel() const
Returns the blur level (radius)
Definition: qgsblureffect.h:83
SIP_NODEFAULTCTORS
#define SIP_NODEFAULTCTORS
Definition: qgis_sip.h:101
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:714
QgsBlurEffect::blurMapUnitScale
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the blur strength (radius).
Definition: qgsblureffect.h:123
QgsBlurEffect::blurMethod
BlurMethod blurMethod() const
Returns the blur method (algorithm) used for performing the blur.
Definition: qgsblureffect.h:137
QgsPaintEffect
Base class for visual effects which can be applied to QPicture drawings.
Definition: qgspainteffect.h:53
QgsBlurEffect::opacity
double opacity() const
Returns the opacity for the effect.
Definition: qgsblureffect.h:153
QgsBlurEffect::setBlurMapUnitScale
void setBlurMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the blur strength (radius).
Definition: qgsblureffect.h:113
QgsBlurEffect::blurUnit
QgsUnitTypes::RenderUnit blurUnit() const
Returns the units used for the blur level (radius).
Definition: qgsblureffect.h:103
QgsPaintEffect::draw
virtual void draw(QgsRenderContext &context)=0
Handles drawing of the effect's result on to the specified render context.
QgsBlurEffect::setBlurMethod
void setBlurMethod(const BlurMethod method)
Sets the blur method (algorithm) to use for performing the blur.
Definition: qgsblureffect.h:130