File indexing completed on 2024-05-12 04:38:07

0001 /*
0002     SPDX-FileCopyrightText: 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
0003     SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>
0004     SPDX-FileCopyrightText: 2009 Milian Wolff <mail@milianw.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #include "configurablecolors.h"
0010 
0011 #include "colorcache.h"
0012 
0013 #include <debug.h>
0014 
0015 #include <KTextEditor/View>
0016 #include <KSyntaxHighlighting/Theme>
0017 
0018 #define ifDebug(x)
0019 
0020 namespace KDevelop {
0021 ConfigurableHighlightingColors::ConfigurableHighlightingColors()
0022 {
0023     reset(nullptr, nullptr);
0024 }
0025 
0026 ConfigurableHighlightingColors::~ConfigurableHighlightingColors() = default;
0027 
0028 KTextEditor::Attribute::Ptr ConfigurableHighlightingColors::attribute(CodeHighlightingType type) const
0029 {
0030     return m_attributes[type];
0031 }
0032 
0033 void ConfigurableHighlightingColors::reset(ColorCache* cache, KTextEditor::View* view)
0034 {
0035     m_attributes.clear();
0036     auto createAttribute = [&](CodeHighlightingType type) {
0037         KTextEditor::Attribute::Ptr a(new KTextEditor::Attribute);
0038         m_attributes[type] = a;
0039         return a;
0040     };
0041     auto addColor = [&](CodeHighlightingType type, QRgb color_) {
0042         auto a = createAttribute(type);
0043         auto color = QColor::fromRgb(color_);
0044         a->setForeground(cache ? cache->blendGlobalColor(color) : color);
0045         ifDebug(qCDebug(LANGUAGE) << #type << "color: " << #color_ << "->" << a->foreground().color().name());
0046     };
0047     // 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.
0048     addColor(CodeHighlightingType::Class, 0x005912); // Dark green
0049     addColor(CodeHighlightingType::TypeAlias, 0x35938d);
0050     addColor(CodeHighlightingType::Enum, 0x6c101e); // Dark red
0051     addColor(CodeHighlightingType::Enumerator, 0x862a38); // Greyish red
0052     addColor(CodeHighlightingType::Function, 0x21005A); // Navy blue
0053     addColor(CodeHighlightingType::MemberVariable, 0x443069); // Dark Burple (blue/purple)
0054     addColor(CodeHighlightingType::LocalClassMember, 0xae7d00); // Light orange
0055     addColor(CodeHighlightingType::LocalMemberFunction, 0xae7d00);
0056     addColor(CodeHighlightingType::InheritedClassMember, 0x705000); // Dark orange
0057     addColor(CodeHighlightingType::InheritedMemberFunction, 0x705000);
0058     addColor(CodeHighlightingType::LocalVariable, 0x0C4D3C);
0059     addColor(CodeHighlightingType::FunctionVariable, 0x300085); // Less dark navy blue
0060     addColor(CodeHighlightingType::NamespaceVariable, 0x9F3C5F); // Rose
0061     addColor(CodeHighlightingType::GlobalVariable, 0x12762B); // Grass green
0062     addColor(CodeHighlightingType::Namespace, 0x6B2840); // Dark rose
0063     addColor(CodeHighlightingType::ForwardDeclaration, 0x5C5C5C); // Gray
0064     addColor(CodeHighlightingType::Macro, 0xA41239);
0065     addColor(CodeHighlightingType::MacroFunctionLike, 0x008080);
0066 
0067     {
0068         auto highlightUses = createAttribute(CodeHighlightingType::HighlightUses);
0069         highlightUses->setDefaultStyle(KTextEditor::dsNormal);
0070         highlightUses->setForeground(highlightUses->selectedForeground());
0071         highlightUses->setBackground(highlightUses->selectedBackground());
0072         highlightUses->setBackgroundFillWhitespace(true);
0073         if (view) {
0074             const auto searchHighlight = view->theme().editorColor(KSyntaxHighlighting::Theme::SearchHighlight);
0075             highlightUses->setBackground(QColor::fromRgb(searchHighlight));
0076         }
0077     }
0078     {
0079         auto error = createAttribute(CodeHighlightingType::Error);
0080         error->setDefaultStyle(KTextEditor::dsError);
0081     }
0082 }
0083 }