Commit 03a023bc authored by Martin Seher's avatar Martin Seher Committed by Milian Wolff
Browse files

Introduce HighlightUses for ConfigurableColors

Move the code from the ContextBrowserPlugin to the ConfigurableColors.
This will make it possible to let users configure this color directly
in the future.
parent 41cb12e4
Pipeline #201499 passed with stage
in 13 minutes and 40 seconds
......@@ -52,6 +52,7 @@ enum class CodeHighlightingType {
MemberVariable,
NamespaceVariable,
GlobalVariable,
HighlightUses,
// Most of these are currently not used:
Argument,
......
......@@ -91,7 +91,7 @@ ColorCache* ColorCache::self()
void ColorCache::generateColors()
{
m_defaultColors->reset(this);
m_defaultColors->reset(this, m_view.data());
// Primary colors taken from: http://colorbrewer2.org/?type=qualitative&scheme=Paired&n=12
const QColor colors[] = {
......
......@@ -12,12 +12,15 @@
#include <debug.h>
#include <KTextEditor/View>
#include <KTextEditor/ConfigInterface>
#define ifDebug(x)
namespace KDevelop {
ConfigurableHighlightingColors::ConfigurableHighlightingColors()
{
reset(nullptr);
reset(nullptr, nullptr);
}
ConfigurableHighlightingColors::~ConfigurableHighlightingColors() = default;
......@@ -27,7 +30,7 @@ KTextEditor::Attribute::Ptr ConfigurableHighlightingColors::attribute(CodeHighli
return m_attributes[type];
}
void ConfigurableHighlightingColors::reset(ColorCache* cache)
void ConfigurableHighlightingColors::reset(ColorCache* cache, KTextEditor::View* view)
{
m_attributes.clear();
auto addColor = [&](CodeHighlightingType type, QRgb color_) {
......@@ -35,7 +38,8 @@ void ConfigurableHighlightingColors::reset(ColorCache* cache)
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();)
ifDebug(qCDebug(LANGUAGE) << #type << "color: " << #color_ << "->" << a->foreground().color().name());
return a;
};
// 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.
addColor(CodeHighlightingType::Class, 0x005912); // Dark green
......@@ -57,5 +61,19 @@ void ConfigurableHighlightingColors::reset(ColorCache* cache)
addColor(CodeHighlightingType::ForwardDeclaration, 0x5C5C5C); // Gray
addColor(CodeHighlightingType::Macro, 0xA41239);
addColor(CodeHighlightingType::MacroFunctionLike, 0x008080);
{
auto highlightUses = addColor(CodeHighlightingType::HighlightUses, 0xffffff);
highlightUses->setDefaultStyle(KTextEditor::dsNormal);
highlightUses->setForeground(highlightUses->selectedForeground());
highlightUses->setBackground(highlightUses->selectedBackground());
highlightUses->setBackgroundFillWhitespace(true);
if (auto iface = qobject_cast<KTextEditor::ConfigInterface*>(view)) {
const auto highlightUsesColor
= iface->configValue(QStringLiteral("search-highlight-color")).value<QColor>();
highlightUses->setBackground(highlightUsesColor);
}
}
}
}
......@@ -15,6 +15,11 @@
#include <KTextEditor/Attribute>
namespace KTextEditor
{
class View;
}
namespace KDevelop {
class ColorCache;
......@@ -24,7 +29,7 @@ public:
explicit ConfigurableHighlightingColors();
~ConfigurableHighlightingColors();
void reset(ColorCache* cache);
void reset(ColorCache* cache, KTextEditor::View* view);
KTextEditor::Attribute::Ptr attribute(CodeHighlightingType type) const;
......
......@@ -42,6 +42,8 @@
#include <language/interfaces/iquickopen.h>
#include <language/highlighting/colorcache.h>
#include <language/highlighting/configurablecolors.h>
#include <language/highlighting/codehighlighting.h>
#include <language/duchain/duchain.h>
#include <language/duchain/ducontext.h>
......@@ -712,17 +714,10 @@ void ContextBrowserPlugin::clearMouseHover()
m_mouseHoverDocument.clear();
}
Attribute::Ptr ContextBrowserPlugin::highlightedUseAttribute(KTextEditor::View* view) const
Attribute::Ptr ContextBrowserPlugin::highlightedUseAttribute() const
{
if (!m_highlightAttribute) {
m_highlightAttribute = Attribute::Ptr(new Attribute());
m_highlightAttribute->setDefaultStyle(KTextEditor::dsNormal);
m_highlightAttribute->setForeground(m_highlightAttribute->selectedForeground());
m_highlightAttribute->setBackgroundFillWhitespace(true);
auto iface = qobject_cast<KTextEditor::ConfigInterface*>(view);
auto background = iface->configValue(QStringLiteral("search-highlight-color")).value<QColor>();
m_highlightAttribute->setBackground(background);
m_highlightAttribute = ColorCache::self()->defaultColors()->attribute(CodeHighlightingType::HighlightUses);
}
return m_highlightAttribute;
}
......@@ -732,9 +727,9 @@ void ContextBrowserPlugin::colorSetupChanged()
m_highlightAttribute = Attribute::Ptr();
}
Attribute::Ptr ContextBrowserPlugin::highlightedSpecialObjectAttribute(KTextEditor::View* view) const
Attribute::Ptr ContextBrowserPlugin::highlightedSpecialObjectAttribute() const
{
return highlightedUseAttribute(view);
return highlightedUseAttribute();
}
void ContextBrowserPlugin::addHighlight(View* view, KDevelop::Declaration* decl)
......@@ -750,7 +745,7 @@ void ContextBrowserPlugin::addHighlight(View* view, KDevelop::Declaration* decl)
// Highlight the declaration
highlights.highlights << decl->createRangeMoving();
highlights.highlights.back()->setAttribute(highlightedUseAttribute(view));
highlights.highlights.back()->setAttribute(highlightedUseAttribute());
highlights.highlights.back()->setZDepth(highlightingZDepth);
// Highlight uses
......@@ -761,7 +756,7 @@ void ContextBrowserPlugin::addHighlight(View* view, KDevelop::Declaration* decl)
const auto& documentUses = fileIt.value();
for (auto& use : documentUses) {
highlights.highlights << PersistentMovingRange::Ptr(new PersistentMovingRange(use, document));
highlights.highlights.back()->setAttribute(highlightedUseAttribute(view));
highlights.highlights.back()->setAttribute(highlightedUseAttribute());
highlights.highlights.back()->setZDepth(highlightingZDepth);
}
}
......@@ -769,7 +764,7 @@ void ContextBrowserPlugin::addHighlight(View* view, KDevelop::Declaration* decl)
if (auto* def = FunctionDefinition::definition(decl)) {
highlights.highlights << def->createRangeMoving();
highlights.highlights.back()->setAttribute(highlightedUseAttribute(view));
highlights.highlights.back()->setAttribute(highlightedUseAttribute());
highlights.highlights.back()->setZDepth(highlightingZDepth);
}
}
......@@ -859,7 +854,7 @@ void ContextBrowserPlugin::updateForView(View* view)
if (allowHighlight) {
highlights.highlights <<
PersistentMovingRange::Ptr(new PersistentMovingRange(specialRange, IndexedString(url)));
highlights.highlights.back()->setAttribute(highlightedSpecialObjectAttribute(view));
highlights.highlights.back()->setAttribute(highlightedSpecialObjectAttribute());
highlights.highlights.back()->setZDepth(highlightingZDepth);
}
if (updateBrowserView)
......
......@@ -108,8 +108,8 @@ public:
void showUses(const KDevelop::DeclarationPointer& declaration) override;
KTextEditor::Attribute::Ptr highlightedUseAttribute(KTextEditor::View* view) const;
KTextEditor::Attribute::Ptr highlightedSpecialObjectAttribute(KTextEditor::View* view) const;
KTextEditor::Attribute::Ptr highlightedUseAttribute() const;
KTextEditor::Attribute::Ptr highlightedSpecialObjectAttribute() const;
public Q_SLOTS:
void showUsesDelayed(const KDevelop::DeclarationPointer& declaration);
......
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