49 switch ( mBlurMethod )
52 drawStackBlur( context );
55 drawGaussianBlur( context );
66 drawBlurredImage( context, im );
76 drawBlurredImage( context, *im );
80void QgsBlurEffect::drawBlurredImage(
QgsRenderContext &context, QImage &image )
85 QPainter *painter = context.
painter();
86 const QgsScopedQPainterState painterState( painter );
87 painter->setCompositionMode( mBlendMode );
88 painter->drawImage(
imageOffset( context ), image );
94 props.insert( QStringLiteral(
"enabled" ),
mEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
95 props.insert( QStringLiteral(
"draw_mode" ), QString::number(
static_cast< int >(
mDrawMode ) ) );
96 props.insert( QStringLiteral(
"blend_mode" ), QString::number(
static_cast< int >( mBlendMode ) ) );
97 props.insert( QStringLiteral(
"opacity" ), QString::number( mOpacity ) );
98 props.insert( QStringLiteral(
"blur_level" ), QString::number( mBlurLevel ) );
101 props.insert( QStringLiteral(
"blur_method" ), QString::number(
static_cast< int >( mBlurMethod ) ) );
108 const QPainter::CompositionMode mode =
static_cast< QPainter::CompositionMode
>( props.value( QStringLiteral(
"blend_mode" ) ).toInt( &ok ) );
113 if ( props.contains( QStringLiteral(
"transparency" ) ) )
115 const double transparency = props.value( QStringLiteral(
"transparency" ) ).toDouble( &ok );
118 mOpacity = 1.0 - transparency;
123 const double opacity = props.value( QStringLiteral(
"opacity" ) ).toDouble( &ok );
130 mEnabled = props.value( QStringLiteral(
"enabled" ), QStringLiteral(
"1" ) ).toInt();
132 const double level = props.value( QStringLiteral(
"blur_level" ) ).toDouble( &ok );
136 if ( !props.contains( QStringLiteral(
"blur_unit" ) ) )
139 mBlurLevel *= 0.2645;
147 mBlurMethod = method;
162 const double spread =
blurLevel * 2.0 + 10;
163 return rect.adjusted( -spread, -spread, spread, spread );
@ ForceVector
Always force vector-based rendering, even when the result will be visually different to a raster-base...
@ RequiresRasterization
The effect requires raster-based rendering.
QFlags< PaintEffectFlag > PaintEffectFlags
Flags which control how paint effects behave.
QgsBlurEffect * clone() const override
Duplicates an effect by creating a deep copy of the effect.
QVariantMap properties() const override
Returns the properties describing the paint effect encoded in a string format.
void draw(QgsRenderContext &context) override
Handles drawing of the effect's result on to the specified render context.
QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const override
Returns the bounding rect required for drawing the effect.
static QgsPaintEffect * create(const QVariantMap &map)
Creates a new QgsBlurEffect effect from a properties string map.
void readProperties(const QVariantMap &props) override
Reads a string map of an effect's properties and restores the effect to the state described by the pr...
BlurMethod
Available blur methods (algorithms).
@ GaussianBlur
Gaussian blur, a slower but high quality blur. Blur level values are the distance in pixels for the b...
@ StackBlur
Stack blur, a fast but low quality blur. Valid blur level values are between 0 - 16.
Qgis::PaintEffectFlags flags() const override
Returns flags which specify how the paint effect behaves.
double opacity() const
Returns the opacity for the effect.
double blurLevel() const
Returns the blur level (radius).
static void multiplyOpacity(QImage &image, double factor, QgsFeedback *feedback=nullptr)
Multiplies opacity of image pixel values by a factor.
static QImage * gaussianBlur(QImage &image, int radius, QgsFeedback *feedback=nullptr)
Performs a gaussian blur on an image.
static void stackBlur(QImage &image, int radius, bool alphaOnly=false, QgsFeedback *feedback=nullptr)
Performs a stack blur on an image.
void drawSource(QPainter &painter)
Draws the source QPicture onto the specified painter.
QImage sourceAsImage(QgsRenderContext &context)
Returns the source QPicture rendered to a new QImage.
const QPicture & source() const
Returns the source QPicture.
QPointF imageOffset(const QgsRenderContext &context) const
Returns the offset which should be used when drawing the source image on to a destination render cont...
bool enabled() const
Returns whether the effect is enabled.
DrawMode
Drawing modes for effects.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsFeedback * feedback() const
Returns the feedback object that can be queried regularly during rendering to check if rendering shou...
Qgis::RasterizedRenderingPolicy rasterizedRenderingPolicy() const
Returns the policy controlling when rasterisation of content during renders is permitted.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.