KWin
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Properties | List of all members
ColorHelper Class Reference

Helper to manipulate colors. More...

#include <colorhelper.h>

Inheritance diagram for ColorHelper:

Public Types

enum  ShadeRole {
  LightShade , MidlightShade , MidShade , DarkShade ,
  ShadowShade
}
 
enum  BackgroundRole {
  NormalBackground = 0 , AlternateBackground = 1 , ActiveBackground = 2 , LinkBackground = 3 ,
  VisitedBackground = 4 , NegativeBackground = 5 , NeutralBackground = 6 , PositiveBackground = 7
}
 
enum  ForegroundRole {
  NormalText = 0 , InactiveText = 1 , ActiveText = 2 , LinkText = 3 ,
  VisitedText = 4 , NegativeText = 5 , NeutralText = 6 , PositiveText = 7
}
 

Public Member Functions

 ColorHelper (QObject *parent=nullptr)
 
 ~ColorHelper () override
 
Q_INVOKABLE QColor shade (const QColor &color, ShadeRole role)
 
Q_INVOKABLE QColor shade (const QColor &color, ShadeRole role, qreal contrast)
 
Q_INVOKABLE QColor multiplyAlpha (const QColor &color, qreal alpha)
 
Q_INVOKABLE QColor background (bool active, BackgroundRole role=NormalBackground) const
 
Q_INVOKABLE QColor foreground (bool active, ForegroundRole role=NormalText) const
 
qreal contrast () const
 

Properties

qreal contrast
 

Detailed Description

Helper to manipulate colors.

Exports a few functions from KColorScheme.

Definition at line 16 of file colorhelper.h.

Member Enumeration Documentation

◆ BackgroundRole

This enumeration describes the background color being selected from the given set.

Background colors are suitable for drawing under text, and should never be used to draw text. In combination with one of the overloads of KColorScheme::shade, they may be used to generate colors for drawing frames, bevels, and similar decorations.

Enumerator
NormalBackground 

Normal background.

AlternateBackground 

Alternate background; for example, for use in lists.

This color may be the same as BackgroundNormal, especially in sets other than View and Window.

ActiveBackground 

Third color; for example, items which are new, active, requesting attention, etc.

Alerting the user that a certain field must be filled out would be a good usage (although NegativeBackground could be used to the same effect, depending on what you are trying to achieve). Unlike ActiveText, this should not be used for mouseover effects.

LinkBackground 

Fourth color; corresponds to (unvisited) links.

Exactly what this might be used for is somewhat harder to qualify; it might be used for bookmarks, as a 'you can click here' indicator, or to highlight recent content (i.e. in a most-recently-accessed list).

VisitedBackground 

Fifth color; corresponds to visited links.

This can also be used to indicate "not recent" content, especially when a color is needed to denote content which is "old" or "archival".

NegativeBackground 

Sixth color; for example, errors, untrusted content, etc.

NeutralBackground 

Seventh color; for example, warnings, secure/encrypted content.

PositiveBackground 

Eigth color; for example, success messages, trusted content.

Definition at line 68 of file colorhelper.h.

◆ ForegroundRole

This enumeration describes the foreground color being selected from the given set.

Foreground colors are suitable for drawing text or glyphs (such as the symbols on window decoration buttons, assuming a suitable background brush is used), and should never be used to draw backgrounds.

For window decorations, the following is suggested, but not set in stone:

  • Maximize - PositiveText
  • Minimize - NeutralText
  • Close - NegativeText
  • WhatsThis - LinkText
  • Sticky - ActiveText
Enumerator
NormalText 

Normal foreground.

InactiveText 

Second color; for example, comments, items which are old, inactive or disabled. Generally used for things that are meant to be "less important". InactiveText is not the same role as NormalText in the inactive state.

ActiveText 

Third color; for example items which are new, active, requesting attention, etc. May be used as a hover color for clickable items.

LinkText 

