QgsColorEffect class

A paint effect which alters the colors (e.g., brightness, contrast) in a source picture.

Base classes

class QgsPaintEffect
Base class for visual effects which can be applied to QPicture drawings.

Public static functions

static auto create(const QgsStringMap& map) -> QgsPaintEffect*
Creates a new QgsColorEffect effect from a properties string map.

Public functions

auto blendMode() const -> QPainter::CompositionMode
Returns the blend mode for the effect.
auto brightness() const -> int
Returns the brightness modification for the effect.
auto clone() const -> QgsColorEffect* override
Duplicates an effect by creating a deep copy of the effect.
auto colorizeColor() const -> QColor
Returns the color used for colorizing a picture.
auto colorizeOn() const -> bool
Returns whether the effect will colorize a picture.
auto colorizeStrength() const -> int
Returns the strength used for colorizing a picture.
auto contrast() const -> int
Returns the contrast modification for the effect.
auto grayscaleMode() const -> QgsImageOperation::GrayscaleMode
Returns whether the effect will convert a picture to grayscale.
auto opacity() const -> double
Returns the opacity for the effect.
auto properties() const -> QgsStringMap override
Returns the properties describing the paint effect encoded in a string format.
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 properties map.
auto saturation() const -> double
Returns the saturation modification for the effect.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
void setBrightness(int brightness)
Sets the brightness modification for the effect.
void setColorizeColor(const QColor& colorizeColor)
Sets the color used for colorizing a picture.
void setColorizeOn(bool colorizeOn)
Sets whether the effect should colorize a picture.
void setColorizeStrength(int colorizeStrength)
Sets the strength for colorizing a picture.
void setContrast(int contrast)
Sets the contrast modification for the effect.
void setGrayscaleMode(QgsImageOperation::GrayscaleMode grayscaleMode)
Sets whether the effect should convert a picture to grayscale.
void setOpacity(const double opacity)
Sets the opacity for the effect.
void setSaturation(double saturation)
Sets the saturation modification for the effect.
auto type() const -> QString override
Returns the effect type.

Protected functions

void draw(QgsRenderContext& context) override
Handles drawing of the effect's result on to the specified render context.

Function documentation

static QgsPaintEffect* QgsColorEffect::create(const QgsStringMap& map)

Creates a new QgsColorEffect effect from a properties string map.

Parameters
map encoded properties string map
Returns new QgsColorEffect

QPainter::CompositionMode QgsColorEffect::blendMode() const

Returns the blend mode for the effect.

Returns blend mode used for drawing the effect on to a destination paint device

int QgsColorEffect::brightness() const

Returns the brightness modification for the effect.

Returns brightness value. Values are between -255 and 255, where 0 represents no change, negative values indicate darkening and positive values indicate lightening

QgsColorEffect* QgsColorEffect::clone() const override

Duplicates an effect by creating a deep copy of the effect.

Returns clone of paint effect

QColor QgsColorEffect::colorizeColor() const

Returns the color used for colorizing a picture.

Returns colorization color

This is only used if colorizeOn() is set to true.

bool QgsColorEffect::colorizeOn() const

Returns whether the effect will colorize a picture.

Returns true if colorization is enableds

int QgsColorEffect::colorizeStrength() const

Returns the strength used for colorizing a picture.

Returns colorization strength, between 0 and 100

This is only used if setColorizeOn() is set to true.

int QgsColorEffect::contrast() const

Returns the contrast modification for the effect.

Returns contrast value. Values are between -100 and 100, where 0 represents no change, negative values indicate less contrast and positive values indicate greater contrast

QgsImageOperation::GrayscaleMode QgsColorEffect::grayscaleMode() const

Returns whether the effect will convert a picture to grayscale.

Returns method for grayscale conversion

double QgsColorEffect::opacity() const

Returns the opacity for the effect.

Returns opacity value between 0 and 1 inclusive, where 0 is fully transparent and 1 is fully opaque.

QgsStringMap QgsColorEffect::properties() const override

Returns the properties describing the paint effect encoded in a string format.

Returns string map of properties, in the form property key, value

void QgsColorEffect::readProperties(const QgsStringMap& props) override

Reads a string map of an effect's properties and restores the effect to the state described by the properties map.

Parameters
props effect properties encoded in a string map

double QgsColorEffect::saturation() const

Returns the saturation modification for the effect.

Returns saturation value. Values are between 0 and 2.0, where 1.0 represents no change, 0.0 represents totally desaturated (grayscale), and positive values indicate greater saturation

void QgsColorEffect::setBlendMode(const QPainter::CompositionMode mode)

Sets the blend mode for the effect.

Parameters
mode blend mode used for drawing the effect on to a destination paint device

void QgsColorEffect::setBrightness(int brightness)

Sets the brightness modification for the effect.

Parameters
brightness Valid values are between -255 and 255, where 0 represents no change, negative values indicate darkening and positive values indicate lightening

void QgsColorEffect::setColorizeColor(const QColor& colorizeColor)

Sets the color used for colorizing a picture.

Parameters
colorizeColor colorization color

This is only used if setColorizeOn() is set to true.

void QgsColorEffect::setColorizeOn(bool colorizeOn)

Sets whether the effect should colorize a picture.

Parameters
colorizeOn set to true to enable colorization

void QgsColorEffect::setColorizeStrength(int colorizeStrength)

Sets the strength for colorizing a picture.

Parameters
colorizeStrength colorization strength, between 0 and 100

This is only used if setColorizeOn() is set to true.

void QgsColorEffect::setContrast(int contrast)

Sets the contrast modification for the effect.

Parameters
contrast Valid values are between -100 and 100, where 0 represents no change, negative values indicate less contrast and positive values indicate greater contrast

void QgsColorEffect::setGrayscaleMode(QgsImageOperation::GrayscaleMode grayscaleMode)

Sets whether the effect should convert a picture to grayscale.

Parameters
grayscaleMode method for grayscale conversion

void QgsColorEffect::setOpacity(const double opacity)

Sets the opacity for the effect.

Parameters
opacity double between 0 and 1 inclusive, where 0 is fully transparent and 1 is fully opaque

void QgsColorEffect::setSaturation(double saturation)

Sets the saturation modification for the effect.

Parameters
saturation Valid values are between 0 and 2.0, where 1.0 represents no change, 0.0 represents totally desaturated (grayscale), and positive values indicate greater saturation

QString QgsColorEffect::type() const override

Returns the effect type.

Returns unique string representation of the effect type

void QgsColorEffect::draw(QgsRenderContext& context) override protected

Handles drawing of the effect's result on to the specified render context.

Parameters
context destination render context

Derived classes must reimplement this method to apply any transformations to the source QPicture and draw the result using the context's painter.