Commit 25c84e56 authored by Milian Wolff's avatar Milian Wolff
Browse files

Simplify ConfigurableHighlightingColors

Remove the CodeHighlightingColors and instead streamline
ConfigurableHighlightingColors and just use that one directly.
Also don't recreate that instance all the time - rebuilding the
attribute hash is sufficient.
parent be873c43
......@@ -34,7 +34,7 @@ ColorCache* ColorCache::m_self = nullptr;
ColorCache::ColorCache(QObject* parent)
: QObject(parent)
, m_defaultColors(nullptr)
, m_defaultColors(new ConfigurableHighlightingColors)
, m_validColorCount(0)
, m_colorOffset(0)
, m_localColorRatio(0)
......@@ -91,11 +91,7 @@ ColorCache* ColorCache::self()
void ColorCache::generateColors()
{
if (m_defaultColors) {
delete m_defaultColors;
}
m_defaultColors = new CodeHighlightingColors(this);
m_defaultColors->reset(this);
// Primary colors taken from: http://colorbrewer2.org/?type=qualitative&scheme=Paired&n=12
const QColor colors[] = {
......@@ -302,9 +298,8 @@ QColor ColorCache::blendLocalColor(QColor color) const
return blend(color, m_localColorRatio);
}
CodeHighlightingColors* ColorCache::defaultColors() const
ConfigurableHighlightingColors* ColorCache::defaultColors() const
{
Q_ASSERT(m_defaultColors);
return m_defaultColors;
}
......
......@@ -20,7 +20,7 @@ class View;
}
namespace KDevelop {
class CodeHighlightingColors;
class ConfigurableHighlightingColors;
class IDocument;
/**
......@@ -62,7 +62,7 @@ public:
QColor blendGlobalColor(QColor color) const;
/// access the default colors
CodeHighlightingColors* defaultColors() const;
ConfigurableHighlightingColors* defaultColors() const;
/**
* @returns a primary color if @p num less primaryColorCount and a supplementary color if @p num >= primaryColorCount and < validColorCount
......@@ -127,7 +127,7 @@ private:
void updateColorsFromView(KTextEditor::View* view);
/// the default colors for the different types
CodeHighlightingColors* m_defaultColors;
ConfigurableHighlightingColors* m_defaultColors;
/// the generated colors
QVector<QColor> m_colors;
......
......@@ -8,7 +8,6 @@
#include "configurablecolors.h"
#include "codehighlighting.h"
#include "colorcache.h"
#include <debug.h>
......@@ -16,60 +15,45 @@
#define ifDebug(x)
namespace KDevelop {
KTextEditor::Attribute::Ptr ConfigurableHighlightingColors::defaultAttribute() const
ConfigurableHighlightingColors::ConfigurableHighlightingColors()
{
return m_defaultAttribute;
reset(nullptr);
}
void ConfigurableHighlightingColors::setDefaultAttribute(const KTextEditor::Attribute::Ptr& defaultAttrib)
{
m_defaultAttribute = defaultAttrib;
}
ConfigurableHighlightingColors::~ConfigurableHighlightingColors() = default;
KTextEditor::Attribute::Ptr ConfigurableHighlightingColors::attribute(CodeHighlightingType type) const
{
return m_attributes[type];
}
void ConfigurableHighlightingColors::addAttribute(CodeHighlightingType type,
const KTextEditor::Attribute::Ptr& attribute)
{
m_attributes[type] = attribute;
}
ConfigurableHighlightingColors::ConfigurableHighlightingColors()
{
KTextEditor::Attribute::Ptr a(new KTextEditor::Attribute);
setDefaultAttribute(a);
}
#define ADD_COLOR(type, color_) \
{ \
KTextEditor::Attribute::Ptr a(new KTextEditor::Attribute); \
a->setForeground(QColor(cache->blendGlobalColor(color_))); \
addAttribute(CodeHighlightingType::type, a); \
ifDebug(qCDebug(LANGUAGE) << #type << "color: " << #color_ << "->" << a->foreground().color().name();) \
}
CodeHighlightingColors::CodeHighlightingColors(ColorCache* cache) : ConfigurableHighlightingColors()
void ConfigurableHighlightingColors::reset(ColorCache* cache)
{
m_attributes.clear();
auto addColor = [&](CodeHighlightingType type, QRgb color_) {
auto color = QColor::fromRgb(color_);
KTextEditor::Attribute::Ptr a(new KTextEditor::Attribute);
a->setForeground(cache ? cache->blendGlobalColor(color) : color);
m_attributes[type] = a;
ifDebug(qCDebug(LANGUAGE) << #type << "color: " << #color_ << "->" << a->foreground().color().name();)
};
// TODO: The set of colors doesn't work very well. Many colors simply too dark (even on the maximum "Global colorization intensity" they hardly distinguishable from grey) and look alike.
ADD_COLOR(Class, 0x005912) // Dark green
ADD_COLOR(TypeAlias, 0x35938d)
ADD_COLOR(Enum, 0x6c101e) // Dark red
ADD_COLOR(Enumerator, 0x862a38) // Greyish red
ADD_COLOR(Function, 0x21005A) // Navy blue
ADD_COLOR(MemberVariable, 0x443069) // Dark Burple (blue/purple)
ADD_COLOR(LocalClassMember, 0xae7d00) // Light orange
ADD_COLOR(InheritedClassMember, 0x705000) // Dark orange
ADD_COLOR(LocalVariable, 0x0C4D3C)
ADD_COLOR(FunctionVariable, 0x300085) // Less dark navy blue
ADD_COLOR(NamespaceVariable, 0x9F3C5F) // Rose
ADD_COLOR(GlobalVariable, 0x12762B) // Grass green
ADD_COLOR(Namespace, 0x6B2840) // Dark rose
ADD_COLOR(ErrorVariable, 0x8b0019) // Pure red
ADD_COLOR(ForwardDeclaration, 0x5C5C5C) // Gray
ADD_COLOR(Macro, 0xA41239)
ADD_COLOR(MacroFunctionLike, 0x008080)
addColor(CodeHighlightingType::Class, 0x005912); // Dark green
addColor(CodeHighlightingType::TypeAlias, 0x35938d);
addColor(CodeHighlightingType::Enum, 0x6c101e); // Dark red
addColor(CodeHighlightingType::Enumerator, 0x862a38); // Greyish red
addColor(CodeHighlightingType::Function, 0x21005A); // Navy blue
addColor(CodeHighlightingType::MemberVariable, 0x443069); // Dark Burple (blue/purple)
addColor(CodeHighlightingType::LocalClassMember, 0xae7d00); // Light orange
addColor(CodeHighlightingType::InheritedClassMember, 0x705000); // Dark orange
addColor(CodeHighlightingType::LocalVariable, 0x0C4D3C);
addColor(CodeHighlightingType::FunctionVariable, 0x300085); // Less dark navy blue
addColor(CodeHighlightingType::NamespaceVariable, 0x9F3C5F); // Rose
addColor(CodeHighlightingType::GlobalVariable, 0x12762B); // Grass green
addColor(CodeHighlightingType::Namespace, 0x6B2840); // Dark rose
addColor(CodeHighlightingType::ErrorVariable, 0x8b0019); // Pure red
addColor(CodeHighlightingType::ForwardDeclaration, 0x5C5C5C); // Gray
addColor(CodeHighlightingType::Macro, 0xA41239);
addColor(CodeHighlightingType::MacroFunctionLike, 0x008080);
}
}
......@@ -22,29 +22,14 @@ class KDEVPLATFORMLANGUAGE_EXPORT ConfigurableHighlightingColors
{
public:
explicit ConfigurableHighlightingColors();
~ConfigurableHighlightingColors();
void addAttribute(CodeHighlightingType type, const KTextEditor::Attribute::Ptr& attribute);
void reset(ColorCache* cache);
KTextEditor::Attribute::Ptr attribute(CodeHighlightingType type) const;
void setDefaultAttribute(const KTextEditor::Attribute::Ptr& defaultAttrib);
KTextEditor::Attribute::Ptr defaultAttribute() const;
private:
KTextEditor::Attribute::Ptr m_defaultAttribute;
QHash<int, KTextEditor::Attribute::Ptr> m_attributes;
QHash<CodeHighlightingType, KTextEditor::Attribute::Ptr> m_attributes;
QString m_highlightingName;
};
// ######### start CodeHighlightingColors
class CodeHighlightingColors
: public ConfigurableHighlightingColors
{
public:
explicit CodeHighlightingColors(ColorCache* cache);
};
}
......
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