36 QPainter *painter = context.
painter();
44 colorisedIm.invertPixels( QImage::InvertRgba );
53 QPointF transPt( -offsetDist * std::cos( angleRad + M_PI_2 ),
54 -offsetDist * std::sin( angleRad + M_PI_2 ) );
62 QImage innerShadowIm( colorisedIm.width(), colorisedIm.height(), QImage::Format_ARGB32 );
63 innerShadowIm.fill( Qt::transparent );
64 QPainter imPainter( &innerShadowIm );
67 imPainter.drawImage( transPt.x(), transPt.y(), colorisedIm );
70 imPainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
74 painter->drawImage(
imageOffset( context ), innerShadowIm );
78 painter->drawImage(
imageOffset( context ) + transPt, colorisedIm );
86 props.insert( QStringLiteral(
"enabled" ),
mEnabled ?
"1" :
"0" );
87 props.insert( QStringLiteral(
"draw_mode" ), QString::number(
int(
mDrawMode ) ) );
88 props.insert( QStringLiteral(
"blend_mode" ), QString::number(
int(
mBlendMode ) ) );
89 props.insert( QStringLiteral(
"opacity" ), QString::number(
mOpacity ) );
90 props.insert( QStringLiteral(
"blur_level" ), QString::number(
mBlurLevel ) );
91 props.insert( QStringLiteral(
"offset_angle" ), QString::number(
mOffsetAngle ) );
92 props.insert( QStringLiteral(
"offset_distance" ), QString::number(
mOffsetDist ) );
102 QPainter::CompositionMode mode =
static_cast< QPainter::CompositionMode
>( props.value( QStringLiteral(
"blend_mode" ) ).toInt( &ok ) );
107 if ( props.contains( QStringLiteral(
"transparency" ) ) )
109 double transparency = props.value( QStringLiteral(
"transparency" ) ).toDouble( &ok );
117 double opacity = props.value( QStringLiteral(
"opacity" ) ).toDouble( &ok );
123 mEnabled = props.value( QStringLiteral(
"enabled" ), QStringLiteral(
"1" ) ).toInt();
125 int level = props.value( QStringLiteral(
"blur_level" ) ).toInt( &ok );
130 int angle = props.value( QStringLiteral(
"offset_angle" ) ).toInt( &ok );
135 double distance = props.value( QStringLiteral(
"offset_distance" ) ).toDouble( &ok );
142 if ( props.contains( QStringLiteral(
"color" ) ) )
154 return rect.adjusted( -spread, -spread, spread, spread );
177 return QStringLiteral(
"dropShadow" );
210 return QStringLiteral(
"innerShadow" );
static void overlayColor(QImage &image, const QColor &color)
Overlays a color onto an image.
static void multiplyOpacity(QImage &image, const double factor)
Multiplies opacity of image pixel values by a factor.
QString type() const override
Returns the effect type.
Base class for visual effects which can be applied to QPicture drawings.
QgsStringMap properties() const override
Returns the properties describing the paint effect encoded in a string format.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
QgsDropShadowEffect * clone() const override
Duplicates an effect by creating a deep copy of the effect.
QMap< QString, QString > QgsStringMap
virtual bool exteriorShadow() const =0
Specifies whether the shadow is drawn outside the picture or within the picture.
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)
QImage * sourceAsImage(QgsRenderContext &context)
Returns the source QPicture rendered to a new QImage.
static QString encodeColor(const QColor &color)
QPointF imageOffset(const QgsRenderContext &context) const
Returns the offset which should be used when drawing the source image on to a destination render cont...
QgsMapUnitScale mOffsetMapUnitScale
double opacity() const
Returns the opacity for the effect.
bool exteriorShadow() const override
Specifies whether the shadow is drawn outside the picture or within the picture.
QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const override
Returns the bounding rect required for drawing the effect.
QPainter::CompositionMode mBlendMode
bool enabled() const
Returns whether the effect is enabled.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
A paint effect which draws an offset and optionally blurred drop shadow.
void draw(QgsRenderContext &context) override
Handles drawing of the effect's result on to the specified render context.
bool exteriorShadow() const override
Specifies whether the shadow is drawn outside the picture or within the picture.
DrawMode
Drawing modes for effects.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
QgsInnerShadowEffect * clone() const override
Duplicates an effect by creating a deep copy of the effect.
QString type() const override
Returns the effect type.
A paint effect which draws an offset and optionally blurred drop shadow within a picture.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
static void stackBlur(QImage &image, const int radius, const bool alphaOnly=false)
Performs a stack blur on an image.
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...
static QgsPaintEffect * create(const QgsStringMap &map)
Creates a new QgsInnerShadowEffect effect from a properties string map.
Base class for paint effects which offset, blurred shadows.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
QgsUnitTypes::RenderUnit mOffsetUnit
const QPicture * source() const
Returns the source QPicture.
static QColor decodeColor(const QString &str)
static QgsPaintEffect * create(const QgsStringMap &map)
Creates a new QgsDropShadowEffect effect from a properties string map.