42 QPainter *painter = context.
painter();
50 colorisedIm.invertPixels( QImage::InvertRgba );
64 colorisedIm = QImage( *imb );
71 const QPointF transPt( -offsetDist * std::cos( angleRad + M_PI_2 ),
72 -offsetDist * std::sin( angleRad + M_PI_2 ) );
80 QImage innerShadowIm( colorisedIm.width(), colorisedIm.height(), QImage::Format_ARGB32 );
81 innerShadowIm.fill( Qt::transparent );
82 QPainter imPainter( &innerShadowIm );
85 imPainter.drawImage( transPt.x(), transPt.y(), colorisedIm );
88 imPainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
92 painter->drawImage(
imageOffset( context ), innerShadowIm );
96 painter->drawImage(
imageOffset( context ) + transPt, colorisedIm );
103 props.insert( QStringLiteral(
"enabled" ),
mEnabled ?
"1" :
"0" );
104 props.insert( QStringLiteral(
"draw_mode" ), QString::number(
int(
mDrawMode ) ) );
105 props.insert( QStringLiteral(
"blend_mode" ), QString::number(
int(
mBlendMode ) ) );
106 props.insert( QStringLiteral(
"opacity" ), QString::number(
mOpacity ) );
107 props.insert( QStringLiteral(
"blur_level" ), QString::number(
mBlurLevel ) );
110 props.insert( QStringLiteral(
"offset_angle" ), QString::number(
mOffsetAngle ) );
111 props.insert( QStringLiteral(
"offset_distance" ), QString::number(
mOffsetDist ) );
121 const QPainter::CompositionMode mode =
static_cast< QPainter::CompositionMode
>( props.value( QStringLiteral(
"blend_mode" ) ).toInt( &ok ) );
126 if ( props.contains( QStringLiteral(
"transparency" ) ) )
128 const double transparency = props.value( QStringLiteral(
"transparency" ) ).toDouble( &ok );
136 const double opacity = props.value( QStringLiteral(
"opacity" ) ).toDouble( &ok );
142 mEnabled = props.value( QStringLiteral(
"enabled" ), QStringLiteral(
"1" ) ).toInt();
144 const double level = props.value( QStringLiteral(
"blur_level" ) ).toDouble( &ok );
148 if ( !props.contains( QStringLiteral(
"blur_unit" ) ) )
156 const int angle = props.value( QStringLiteral(
"offset_angle" ) ).toInt( &ok );
161 const double distance = props.value( QStringLiteral(
"offset_distance" ) ).toDouble( &ok );
168 if ( props.contains( QStringLiteral(
"color" ) ) )
184 return rect.adjusted( -spread, -spread, spread, spread );
207 return QStringLiteral(
"dropShadow" );
240 return QStringLiteral(
"innerShadow" );
@ ShadowOffset
Shadow offset.
A paint effect which draws an offset and optionally blurred drop shadow.
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 SIP_HOLDGIL
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.
A paint effect which draws an offset and optionally blurred drop shadow within a picture.
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.
Base class for visual effects which can be applied to QPicture drawings.
QPointF imageOffset(const QgsRenderContext &context) const
Returns the offset which should be used when drawing the source image on to a destination render cont...
const QPicture * source() const
Returns the source QPicture.
bool enabled() const
Returns whether the effect is enabled.
DrawMode
Drawing modes for effects.
QImage * sourceAsImage(QgsRenderContext &context)
Returns the source QPicture rendered to a new QImage.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QgsFeedback * feedback() const
Returns the feedback object that can be queried regularly during rendering to check if rendering shou...
Scoped object for saving and restoring a QPainter object's state.
Base class for paint effects which offset, blurred shadows.
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.
QgsUnitTypes::RenderUnit mOffsetUnit
QgsUnitTypes::RenderUnit mBlurUnit
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
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.
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 QColor decodeColor(const QString &str)
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static QString encodeColor(const QColor &color)
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)