KIconThemes 5.109.0
Public Types | Public Member Functions | Static Public Member Functions | List of all members
KIconEffect

Applies effects to icons. More...

#include <KIconEffect>

Public Types

enum  Effects {
  NoEffect , ToGray , Colorize , ToGamma ,
  DeSaturate , ToMonochrome , LastEffect
}
 This is the enumeration of all possible icon effects. More...
 

Public Member Functions

 KIconEffect ()
 Create a new KIconEffect.
 
 KIconEffect (const KIconEffect &)=delete
 
QImage apply (const QImage &src, int effect, float value, const QColor &rgb, bool trans) const
 Applies an effect to an image.
 
QImage apply (const QImage &src, int effect, float value, const QColor &rgb, const QColor &rgb2, bool trans) const
 
QImage apply (const QImage &src, int group, int state) const
 Applies an effect to an image.
 
QPixmap apply (const QPixmap &src, int effect, float value, const QColor &rgb, bool trans) const
 Applies an effect to a pixmap.
 
QPixmap apply (const QPixmap &src, int effect, float value, const QColor &rgb, const QColor &rgb2, bool trans) const
 
QPixmap apply (const QPixmap &src, int group, int state) const
 Applies an effect to a pixmap.
 
QImage doublePixels (const QImage &src) const
 Returns an image twice as large, consisting of 2x2 pixels.
 
QString fingerprint (int group, int state) const
 Returns a fingerprint for the effect by encoding the given group and state into a QString.
 
bool hasEffect (int group, int state) const
 Tests whether an effect has been configured for the given icon group.
 
void init ()
 Rereads configuration.
 
KIconEffectoperator= (const KIconEffect &)=delete
 

Static Public Member Functions

static void colorize (QImage &image, const QColor &col, float value)
 Colorizes an image with a specific color.
 
static void deSaturate (QImage &image, float value)
 Desaturates an image.
 
static void overlay (QImage &src, QImage &overlay)
 Overlays an image with an other image.
 
static void semiTransparent (QImage &image)
 Renders an image semi-transparent.
 
static void semiTransparent (QPixmap &pixmap)
 Renders a pixmap semi-transparent.
 
static void toGamma (QImage &image, float value)
 Changes the gamma value of an image.
 
static void toGray (QImage &image, float value)
 Tints an image gray.
 
static void toMonochrome (QImage &image, const QColor &black, const QColor &white, float value)
 Produces a monochrome icon with a given foreground and background color.
 

Detailed Description

Applies effects to icons.

This class applies effects to icons depending on their state and group. For example, it can be used to make all disabled icons in a toolbar gray.

Various Effects applied to an image
See also
QIcon::fromTheme

Member Enumeration Documentation

◆ Effects

This is the enumeration of all possible icon effects.

Note that 'LastEffect' is no valid icon effect but only used internally to check for invalid icon effects.

  • NoEffect: Do not apply any icon effect
  • ToGray: Tints the icon gray
  • Colorize: Tints the icon with a specific color
  • ToGamma: Change the gamma value of the icon
  • DeSaturate: Reduce the saturation of the icon
  • ToMonochrome: Produces a monochrome icon

Constructor & Destructor Documentation

◆ KIconEffect()

KIconEffect::KIconEffect ( )

Create a new KIconEffect.

You will most likely never have to use this to create a new KIconEffect yourself, as you can use the KIconEffect provided by the global KIconLoader (which itself is accessible by KIconLoader::global()) through its iconEffect() function.

Member Function Documentation

◆ apply() [1/4]

QImage KIconEffect::apply ( const QImage &  src,
int  effect,
float  value,
const QColor &  rgb,
bool  trans 
) const

Applies an effect to an image.

Parameters
srcThe image.
effectThe effect to apply, one of KIconEffect::Effects.
valueStrength of the effect. 0 <= value <= 1.
rgbColor parameter for effects that need one.
transAdd Transparency if trans = true.
Returns
An image with the effect applied.

◆ apply() [2/4]

QImage KIconEffect::apply ( const QImage &  src,
int  group,
int  state 
) const

Applies an effect to an image.

The effect to apply depends on the group and state parameters, and is configured by the user.

Parameters
srcThe image.
groupThe group for the icon, see KIconLoader::Group
stateThe icon's state, see KIconLoader::States
Returns
An image with the effect applied.

◆ apply() [3/4]

QPixmap KIconEffect::apply ( const QPixmap &  src,
int  effect,
float  value,
const QColor &  rgb,
bool  trans 
) const

Applies an effect to a pixmap.

Parameters
srcThe pixmap.
effectThe effect to apply, one of KIconEffect::Effects.
valueStrength of the effect. 0 <= value <= 1.
rgbColor parameter for effects that need one.
transAdd Transparency if trans = true.
Returns
A pixmap with the effect applied.

◆ apply() [4/4]

QPixmap KIconEffect::apply ( const QPixmap &  src,
int  group,
int  state 
) const

Applies an effect to a pixmap.

Parameters
srcThe pixmap.
groupThe group for the icon, see KIconLoader::Group
stateThe icon's state, see KIconLoader::States
Returns
A pixmap with the effect applied.

◆ colorize()

static void KIconEffect::colorize ( QImage &  image,
const QColor &  col,
float  value 
)
static

Colorizes an image with a specific color.

Parameters
imageThe image
colThe color with which the image is tinted
valueStrength of the effect. 0 <= value <= 1

◆ deSaturate()

static void KIconEffect::deSaturate ( QImage &  image,
float  value 
)
static

Desaturates an image.

Parameters
imageThe image
valueStrength of the effect. 0 <= value <= 1

◆ doublePixels()

QImage KIconEffect::doublePixels ( const QImage &  src) const

Returns an image twice as large, consisting of 2x2 pixels.

Parameters
srcthe image.
Returns
the scaled image.

◆ fingerprint()

QString KIconEffect::fingerprint ( int  group,
int  state 
) const

Returns a fingerprint for the effect by encoding the given group and state into a QString.

This is useful for caching.

Parameters
groupthe group, see KIconLoader::Group
statethe state, see KIconLoader::States
Returns
the fingerprint of the given group+state

◆ hasEffect()

bool KIconEffect::hasEffect ( int  group,
int  state 
) const

Tests whether an effect has been configured for the given icon group.

Parameters
groupthe group to check, see KIconLoader::Group
statethe state to check, see KIconLoader::States
Returns
true if an effect is configured for the given group in state, otherwise false.
See also
KIconLoader::Group KIconLoader::States

◆ init()

void KIconEffect::init ( )

Rereads configuration.

◆ overlay()

static void KIconEffect::overlay ( QImage &  src,
QImage &  overlay 
)
static

Overlays an image with an other image.

Parameters
srcThe image
overlayThe image to overlay src with

◆ semiTransparent() [1/2]

static void KIconEffect::semiTransparent ( QImage &  image)
static

Renders an image semi-transparent.

Parameters
imageThe image

◆ semiTransparent() [2/2]

static void KIconEffect::semiTransparent ( QPixmap &  pixmap)
static

Renders a pixmap semi-transparent.

Parameters
pixmapThe pixmap

◆ toGamma()

static void KIconEffect::toGamma ( QImage &  image,
float  value 
)
static

Changes the gamma value of an image.

Parameters
imageThe image
valueStrength of the effect. 0 <= value <= 1

◆ toGray()

static void KIconEffect::toGray ( QImage &  image,
float  value 
)
static

Tints an image gray.

Parameters
imageThe image
valueStrength of the effect. 0 <= value <= 1

◆ toMonochrome()

static void KIconEffect::toMonochrome ( QImage &  image,
const QColor &  black,
const QColor &  white,
float  value 
)
static

Produces a monochrome icon with a given foreground and background color.

Parameters
imageThe image
whiteThe color with which the white parts of image are painted
blackThe color with which the black parts of image are painted
valueStrength of the effect. 0 <= value <= 1