27using namespace Qt::StringLiterals;
60 QPainter *painter = context.
painter();
68 colorisedIm.invertPixels( QImage::InvertRgba );
82 colorisedIm = QImage( *imb );
89 const QPointF transPt( -offsetDist * std::cos( angleRad + M_PI_2 ),
90 -offsetDist * std::sin( angleRad + M_PI_2 ) );
98 QImage innerShadowIm( colorisedIm.width(), colorisedIm.height(), QImage::Format_ARGB32 );
99 innerShadowIm.fill( Qt::transparent );
100 QPainter imPainter( &innerShadowIm );
103 imPainter.drawImage( transPt.x(), transPt.y(), colorisedIm );
106 imPainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
110 painter->drawImage(
imageOffset( context ), innerShadowIm );
114 painter->drawImage(
imageOffset( context ) + transPt, colorisedIm );
121 props.insert( u
"enabled"_s,
mEnabled ?
"1" :
"0" );
122 props.insert( u
"draw_mode"_s, QString::number(
int(
mDrawMode ) ) );
123 props.insert( u
"blend_mode"_s, QString::number(
int(
mBlendMode ) ) );
124 props.insert( u
"opacity"_s, QString::number(
mOpacity ) );
125 props.insert( u
"blur_level"_s, QString::number(
mBlurLevel ) );
128 props.insert( u
"offset_angle"_s, QString::number(
mOffsetAngle ) );
129 props.insert( u
"offset_distance"_s, QString::number(
mOffsetDist ) );
139 const QPainter::CompositionMode mode =
static_cast< QPainter::CompositionMode
>( props.value( u
"blend_mode"_s ).toInt( &ok ) );
144 if ( props.contains( u
"transparency"_s ) )
146 const double transparency = props.value( u
"transparency"_s ).toDouble( &ok );
154 const double opacity = props.value( u
"opacity"_s ).toDouble( &ok );
160 mEnabled = props.value( u
"enabled"_s, u
"1"_s ).toInt();
162 const double level = props.value( u
"blur_level"_s ).toDouble( &ok );
166 if ( !props.contains( u
"blur_unit"_s ) )
174 const int angle = props.value( u
"offset_angle"_s ).toInt( &ok );
179 const double distance = props.value( u
"offset_distance"_s ).toDouble( &ok );
186 if ( props.contains( u
"color"_s ) )
202 return rect.adjusted( -spread, -spread, spread, spread );
225 return u
"dropShadow"_s;
258 return u
"innerShadow"_s;
@ 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.
@ ShadowOffset
Shadow offset.
QFlags< PaintEffectFlag > PaintEffectFlags
Flags which control how paint effects behave.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
static QgsPaintEffect * create(const QVariantMap &map)
Creates a new QgsDropShadowEffect effect from a properties string map.
QString type() const override
Returns the effect type.
QgsDropShadowEffect * clone() const override
Duplicates an effect by creating a deep copy of the effect.
bool exteriorShadow() const override
Specifies whether the shadow is drawn outside the picture or within the picture.
bool isCanceled() const
Tells whether the operation has been canceled already.
static void multiplyOpacity(QImage &image, double factor, QgsFeedback *feedback=nullptr)
Multiplies opacity of image pixel values by a factor.
static void overlayColor(QImage &image, const QColor &color)
Overlays a color onto an image.
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.
bool exteriorShadow() const override
Specifies whether the shadow is drawn outside the picture or within the picture.
QString type() const override
Returns the effect type.
static QgsPaintEffect * create(const QVariantMap &map)
Creates a new QgsInnerShadowEffect effect from a properties string map.
QgsInnerShadowEffect * clone() const override
Duplicates an effect by creating a deep copy of the effect.
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.
Scoped object for saving and restoring a QPainter object's state.
QVariantMap properties() const override
Returns the properties describing the paint effect encoded in a string format.
double opacity() const
Returns the opacity for the effect.
Qgis::RenderUnit mOffsetUnit
virtual bool exteriorShadow() const =0
Specifies whether the shadow is drawn outside the picture or within the picture.
void draw(QgsRenderContext &context) override
Handles drawing of the effect's result on to the specified render context.
QgsMapUnitScale mOffsetMapUnitScale
Qgis::RenderUnit mBlurUnit
QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const override
Returns the bounding rect required for drawing the effect.
double blurLevel() const
Returns the blur level (radius) for the shadow.
Qgis::PaintEffectFlags flags() const override
Returns flags which specify how the paint effect behaves.
QPainter::CompositionMode mBlendMode
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...
QgsMapUnitScale mBlurMapUnitScale
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.