2015-08-20 05:19:03 +05:30
|
|
|
#pragma once
|
|
|
|
#include <QtGui/QColor>
|
|
|
|
#include <rainbow.h>
|
2016-11-03 05:40:16 +05:30
|
|
|
#include <MessageLevel.h>
|
2015-08-20 05:19:03 +05:30
|
|
|
#include <QMap>
|
|
|
|
|
|
|
|
class ColorCache
|
|
|
|
{
|
|
|
|
public:
|
2018-07-15 18:21:05 +05:30
|
|
|
ColorCache(QColor front, QColor back, qreal bias)
|
|
|
|
{
|
|
|
|
m_front = front;
|
|
|
|
m_back = back;
|
|
|
|
m_bias = bias;
|
|
|
|
};
|
2015-08-20 05:19:03 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
void addColor(int key, QColor color)
|
|
|
|
{
|
|
|
|
m_colors[key] = {color, blend(color), blendBackground(color)};
|
|
|
|
}
|
2015-08-20 05:19:03 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
void setForeground(QColor front)
|
|
|
|
{
|
|
|
|
if(m_front != front)
|
|
|
|
{
|
|
|
|
m_front = front;
|
|
|
|
recolorAll();
|
|
|
|
}
|
|
|
|
}
|
2015-08-20 05:19:03 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
void setBackground(QColor back)
|
|
|
|
{
|
|
|
|
if(m_back != back)
|
|
|
|
{
|
|
|
|
m_back = back;
|
|
|
|
recolorAll();
|
|
|
|
}
|
|
|
|
}
|
2015-08-20 05:19:03 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
QColor getFront(int key)
|
|
|
|
{
|
|
|
|
auto iter = m_colors.find(key);
|
|
|
|
if(iter == m_colors.end())
|
|
|
|
{
|
|
|
|
return QColor();
|
|
|
|
}
|
|
|
|
return (*iter).front;
|
|
|
|
}
|
2015-08-20 05:19:03 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
QColor getBack(int key)
|
|
|
|
{
|
|
|
|
auto iter = m_colors.find(key);
|
|
|
|
if(iter == m_colors.end())
|
|
|
|
{
|
|
|
|
return QColor();
|
|
|
|
}
|
|
|
|
return (*iter).back;
|
|
|
|
}
|
2015-08-20 05:19:03 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
/**
|
|
|
|
* Blend the color with the front color, adapting to the back color
|
|
|
|
*/
|
|
|
|
QColor blend(QColor color);
|
2015-08-20 05:19:03 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
/**
|
|
|
|
* Blend the color with the back color
|
|
|
|
*/
|
|
|
|
QColor blendBackground(QColor color);
|
2015-08-20 05:19:03 +05:30
|
|
|
|
|
|
|
protected:
|
2018-07-15 18:21:05 +05:30
|
|
|
void recolorAll();
|
2015-08-20 05:19:03 +05:30
|
|
|
|
|
|
|
protected:
|
2018-07-15 18:21:05 +05:30
|
|
|
struct ColorEntry
|
|
|
|
{
|
|
|
|
QColor original;
|
|
|
|
QColor front;
|
|
|
|
QColor back;
|
|
|
|
};
|
2015-08-20 05:19:03 +05:30
|
|
|
|
|
|
|
protected:
|
2018-07-15 18:21:05 +05:30
|
|
|
qreal m_bias;
|
|
|
|
QColor m_front;
|
|
|
|
QColor m_back;
|
|
|
|
QMap<int, ColorEntry> m_colors;
|
2015-08-20 05:19:03 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
class LogColorCache : public ColorCache
|
|
|
|
{
|
|
|
|
public:
|
2018-07-15 18:21:05 +05:30
|
|
|
LogColorCache(QColor front, QColor back)
|
|
|
|
: ColorCache(front, back, 1.0)
|
|
|
|
{
|
2021-10-18 04:17:02 +05:30
|
|
|
addColor((int)MessageLevel::Launcher, QColor("purple"));
|
2018-07-15 18:21:05 +05:30
|
|
|
addColor((int)MessageLevel::Debug, QColor("green"));
|
|
|
|
addColor((int)MessageLevel::Warning, QColor("orange"));
|
|
|
|
addColor((int)MessageLevel::Error, QColor("red"));
|
|
|
|
addColor((int)MessageLevel::Fatal, QColor("red"));
|
|
|
|
addColor((int)MessageLevel::Message, front);
|
|
|
|
}
|
2015-08-20 05:19:03 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
QColor getFront(MessageLevel::Enum level)
|
|
|
|
{
|
|
|
|
if(!m_colors.contains((int) level))
|
|
|
|
{
|
|
|
|
return ColorCache::getFront((int)MessageLevel::Message);
|
|
|
|
}
|
|
|
|
return ColorCache::getFront((int)level);
|
|
|
|
}
|
2015-08-20 05:19:03 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
QColor getBack(MessageLevel::Enum level)
|
|
|
|
{
|
|
|
|
if(level == MessageLevel::Fatal)
|
|
|
|
{
|
|
|
|
return QColor(Qt::black);
|
|
|
|
}
|
|
|
|
return QColor(Qt::transparent);
|
|
|
|
}
|
2015-08-20 05:19:03 +05:30
|
|
|
};
|