Commit 05f74cef authored by Frédéric Larue's avatar Frédéric Larue
Browse files

Generation of category icons with colors related to the current theme.

parent bca18dbc
......@@ -6,6 +6,7 @@
*/
#include "UIMainWindow.h"
#include "ToolCategory.h"
......@@ -14,3 +15,45 @@
QVector<QString> ToolCategory::s_CategoryNames;
QVector<QString> ToolCategory::s_CategoryIcons;
QMap<int,int> ToolCategory::s_CategoryById;
void ToolCategory::declareCategory( int id, const QString& name, const QString &iconName )
{
// Load the template alpha mask image from resources.
QImage alphaMask( iconName );
// Create a new image corresponding to this mask for each of the required colors.
QImage icon( alphaMask.width(), alphaMask.height(), QImage::Format_RGBA8888 );
// Update pixel color values.
QColor c = QApplication::palette().color( QPalette::Active, QPalette::BrightText );
QColor s = QApplication::palette().color( QPalette::Active, QPalette::Shadow );
for( int y=0; y<alphaMask.height(); ++y )
for( int x=0; x<alphaMask.width(); ++x )
{
float l = alphaMask.pixelColor(x,y).redF();
float a = alphaMask.pixelColor(x,y).alphaF();
QColor color( l*c.red () + (1.0f-l)*s.red (),
l*c.green() + (1.0f-l)*s.green(),
l*c.blue () + (1.0f-l)*s.blue (),
a*(l*c.alpha() + (1.0f-l)*s.alpha()) );
icon.setPixelColor( x,y, color );
}
// Save the icon to the style destination directory.
QString themePath = UIMainWindow::getUserSettings()->value("uiStyle").toString();
QString iconFilePath = QFileInfo(themePath).absolutePath() + "/" + QFileInfo(iconName).fileName();
icon.save( iconFilePath );
// Store category info.
s_CategoryById[id] = s_CategoryNames.size();
s_CategoryNames.append( name );
s_CategoryIcons.append( iconName/*iconFilePath*/ );
}
......@@ -27,12 +27,7 @@ public:
static inline QIcon categoryIcon( int id ) { return QIcon( s_CategoryIcons[ s_CategoryById[id] ] ); }
static inline bool isCategoryDeclared( int id ) { return s_CategoryById.contains( id ); }
static inline void declareCategory( int id, const QString& name, const QString &icon )
{
s_CategoryById[id] = s_CategoryNames.size();
s_CategoryNames.append( name );
s_CategoryIcons.append( icon );
}
static void declareCategory( int id, const QString& name, const QString &iconName );
static inline int categoriesCount() { return s_CategoryById.size(); }
static inline QList<int> categoriesId()
......
Supports Markdown
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