Gui::StatefulLabel Class Reference

A text label whose appearance can change based on a specified state. More...

#include <Widgets.h>

Public Slots

void setOverridePreference (bool overridePreference)
 
void setState (QString state)
 

Public Member Functions

void OnChange (Base::Subject< const char * > &rCaller, const char *rcReason)
 Observes the parameter group and clears the cache if it changes. More...
 
void registerState (const QString &state, const QColor &color, const std::string &preferenceName=std::string())
 For convenience, allow simple color-only states via QColor (optionally attached to a user preference) More...
 
void registerState (const QString &state, const QColor &foregroundColor, const QColor &backgroundColor, const std::string &preferenceName=std::string())
 For convenience, allow simple color-only states via QColor (optionally attached to a user preference) More...
 
void registerState (const QString &state, const QString &styleCSS, const std::string &preferenceName=std::string())
 Register a state and its corresponding style (optionally attached to a user preference) More...
 
void setDefaultStyle (const QString &defaultStyle)
 If an unrecognized state is set, use this style. More...
 
void setParameterGroup (const std::string &groupName)
 If any of the states have user preferences associated with them, this sets the parameter group that stores those preferences. More...
 
 StatefulLabel (QWidget *parent=nullptr)
 
virtual ~StatefulLabel ()
 
- Public Member Functions inherited from Base::Observer< const char * >
virtual const char * Name ()
 This method can be reimplemented from the concrete Observer and returns the name of the observer. More...
 
 Observer ()
 A constructor. More...
 
virtual void OnChange (Subject< const char * > &rCaller, const char * rcReason)=0
 This method need to be reimplemented from the concrete Observer and get called by the observed class. More...
 
virtual void OnDestroy (Subject< const char * > &rCaller)
 This method need to be reimplemented from the concrete Observer and get called by the observed class. More...
 
virtual ~Observer ()
 A destructor. More...
 

Properties

bool overridePreference
 
QString state
 

Detailed Description

A text label whose appearance can change based on a specified state.

The state is an arbitrary string exposed as a Qt Property (and thus available for selection via a stylesheet). This is intended for things like messages to the user, where a message that is an "error" might be colored differently than one that is a "warning" or a "message".

In order of style precedence for a given state: User preference > Stylesheet > Default unless the stylesheet sets the overridePreference, in which case the stylesheet will take precedence. If a stylesheet sets styles for this widgets states, it should also set the "handledByStyle" property to ensure the style values are used, rather than the defaults.

For example, the .qss might contain: GuiStatefulLabel { qproperty-overridePreference: true; } GuiStatefulLabel[state="special_state"] { color: red; } In this case, StatefulLabels with state "special_state" will be colored red, regardless of any entry in preferences. Use the "overridePreference" stylesheet option with care!

Author
Chris Hennes

Constructor & Destructor Documentation

◆ StatefulLabel()

StatefulLabel::StatefulLabel ( QWidget parent = nullptr)

◆ ~StatefulLabel()

StatefulLabel::~StatefulLabel ( )
virtual

Member Function Documentation

◆ OnChange()

void StatefulLabel::OnChange ( Base::Subject< const char * > &  rCaller,
const char *  rcReason 
)
virtual

Observes the parameter group and clears the cache if it changes.

Implements Base::Observer< const char * >.

References state.

◆ registerState() [1/3]

void StatefulLabel::registerState ( const QString &  state,
const QColor &  color,
const std::string &  preferenceName = std::string() 
)

For convenience, allow simple color-only states via QColor (optionally attached to a user preference)

References state.

◆ registerState() [2/3]

void StatefulLabel::registerState ( const QString &  state,
const QColor &  foregroundColor,
const QColor &  backgroundColor,
const std::string &  preferenceName = std::string() 
)

For convenience, allow simple color-only states via QColor (optionally attached to a user preference)

References state.

◆ registerState() [3/3]

void StatefulLabel::registerState ( const QString &  state,
const QString &  styleCSS,
const std::string &  preferenceName = std::string() 
)

Register a state and its corresponding style (optionally attached to a user preference)

References state.

◆ setDefaultStyle()

void StatefulLabel::setDefaultStyle ( const QString &  defaultStyle)

If an unrecognized state is set, use this style.

◆ setOverridePreference

void StatefulLabel::setOverridePreference ( bool  overridePreference)
slot

References overridePreference.

◆ setParameterGroup()

void StatefulLabel::setParameterGroup ( const std::string &  groupName)

If any of the states have user preferences associated with them, this sets the parameter group that stores those preferences.

All states must be in the same parameter group, but the group does not have to have entries for all of them.

References Base::Subject< _MessageType >::Attach(), App::GetApplication(), and App::Application::GetParameterGroupByPath().

◆ setState

void StatefulLabel::setState ( QString  state)
slot

References state.

Property Documentation

◆ overridePreference

bool Gui::StatefulLabel::overridePreference
write

Referenced by setOverridePreference().

◆ state


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