Commit 6c2ef5e8 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 0742a321
......@@ -52,6 +52,7 @@ enum class CodeHighlightingType {
MemberVariable,
NamespaceVariable,
GlobalVariable,
HighlightUses,
// Most of these are currently not used:
Argument,
......
......@@ -152,6 +152,12 @@ void ColorCache::updateColorsFromView(KTextEditor::View* view)
return;
}
auto iface = qobject_cast<KTextEditor::ConfigInterface*>(view);
Q_ASSERT(iface);
const auto highlightUsesColor = iface->configValue(QStringLiteral("search-highlight-color")).value<QColor>();
m_defaultColors->attribute(CodeHighlightingType::HighlightUses)->setBackground(highlightUsesColor);
QColor foreground(QColor::Invalid);
QColor background(QColor::Invalid);
......@@ -161,14 +167,9 @@ void ColorCache::updateColorsFromView(KTextEditor::View* view)
background = style->background().color();
}
// FIXME: this is in kateview
// qCDebug(LANGUAGE) << "got foreground:" << foreground.name() << "old is:" << m_foregroundColor.name();
//NOTE: this slot is defined in KatePart > 4.4, see ApiDocs of the ConfigInterface
// the signal is not defined in ConfigInterface, but according to the docs it should be
// can't use new signal slot syntax here, since ConfigInterface is not a QObject
if (KTextEditor::View* view = m_view.data()) {
Q_ASSERT(qobject_cast<KTextEditor::ConfigInterface*>(view));
// we only listen to a single view, i.e. the active one
#if KTEXTEDITOR_VERSION >= QT_VERSION_CHECK(5, 79, 0)
disconnect(view, &KTextEditor::View::configChanged, this, &ColorCache::slotViewSettingsChanged);
......@@ -176,7 +177,6 @@ void ColorCache::updateColorsFromView(KTextEditor::View* view)
disconnect(view, SIGNAL(configChanged()), this, SLOT(slotViewSettingsChanged()));
#endif
}
Q_ASSERT(qobject_cast<KTextEditor::ConfigInterface*>(view));
#if KTEXTEDITOR_VERSION >= QT_VERSION_CHECK(5, 79, 0)
connect(view, &KTextEditor::View::configChanged, this, &ColorCache::slotViewSettingsChanged);
#else
......
......@@ -35,7 +35,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 +58,12 @@ 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->setBackgroundFillWhitespace(true);
}
}
}
......@@ -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