60 std::unique_ptr< QgsGradientColorRamp > tempRamp;
68 QColor transparentColor =
mColor;
69 transparentColor.setAlpha( 0 );
71 ramp = tempRamp.get();
82 if ( blurLevel <= 16 )
99 p.setRenderHint( QPainter::Antialiasing );
100 p.setCompositionMode( QPainter::CompositionMode_DestinationIn );
105 QPainter *painter = context.
painter();
115 props.insert( QStringLiteral(
"enabled" ),
mEnabled ?
"1" :
"0" );
116 props.insert( QStringLiteral(
"draw_mode" ), QString::number(
int(
mDrawMode ) ) );
117 props.insert( QStringLiteral(
"blend_mode" ), QString::number(
int(
mBlendMode ) ) );
118 props.insert( QStringLiteral(
"opacity" ), QString::number(
mOpacity ) );
119 props.insert( QStringLiteral(
"blur_level" ), QString::number(
mBlurLevel ) );
122 props.insert( QStringLiteral(
"spread" ), QString::number(
mSpread ) );
125 props.insert( QStringLiteral(
"color_type" ), QString::number( static_cast< int >(
mColorType ) ) );
139 QPainter::CompositionMode mode =
static_cast< QPainter::CompositionMode
>( props.value( QStringLiteral(
"blend_mode" ) ).toInt( &ok ) );
144 if ( props.contains( QStringLiteral(
"transparency" ) ) )
146 double transparency = props.value( QStringLiteral(
"transparency" ) ).toDouble( &ok );
154 double opacity = props.value( QStringLiteral(
"opacity" ) ).toDouble( &ok );
160 mEnabled = props.value( QStringLiteral(
"enabled" ), QStringLiteral(
"1" ) ).toInt();
162 double level = props.value( QStringLiteral(
"blur_level" ) ).toDouble( &ok );
166 if ( !props.contains( QStringLiteral(
"blur_unit" ) ) )
174 double spread = props.value( QStringLiteral(
"spread" ) ).toDouble( &ok );
186 if ( props.contains( QStringLiteral(
"single_color" ) ) )
193 if ( props.contains( QStringLiteral(
"rampType" ) ) && props[QStringLiteral(
"rampType" )] == QStringLiteral(
"cpt-city" ) )
233 spread += blurLevel * 2 + 10;
234 return rect.adjusted( -spread, -spread, spread, spread );
static void multiplyOpacity(QImage &image, double factor)
Multiplies opacity of image pixel values by a factor.
double opacity() const
Returns the opacity for the effect.
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
Abstract base class for color ramps.
QPainter::CompositionMode mBlendMode
QgsGlowEffect & operator=(const QgsGlowEffect &rhs)
Base class for visual effects which can be applied to QPicture drawings.
void draw(QgsRenderContext &context) override
Handles drawing of the effect's result on to the specified render context.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QgsColorRamp * create(const QgsStringMap &properties=QgsStringMap())
QgsUnitTypes::RenderUnit mBlurUnit
QMap< QString, QString > QgsStringMap
virtual bool shadeExterior() const =0
Specifies whether the glow is drawn outside the picture or within the picture.
Base class for paint effect which draw a glow inside or outside a picture.
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...
~QgsGlowEffect() override
virtual QString type() const =0
Returns the effect type.
QgsUnitTypes::RenderUnit spreadUnit() const
Returns the units used for the glow spread distance.
static QgsPaintEffect * create(const QgsStringMap &map)
Creates a new QgsOuterGlowEffect effect from a properties string map.
const QgsMapUnitScale & spreadMapUnitScale() const
Returns the map unit scale used for the spread distance.
static void distanceTransform(QImage &image, const QgsImageOperation::DistanceTransformProperties &properties)
Performs a distance transform on the source image and shades the result using a color ramp...
bool enabled() const
Returns whether the effect is enabled.
GlowColorType
Color sources for the glow.
double blurLevel() const
Returns the blur level (radius) for the glow.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
GlowColorType colorType() const
Returns the color mode used for the glow.
A paint effect which draws a glow outside of a picture.
DrawMode
Drawing modes for effects.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
static QImage * gaussianBlur(QImage &image, int radius)
Performs a gaussian blur on an image.
QgsOuterGlowEffect * clone() const override
Duplicates an effect by creating a deep copy of the effect.
static QgsColorRamp * create(const QgsStringMap &properties=QgsStringMap())
Creates a new QgsColorRamp from a map of properties.
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.
Use colors from a color ramp.
double spread() const
Returns the spread distance used for drawing the glow effect.
QPainter::CompositionMode blendMode() const
Returns the blend mode for the effect.
QgsInnerGlowEffect * clone() const override
Duplicates an effect by creating a deep copy of the effect.
static void stackBlur(QImage &image, int radius, bool alphaOnly=false)
Performs a stack blur on an image.
QgsMapUnitScale mSpreadMapUnitScale
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...
virtual QgsStringMap properties() const =0
Returns a string map containing all the color ramp's properties.
QgsMapUnitScale mBlurMapUnitScale
QgsStringMap properties() const override
Returns the properties describing the paint effect encoded in a string format.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
void setRamp(QgsColorRamp *ramp)
Sets the color ramp for the glow.
QgsColorRamp * ramp() const
Returns the color ramp used for the glow.
const QPicture * source() const
Returns the source QPicture.
A paint effect which draws a glow within a picture.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
QRectF boundingRect(const QRectF &rect, const QgsRenderContext &context) const override
Returns the bounding rect required for drawing the effect.
static QgsPaintEffect * create(const QgsStringMap &map)
Creates a new QgsInnerGlowEffect effect from a properties string map.
static QColor decodeColor(const QString &str)
QgsUnitTypes::RenderUnit mSpreadUnit
QColor color() const
Returns the color for the glow.