Commit 2c0c6e03 authored by Frédéric Larue's avatar Frédéric Larue

PaletteDictionary improved.

parent c53d4a45
......@@ -11,61 +11,56 @@
QString PaletteDictionary::s_ColorGroupNames[ QPalette::NColorGroups ] = {
"active" ,
"disabled" ,
"inactive"
};
QString PaletteDictionary::s_ColorRoleNames[ QPalette::NColorRoles ] = {
"window-text" ,
"button" ,
"light" ,
"midlight" ,
"dark" ,
"mid" ,
"text" ,
"bright-text" ,
"button-text" ,
"base" ,
"window" ,
"shadow" ,
"highlight" ,
"highlighted-text" ,
"link" ,
"link-visited" ,
"alternate-base" ,
"no-role" ,
"tool-tip-base" ,
"tool-tip-text"
};
void PaletteDictionary::FromPalette( const QPalette &palette )
{
clear();
QPalette::ColorGroup colorGroup[] = { QPalette::Active, QPalette::Disabled, QPalette::Inactive };
QString colorGroupPrefix[] = { "active_", "disabled_", "inactive_" };
for( int i=0; i<3; ++i )
{
(*this)[ colorGroupPrefix[i]+"window" ] = palette.color( colorGroup[i], QPalette::Window );
(*this)[ colorGroupPrefix[i]+"window-text" ] = palette.color( colorGroup[i], QPalette::WindowText );
(*this)[ colorGroupPrefix[i]+"text" ] = palette.color( colorGroup[i], QPalette::Text );
(*this)[ colorGroupPrefix[i]+"bright-text" ] = palette.color( colorGroup[i], QPalette::BrightText );
(*this)[ colorGroupPrefix[i]+"button" ] = palette.color( colorGroup[i], QPalette::Button );
(*this)[ colorGroupPrefix[i]+"button-text" ] = palette.color( colorGroup[i], QPalette::ButtonText );
(*this)[ colorGroupPrefix[i]+"shadow" ] = palette.color( colorGroup[i], QPalette::Shadow );
(*this)[ colorGroupPrefix[i]+"base" ] = palette.color( colorGroup[i], QPalette::Base );
(*this)[ colorGroupPrefix[i]+"alternate-base" ] = palette.color( colorGroup[i], QPalette::AlternateBase );
(*this)[ colorGroupPrefix[i]+"dark" ] = palette.color( colorGroup[i], QPalette::Dark );
(*this)[ colorGroupPrefix[i]+"mid" ] = palette.color( colorGroup[i], QPalette::Mid );
(*this)[ colorGroupPrefix[i]+"midlight" ] = palette.color( colorGroup[i], QPalette::Midlight );
(*this)[ colorGroupPrefix[i]+"light" ] = palette.color( colorGroup[i], QPalette::Light );
(*this)[ colorGroupPrefix[i]+"highlight" ] = palette.color( colorGroup[i], QPalette::Highlight );
(*this)[ colorGroupPrefix[i]+"highlighted-text" ] = palette.color( colorGroup[i], QPalette::HighlightedText );
(*this)[ colorGroupPrefix[i]+"link" ] = palette.color( colorGroup[i], QPalette::Link );
(*this)[ colorGroupPrefix[i]+"link-visited" ] = palette.color( colorGroup[i], QPalette::LinkVisited );
}
for( int group=0; group<QPalette::NColorGroups; ++group )
for( int role=0; role<QPalette::NColorRoles; ++role )
(*this)[ s_ColorGroupNames[group] + '_' + s_ColorRoleNames[role] ] = palette.color( (QPalette::ColorGroup) group, (QPalette::ColorRole) role );
}
void PaletteDictionary::ToPalette( QPalette &palette ) const
{
QMap<QString,QPalette::ColorGroup> groupByName;
groupByName["active" ] = QPalette::Active;
groupByName["disabled"] = QPalette::Disabled;
groupByName["inactive"] = QPalette::Inactive;
for( int g=0; g<QPalette::NColorGroups; ++g )
groupByName[ s_ColorGroupNames[g] ] = (QPalette::ColorGroup) g;
QMap<QString,QPalette::ColorRole> roleByName;
roleByName["window" ] = QPalette::Window;
roleByName["window-text" ] = QPalette::WindowText;
roleByName["text" ] = QPalette::Text;
roleByName["bright-text" ] = QPalette::BrightText;
roleByName["button" ] = QPalette::Button;
roleByName["button-text" ] = QPalette::ButtonText;
roleByName["shadow" ] = QPalette::Shadow;
roleByName["base" ] = QPalette::Base;
roleByName["alternate-base" ] = QPalette::AlternateBase;
roleByName["dark" ] = QPalette::Dark;
roleByName["mid" ] = QPalette::Mid;
roleByName["midlight" ] = QPalette::Midlight;
roleByName["light" ] = QPalette::Light;
roleByName["highlight" ] = QPalette::Highlight;
roleByName["highlighted-text"] = QPalette::HighlightedText;
roleByName["link" ] = QPalette::Link;
roleByName["link-visited" ] = QPalette::LinkVisited;
for( int r=0; r<QPalette::NColorRoles; ++r )
roleByName[ s_ColorRoleNames[r] ] = (QPalette::ColorRole) r;
for( auto color=begin(); color!=end(); ++color )
{
......
......@@ -14,16 +14,23 @@
class PaletteDictionary : public QMap<QString,QColor>
{
static QString s_ColorGroupNames[ QPalette::NColorGroups ];
static QString s_ColorRoleNames [ QPalette::NColorRoles ];
public:
inline PaletteDictionary() : QMap<QString,QColor>() {}
inline PaletteDictionary( const QPalette &palette ) : QMap<QString,QColor>() { FromPalette( palette ); }
inline PaletteDictionary() : QMap<QString,QColor>() {}
inline PaletteDictionary( const QPalette &palette ) : QMap<QString,QColor>() { FromPalette( palette ); }
void FromPalette( const QPalette &palette );
void ToPalette( QPalette &palette ) const;
bool Save( const QString &filename ) const;
bool Load( const QString &filename );
void FromPalette( const QPalette &palette );
void ToPalette( QPalette &palette ) const;
bool Save( const QString &filename ) const;
bool Load( const QString &filename );
static inline const QString& ColorGroupName( QPalette::ColorGroup group ) { return s_ColorGroupNames[group]; }
static inline const QString& ColorRoleName( QPalette::ColorRole role ) { return s_ColorRoleNames[role]; }
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment