Krita Source Code Documentation
Loading...
Searching...
No Matches
KStatefulBrush Class Reference

#include <kcolorscheme.h>

Public Member Functions

QBrush brush (const QPalette &) const
 
QBrush brush (const QWidget *) const
 
QBrush brush (QPalette::ColorGroup) const
 
 KStatefulBrush ()
 
 KStatefulBrush (const KStatefulBrush &)
 
 KStatefulBrush (const QBrush &, const QBrush &background, KSharedConfigPtr=KSharedConfigPtr())
 
 KStatefulBrush (const QBrush &, KSharedConfigPtr=KSharedConfigPtr())
 
 KStatefulBrush (KColorScheme::ColorSet, KColorScheme::BackgroundRole, KSharedConfigPtr=KSharedConfigPtr())
 
 KStatefulBrush (KColorScheme::ColorSet, KColorScheme::DecorationRole, KSharedConfigPtr=KSharedConfigPtr())
 
 KStatefulBrush (KColorScheme::ColorSet, KColorScheme::ForegroundRole, KSharedConfigPtr=KSharedConfigPtr())
 
KStatefulBrushoperator= (const KStatefulBrush &)
 
 ~KStatefulBrush ()
 

Private Attributes

class KStatefulBrushPrivated
 

Detailed Description

A container for a "state-aware" brush.

KStatefulBrush provides an easy and safe way to store a color for use in a user interface. It is "safe" both in that it will make it easy to deal with widget states in a correct manner, and that it insulates you against changes in QPalette::ColorGroup.

Basically, a stateful brush is used to cache a particular "color" from the KDE system palette (usually, one which does not live in QPalette). When you are ready to draw using the brush, you use the current state to retrieve the appropriate brush.

Stateful brushes can also be used to apply state effects to arbitrary brushes, for example when working with a application specific user-defined color palette.

Note
As of Qt 4.3, QPalette::ColorGroup is missing a state for disabled widgets in an inactive window. Hopefully Trolltech will fix this bug, at which point KColorScheme and KStatefulBrush will be updated to recognize the new state. Using KStatefulBrush will allow your application to inherit these changes "for free", without even recompiling.

Definition at line 453 of file kcolorscheme.h.

Constructor & Destructor Documentation

◆ KStatefulBrush() [1/7]

KStatefulBrush::KStatefulBrush ( )
explicit

Construct a "default" stateful brush. For such an instance, all overloads of KStatefulBrush::brush will return a default brush (i.e. QBrush()).

Definition at line 600 of file kcolorscheme.cpp.

601{
602 d = new KStatefulBrushPrivate[3];
603}
class KStatefulBrushPrivate * d

References d.

◆ KStatefulBrush() [2/7]

KStatefulBrush::KStatefulBrush ( KColorScheme::ColorSet set,
KColorScheme::ForegroundRole role,
KSharedConfigPtr config = KSharedConfigPtr() )
explicit

Construct a stateful brush from given color set and foreground role, using the colors from the given KConfig (if null, the system colors are used).

Definition at line 605 of file kcolorscheme.cpp.

607{
608 d = new KStatefulBrushPrivate[3];
609 d[0] = KColorScheme(QPalette::Active, set, config).foreground(role);
610 d[1] = KColorScheme(QPalette::Disabled, set, config).foreground(role);
611 d[2] = KColorScheme(QPalette::Inactive, set, config).foreground(role);
612}
QBrush foreground(ForegroundRole=NormalText) const

References d, and KColorScheme::foreground().

◆ KStatefulBrush() [3/7]

KStatefulBrush::KStatefulBrush ( KColorScheme::ColorSet set,
KColorScheme::BackgroundRole role,
KSharedConfigPtr config = KSharedConfigPtr() )
explicit

Construct a stateful brush from given color set and background role, using the colors from the given KConfig (if null, the system colors are used).

Definition at line 614 of file kcolorscheme.cpp.

616{
617 d = new KStatefulBrushPrivate[3];
618 d[0] = KColorScheme(QPalette::Active, set, config).background(role);
619 d[1] = KColorScheme(QPalette::Disabled, set, config).background(role);
620 d[2] = KColorScheme(QPalette::Inactive, set, config).background(role);
621}
QBrush background(BackgroundRole=NormalBackground) const

References KColorScheme::background(), and d.

◆ KStatefulBrush() [4/7]

KStatefulBrush::KStatefulBrush ( KColorScheme::ColorSet set,
KColorScheme::DecorationRole role,
KSharedConfigPtr config = KSharedConfigPtr() )
explicit

Construct a stateful brush from given color set and decoration role, using the colors from the given KConfig (if null, the system colors are used).

Definition at line 623 of file kcolorscheme.cpp.

625{
626 d = new KStatefulBrushPrivate[3];
627 d[0] = KColorScheme(QPalette::Active, set, config).decoration(role);
628 d[1] = KColorScheme(QPalette::Disabled, set, config).decoration(role);
629 d[2] = KColorScheme(QPalette::Inactive, set, config).decoration(role);
630}
QBrush decoration(DecorationRole) const

References d, and KColorScheme::decoration().

◆ KStatefulBrush() [5/7]

KStatefulBrush::KStatefulBrush ( const QBrush & brush,
KSharedConfigPtr config = KSharedConfigPtr() )
explicit

Construct a stateful background brush from a specified QBrush (or QColor, via QBrush's implicit constructor). The various states are determined from the base QBrush (which fills in the Active state) according to the same rules used to build stateful color schemes from the system color scheme. The state effects from the given KConfig are used (if null, the system state effects are used).

Definition at line 632 of file kcolorscheme.cpp.

633{
634 if (!config) {
635 config = KSharedConfig::openConfig();
636 }
637 d = new KStatefulBrushPrivate[3];
638 d[0] = brush;
639 d[1] = StateEffects(QPalette::Disabled, config).brush(brush);
640 d[2] = StateEffects(QPalette::Inactive, config).brush(brush);
641}
QBrush brush(QPalette::ColorGroup) const
QBrush brush(const QBrush &background) const

References StateEffects::brush(), brush(), and d.

◆ KStatefulBrush() [6/7]

KStatefulBrush::KStatefulBrush ( const QBrush & brush,
const QBrush & background,
KSharedConfigPtr config = KSharedConfigPtr() )
explicit

Construct a stateful foreground/decoration brush from a specified QBrush (or QColor, via QBrush's implicit constructor). The various states are determined from the base QBrush (which fills in the Active state) according to the same rules used to build stateful color schemes from the system color scheme. The state effects from the given KConfig are used (if null, the system state effects are used).

Parameters
brushThe foreground brush
backgroundThe background brush (or color) corresponding to the KColorScheme::NormalBackground role and QPalette::Active state for this foreground/decoration color.
configThe configuration.

Definition at line 643 of file kcolorscheme.cpp.

645{
646 if (!config) {
647 config = KSharedConfig::openConfig();
648 }
649 d = new KStatefulBrushPrivate[3];
650 d[0] = brush;
651 d[1] = StateEffects(QPalette::Disabled, config).brush(brush, background);
652 d[2] = StateEffects(QPalette::Inactive, config).brush(brush, background);
653}

References StateEffects::brush(), brush(), and d.

◆ KStatefulBrush() [7/7]

KStatefulBrush::KStatefulBrush ( const KStatefulBrush & other)

Construct a copy of another KStatefulBrush.

Definition at line 655 of file kcolorscheme.cpp.

656{
657 d = new KStatefulBrushPrivate[3];
658 d[0] = other.d[0];
659 d[1] = other.d[1];
660 d[2] = other.d[2];
661}

References d.

◆ ~KStatefulBrush()

KStatefulBrush::~KStatefulBrush ( )

Destructor

Definition at line 663 of file kcolorscheme.cpp.

664{
665 delete[] d;
666}

References d.

Member Function Documentation

◆ brush() [1/3]

QBrush KStatefulBrush::brush ( const QPalette & pal) const

Retrieve the brush, using a QPalette reference to determine the correct state. Use when your painting code has easy access to the QPalette that it is supposed to be using. The state used in this instance is the currentColorGroup of the palette.

Definition at line 688 of file kcolorscheme.cpp.

689{
690 return brush(pal.currentColorGroup());
691}

References brush().

◆ brush() [2/3]

QBrush KStatefulBrush::brush ( const QWidget * widget) const

Retrieve the brush, using a QWidget pointer to determine the correct state. Use when you have a pointer to the widget that you are painting. The state used is the current state of the widget.

Note
If you pass an invalid widget, you will get a default brush (i.e. QBrush()).

Definition at line 693 of file kcolorscheme.cpp.

694{
695 if (widget) {
696 return brush(widget->palette());
697 } else {
698 return QBrush();
699 }
700}

References brush().

◆ brush() [3/3]

QBrush KStatefulBrush::brush ( QPalette::ColorGroup state) const

Retrieve the brush for the specified widget state. This is used when you know explicitly what state is wanted. Otherwise one of overloads is often more convenient.

Definition at line 676 of file kcolorscheme.cpp.

677{
678 switch (state) {
679 case QPalette::Inactive:
680 return d[2];
681 case QPalette::Disabled:
682 return d[1];
683 default:
684 return d[0];
685 }
686}

References d.

◆ operator=()

KStatefulBrush & KStatefulBrush::operator= ( const KStatefulBrush & other)

Standard assignment operator

Definition at line 668 of file kcolorscheme.cpp.

669{
670 d[0] = other.d[0];
671 d[1] = other.d[1];
672 d[2] = other.d[2];
673 return *this;
674}

References d.

Member Data Documentation

◆ d

class KStatefulBrushPrivate* KStatefulBrush::d
private

Definition at line 552 of file kcolorscheme.h.


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