Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
Unified default and named styles hash table.
Browse files Browse the repository at this point in the history
  • Loading branch information
pasnox committed Sep 16, 2012
1 parent fca181a commit 075b3f1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 30 deletions.
70 changes: 43 additions & 27 deletions src/theme/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
**
****************************************************************************/
#include "Theme.h"
#include "Tools.h"

#include <QFile>

class Theme::SchemaData : public QSharedData
{
public:
QHash<QodeEdit::DefaultStyle, Theme::Style> defaultStyles;
QHash<QString, Theme::Style> styles;
QString name;

Expand All @@ -33,7 +33,6 @@ class Theme::SchemaData : public QSharedData

SchemaData( const Theme::SchemaData& other )
: QSharedData( other ),
QE_OTHER_INIT( defaultStyles ),
QE_OTHER_INIT( styles ),
QE_OTHER_INIT( name )
{
Expand All @@ -42,35 +41,52 @@ class Theme::SchemaData : public QSharedData
virtual ~SchemaData() {
}

Theme::Style* defaultStyle( QodeEdit::DefaultStyle defaultStyle ) {
return &styles[ QString( "ds%1" ).arg( QodeEdit::Tools::defaultStyleToString( defaultStyle ) ).toLower().trimmed() ];
}

void initToDefault() {
//defaultStyles[ QodeEdit::NormalStyle ].;
Theme::Style* style = 0;

style = defaultStyle( QodeEdit::NormalStyle );

defaultStyles[ QodeEdit::KeywordStyle ].setFontWeight( QFont::Bold );
style = defaultStyle( QodeEdit::KeywordStyle );
style->setFontWeight( QFont::Bold );

defaultStyles[ QodeEdit::DataTypeStyle ].setForeground( QBrush( QColor( "#0057ae" ) ) );
style = defaultStyle( QodeEdit::DataTypeStyle );
style->setForeground( QBrush( QColor( "#0057ae" ) ) );

defaultStyles[ QodeEdit::DecValStyle ].setForeground( QBrush( QColor( "#b07e00" ) ) );
defaultStyles[ QodeEdit::BaseNStyle ].setForeground( QBrush( QColor( "#b07e00" ) ) );
defaultStyles[ QodeEdit::FloatStyle ].setForeground( QBrush( QColor( "#b07e00" ) ) );
style = defaultStyle( QodeEdit::DecValStyle );
style->setForeground( QBrush( QColor( "#b07e00" ) ) );
style->setForeground( QBrush( QColor( "#b07e00" ) ) );
style->setForeground( QBrush( QColor( "#b07e00" ) ) );

defaultStyles[ QodeEdit::CharStyle ].setForeground( QBrush( QColor( "#ff80e0" ) ) );
style = defaultStyle( QodeEdit::CharStyle );
style->setForeground( QBrush( QColor( "#ff80e0" ) ) );

defaultStyles[ QodeEdit::StringStyle ].setForeground( QBrush( QColor( "#bf0303" ) ) );
style = defaultStyle( QodeEdit::StringStyle );
style->setForeground( QBrush( QColor( "#bf0303" ) ) );

defaultStyles[ QodeEdit::CommentStyle ].setForeground( QBrush( QColor( "#888786" ) ) );
defaultStyles[ QodeEdit::CommentStyle ].setFontItalic( true );
style = defaultStyle( QodeEdit::CommentStyle );
style->setForeground( QBrush( QColor( "#888786" ) ) );
style->setFontItalic( true );

defaultStyles[ QodeEdit::OthersStyle ].setForeground( QBrush( QColor( "#006e26" ) ) );
style = defaultStyle( QodeEdit::OthersStyle );
style->setForeground( QBrush( QColor( "#006e26" ) ) );

defaultStyles[ QodeEdit::AlertStyle ].setForeground( QBrush( QColor( "#bf0303" ) ) );
defaultStyles[ QodeEdit::AlertStyle ].setBackground( QBrush( QColor( "#f7e7e7" ) ) );
defaultStyles[ QodeEdit::AlertStyle ].setFontWeight( QFont::Bold );
style = defaultStyle( QodeEdit::AlertStyle );
style->setForeground( QBrush( QColor( "#bf0303" ) ) );
style->setBackground( QBrush( QColor( "#f7e7e7" ) ) );
style->setFontWeight( QFont::Bold );

defaultStyles[ QodeEdit::FunctionStyle ].setForeground( QBrush( QColor( "#442886" ) ) );
style = defaultStyle( QodeEdit::FunctionStyle );
style->setForeground( QBrush( QColor( "#442886" ) ) );

defaultStyles[ QodeEdit::RegionMarkerStyle ].setForeground( QBrush( QColor( "#0057ae" ) ) );
style = defaultStyle( QodeEdit::RegionMarkerStyle );
style->setForeground( QBrush( QColor( "#0057ae" ) ) );

defaultStyles[ QodeEdit::ErrorStyle ].setForeground( QBrush( QColor( "#e1eaf8" ) ) );
style = defaultStyle( QodeEdit::ErrorStyle );
style->setForeground( QBrush( QColor( "#e1eaf8" ) ) );
}
};

Expand All @@ -81,22 +97,22 @@ Theme::Schema::~Schema()
{
}

Theme::Style Theme::Schema::defaultStyle( QodeEdit::DefaultStyle type ) const
Theme::Style Theme::Schema::style( const QString& name ) const
{
return d->defaultStyles.value( type );
return d->styles.value( name.toLower().trimmed() );
}

void Theme::Schema::setDefaultStyle( QodeEdit::DefaultStyle type, const Theme::Style& style )
void Theme::Schema::setStyle( const QString& name, const Theme::Style& style )
{
d->defaultStyles[ type ] = style;
d->styles[ name.toLower().trimmed() ] = style;
}

Theme::Style Theme::Schema::style( const QString& name ) const
Theme::Style Theme::Schema::defaultStyle( QodeEdit::DefaultStyle defaultStyle ) const
{
return d->styles.value( name.toLower().trimmed() );
return style( QString( "ds%1" ).arg( QodeEdit::Tools::defaultStyleToString( defaultStyle ) ) );
}

void Theme::Schema::setStyle( const QString& name, const Theme::Style& style )
void Theme::Schema::setDefaultStyle( QodeEdit::DefaultStyle defaultStyle, const Theme::Style& style )
{
d->styles[ name.toLower().trimmed() ] = style;
setStyle( QString( "ds%1" ).arg( QodeEdit::Tools::defaultStyleToString( defaultStyle ) ), style );
}
6 changes: 3 additions & 3 deletions src/theme/Theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class Schema
QE_DECL_SHARED_CLASS( Schema, Theme );
QE_DECL_MEMBER( QString, name );

Theme::Style defaultStyle( QodeEdit::DefaultStyle type ) const;
void setDefaultStyle( QodeEdit::DefaultStyle type, const Theme::Style& style );

Theme::Style style( const QString& name ) const;
void setStyle( const QString& name, const Theme::Style& style );

Theme::Style defaultStyle( QodeEdit::DefaultStyle defaultStyle ) const;
void setDefaultStyle( QodeEdit::DefaultStyle defaultStyle, const Theme::Style& style );
};

}; // Theme
Expand Down

0 comments on commit 075b3f1

Please sign in to comment.