Fourth color; use for (unvisited) links. May also be used for other clickable items or content that indicates relationships, items that indicate somewhere the user can visit, etc.

VisitedText 

Fifth color; used for (visited) links. As with LinkText, may be used for items that have already been "visited" or accessed. May also be used to indicate "historical" (i.e. "old") items or information, especially if InactiveText is being used in the same context to express something different.

NegativeText 

Sixth color; for example, errors, untrusted content, deletions, etc.

NeutralText 

Seventh color; for example, warnings, secure/encrypted content.

PositiveText 

Eigth color; for example, additions, success messages, trusted content.

Definition at line 138 of file colorhelper.h.

◆ ShadeRole

This enumeration describes the color shade being selected from the given set.

Color shades are used to draw "3d" elements, such as frames and bevels. They are neither foreground nor background colors. Text should not be painted over a shade, and shades should not be used to draw text.

Enumerator
LightShade 

The light color is lighter than dark() or shadow() and contrasts with the base color.

MidlightShade 

The midlight color is in between base() and light().

MidShade 

The mid color is in between base() and dark().

DarkShade 

The dark color is in between mid() and shadow().

ShadowShade 

The shadow color is darker than light() or midlight() and contrasts the base color.

Definition at line 34 of file colorhelper.h.

Constructor & Destructor Documentation

◆ ColorHelper()

ColorHelper::ColorHelper ( QObject * parent = nullptr)
explicit

Definition at line 10 of file colorhelper.cpp.

◆ ~ColorHelper()

ColorHelper::~ColorHelper ( )
override

Definition at line 15 of file colorhelper.cpp.

Member Function Documentation

◆ background()

QColor ColorHelper::background ( bool active,
ColorHelper::BackgroundRole role = NormalBackground ) const

Retrieve the requested background brush's color for the active button.

Parameters
activeWhether the active or inactive palette should be used.

Definition at line 41 of file colorhelper.cpp.

◆ contrast()

qreal ColorHelper::contrast ( ) const

Definition at line 29 of file colorhelper.cpp.

◆ foreground()

QColor ColorHelper::foreground ( bool active,
ColorHelper::ForegroundRole role = NormalText ) const

Retrieve the requested foreground brush's color for the active button.

Parameters
activeWhether the active or inactive palette should be used.

Definition at line 47 of file colorhelper.cpp.

◆ multiplyAlpha()

QColor ColorHelper::multiplyAlpha ( const QColor & color,
qreal alpha )

Retrieve the requested shade color, using the specified color as the base color and the specified contrast.

Parameters
contrastAmount roughly specifying the contrast by which to adjust the base color, between -1.0 and 1.0 (values between 0.0 and 1.0 correspond to the value from KGlobalSettings::contrastF)
Note
Shades are chosen such that all shades would contrast with the base color. This means that if base is very dark, the 'dark' shades will be lighter than the base color, with midlight() == shadow(). Conversely, if the base color is very light, the 'light' shades will be darker than the base color, with light() == mid().
See also
KColorUtils::shade

Definition at line 34 of file colorhelper.cpp.

◆ shade() [1/2]

QColor ColorHelper::shade ( const QColor & color,
ColorHelper::ShadeRole role )

Retrieve the requested shade color, using the specified color as the base color and the system contrast setting.

Note
Shades are chosen such that all shades would contrast with the base color. This means that if base is very dark, the 'dark' shades will be lighter than the base color, with midlight() == shadow(). Conversely, if the base color is very light, the 'light' shades will be darker than the base color, with light() == mid().

Definition at line 19 of file colorhelper.cpp.

◆ shade() [2/2]

QColor ColorHelper::shade ( const QColor & color,
ColorHelper::ShadeRole role,
qreal contrast )

Definition at line 24 of file colorhelper.cpp.

Property Documentation

◆ contrast

qreal ColorHelper::contrast
read

Same as KGlobalSettings::contrastF.

Definition at line 22 of file colorhelper.h.


The documentation for this class was generated from the following files: