34 switch ( mBlurMethod )
37 drawStackBlur( context );
40 drawGaussianBlur( context );
49 drawBlurredImage( context, im );
55 drawBlurredImage( context, *im );
59 void QgsBlurEffect::drawBlurredImage(
QgsRenderContext &context, QImage &image )
64 QPainter *painter = context.
painter();
66 painter->setCompositionMode( mBlendMode );
67 painter->drawImage(
imageOffset( context ), image );
74 props.insert( QStringLiteral(
"enabled" ),
mEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
75 props.insert( QStringLiteral(
"draw_mode" ), QString::number( static_cast< int >(
mDrawMode ) ) );
76 props.insert( QStringLiteral(
"blend_mode" ), QString::number( static_cast< int >( mBlendMode ) ) );
77 props.insert( QStringLiteral(
"opacity" ), QString::number( mOpacity ) );
78 props.insert( QStringLiteral(
"blur_level" ), QString::number( mBlurLevel ) );
79 props.insert( QStringLiteral(
"blur_method" ), QString::number( static_cast< int >( mBlurMethod ) ) );
86 QPainter::CompositionMode mode =
static_cast< QPainter::CompositionMode
>( props.value( QStringLiteral(
"blend_mode" ) ).toInt( &ok ) );
91 if ( props.contains( QStringLiteral(
"transparency" ) ) )
93 double transparency = props.value( QStringLiteral(
"transparency" ) ).toDouble( &ok );
96 mOpacity = 1.0 - transparency;
101 double opacity = props.value( QStringLiteral(
"opacity" ) ).toDouble( &ok );
108 mEnabled = props.value( QStringLiteral(
"enabled" ), QStringLiteral(
"1" ) ).toInt();
110 int level = props.value( QStringLiteral(
"blur_level" ) ).toInt( &ok );
118 mBlurMethod = method;
133 double spread = mBlurLevel * 2.0 + 10;
134 return rect.adjusted( -spread, -spread, spread, spread );
double opacity() const
Returns the opacity for the effect.
static void multiplyOpacity(QImage &image, double factor)
Multiplies opacity of image pixel values by a factor.
QgsStringMap properties() const override
Returns the properties describing the paint effect encoded in a string format.
QgsBlurEffect()=default
Constructor for QgsBlurEffect.
Base class for visual effects which can be applied to QPicture drawings.
Gaussian blur, a slower but high quality blur. Blur level values are the distance in pixels for the b...
QMap< QString, QString > QgsStringMap
QImage * sourceAsImage(QgsRenderContext &context)
Returns the source QPicture rendered to a new QImage.
Stack blur, a fast but low quality blur. Valid blur level values are between 0 - 16.
QPointF imageOffset(const QgsRenderContext &context) const
Returns the offset which should be used when drawing the source image on to a destination render cont...
BlurMethod
Available blur methods (algorithms)
bool enabled() const
Returns whether the effect is enabled.
A paint effect which blurs a source picture, using a number of different blur methods.
DrawMode
Drawing modes for effects.
static QImage * gaussianBlur(QImage &image, int radius)
Performs a gaussian blur on an image.
Contains information about the context of a rendering operation.
void draw(QgsRenderContext &context) override
Handles drawing of the effect's result on to the specified render context.
QPainter * painter()
Returns the destination QPainter for the render operation.
static void stackBlur(QImage &image, int radius, bool alphaOnly=false)
Performs a stack blur on an image.
static QgsPaintEffect * create(const QgsStringMap &map)
Creates a new QgsBlurEffect effect from a properties string map.
const QPicture * source() const
Returns the source QPicture.
void readProperties(const QgsStringMap &props) override
Reads a string map of an effect's properties and restores the effect to the state described by the pr...
QgsBlurEffect * clone() const override
Duplicates an effect by creating a deep copy of the effect.
QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const override
Returns the bounding rect required for drawing the effect.