QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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 "qgis.h"
24#include "qgsmapunitscale.h"
25
26#include <QPainter>
27
37{
38
39 public:
40
43 {
45 GaussianBlur
46 };
47
53 static QgsPaintEffect *create( const QVariantMap &map ) SIP_FACTORY;
54
58 QgsBlurEffect() = default;
59
60 QString type() const override { return QStringLiteral( "blur" ); }
61 QVariantMap properties() const override;
62 void readProperties( const QVariantMap &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 Qgis::RenderUnit unit ) { mBlurUnit = unit; }
96
105 Qgis::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
RenderUnit
Rendering size units.
Definition: qgis.h:4255
@ Millimeters
Millimeters.
A paint effect which blurs a source picture, using a number of different blur methods.
Definition: qgsblureffect.h:37
const QgsMapUnitScale & blurMapUnitScale() const
Returns the map unit scale used for the blur strength (radius).
void setBlurUnit(const Qgis::RenderUnit unit)
Sets the units used for the blur level (radius).
Definition: qgsblureffect.h:95
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.
Qgis::RenderUnit blurUnit() const
Returns the units used for the blur level (radius).
QgsBlurEffect()=default
Constructor for QgsBlurEffect.
BlurMethod
Available blur methods (algorithms)
Definition: qgsblureffect.h:43
@ StackBlur
Stack blur, a fast but low quality blur. Valid blur level values are between 0 - 16.
Definition: qgsblureffect.h:44
double opacity() const
Returns the opacity for the effect.
QString type() const override
Returns the effect type.
Definition: qgsblureffect.h:60
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.
double blurLevel() const
Returns the blur level (radius)
Definition: qgsblureffect.h:85
void setBlurMethod(const BlurMethod method)
Sets the blur method (algorithm) to use for performing the blur.
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.
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_NODEFAULTCTORS
Definition: qgis_sip.h:101