QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
36 QPainter *painter = context.
painter();
44 colorisedIm.invertPixels( QImage::InvertRgba );
57 colorisedIm = QImage( *imb );
64 QPointF transPt( -offsetDist * std::cos( angleRad + M_PI_2 ),
65 -offsetDist * std::sin( angleRad + M_PI_2 ) );
73 QImage innerShadowIm( colorisedIm.width(), colorisedIm.height(), QImage::Format_ARGB32 );
74 innerShadowIm.fill( Qt::transparent );
75 QPainter imPainter( &innerShadowIm );
78 imPainter.drawImage( transPt.x(), transPt.y(), colorisedIm );
81 imPainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
85 painter->drawImage(
imageOffset( context ), innerShadowIm );
89 painter->drawImage(
imageOffset( context ) + transPt, colorisedIm );
96 props.insert( QStringLiteral(
"enabled" ),
mEnabled ?
"1" :
"0" );
97 props.insert( QStringLiteral(
"draw_mode" ), QString::number(
int(
mDrawMode ) ) );
98 props.insert( QStringLiteral(
"blend_mode" ), QString::number(
int(
mBlendMode ) ) );
99 props.insert( QStringLiteral(
"opacity" ), QString::number(
mOpacity ) );
100 props.insert( QStringLiteral(
"blur_level" ), QString::number(
mBlurLevel ) );
103 props.insert( QStringLiteral(
"offset_angle" ), QString::number(
mOffsetAngle ) );
104 props.insert( QStringLiteral(
"offset_distance" ), QString::number(
mOffsetDist ) );
114 QPainter::CompositionMode mode =
static_cast< QPainter::CompositionMode
>( props.value( QStringLiteral(
"blend_mode" ) ).toInt( &ok ) );
119 if ( props.contains( QStringLiteral(
"transparency" ) ) )
121 double transparency = props.value( QStringLiteral(
"transparency" ) ).toDouble( &ok );
129 double opacity = props.value( QStringLiteral(
"opacity" ) ).toDouble( &ok );
135 mEnabled = props.value( QStringLiteral(
"enabled" ), QStringLiteral(
"1" ) ).toInt();
137 double level = props.value( QStringLiteral(
"blur_level" ) ).toDouble( &ok );
141 if ( !props.contains( QStringLiteral(
"blur_unit" ) ) )
149 int angle = props.value( QStringLiteral(
"offset_angle" ) ).toInt( &ok );
154 double distance = props.value( QStringLiteral(
"offset_distance" ) ).toDouble( &ok );
161 if ( props.contains( QStringLiteral(
"color" ) ) )
174 return rect.adjusted( -spread, -spread, spread, spread );
197 return QStringLiteral(
"dropShadow" );
230 return QStringLiteral(
"innerShadow" );
DrawMode
Drawing modes for effects.
bool exteriorShadow() const override
Specifies whether the shadow is drawn outside the picture or within the picture.
static QString encodeColor(const QColor &color)
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
A paint effect which draws an offset and optionally blurred drop shadow within a picture.
QgsUnitTypes::RenderUnit mOffsetUnit
QString type() const override
Returns the effect type.
QgsStringMap properties() const override
Returns the properties describing the paint effect encoded in a string format.
static void multiplyOpacity(QImage &image, double factor)
Multiplies opacity of image pixel values by a factor.
QgsUnitTypes::RenderUnit mBlurUnit
Contains information about the context of a rendering operation.
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.
static QColor decodeColor(const QString &str)
QPainter::CompositionMode mBlendMode
double opacity() const
Returns the opacity for the effect.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
QgsDropShadowEffect * clone() const override
Duplicates an effect by creating a deep copy of the effect.
QgsMapUnitScale mOffsetMapUnitScale
A paint effect which draws an offset and optionally blurred drop shadow.
virtual bool exteriorShadow() const =0
Specifies whether the shadow is drawn outside the picture or within the picture.
Scoped object for saving and restoring a QPainter object's state.
double blurLevel() const
Returns the blur level (radius) for the shadow.
QPointF imageOffset(const QgsRenderContext &context) const
Returns the offset which should be used when drawing the source image on to a destination render cont...
QString type() const override
Returns the effect type.
QMap< QString, QString > QgsStringMap
static QImage * gaussianBlur(QImage &image, int radius)
Performs a gaussian blur on an image.
QImage * sourceAsImage(QgsRenderContext &context)
Returns the source QPicture rendered to a new QImage.
QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const override
Returns the bounding rect required for drawing the effect.
const QPicture * source() const
Returns the source QPicture.
Base class for visual effects which can be applied to QPicture drawings.
static void stackBlur(QImage &image, int radius, bool alphaOnly=false)
Performs a stack blur on an image.
QgsMapUnitScale mBlurMapUnitScale
bool exteriorShadow() const override
Specifies whether the shadow is drawn outside the picture or within the picture.
static QgsPaintEffect * create(const QgsStringMap &map)
Creates a new QgsDropShadowEffect effect from a properties string map.
QPainter * painter()
Returns the destination QPainter for the render operation.
bool enabled() const
Returns whether the effect is enabled.
void draw(QgsRenderContext &context) override
Handles drawing of the effect's result on to the specified render context.
static void overlayColor(QImage &image, const QColor &color)
Overlays a color onto an image.
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)
QgsInnerShadowEffect * clone() const override
Duplicates an effect by creating a deep copy of the effect.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
Base class for paint effects which offset, blurred shadows.