• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • utils
katedefaultcolors.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries and the Kate part.
2  *
3  * Copyright (C) 2014 Milian Wolff <mail@milianw.de>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "katedefaultcolors.h"
22 
23 #include <ktexteditor/markinterface.h>
24 
25 #include <KColorUtils>
26 
27 using namespace Kate;
28 
29 KateDefaultColors::KateDefaultColors()
30  : m_view(QPalette::Active, KColorScheme::View)
31  , m_window(QPalette::Active, KColorScheme::Window)
32  , m_selection(QPalette::Active, KColorScheme::Selection)
33  , m_inactiveSelection(QPalette::Inactive, KColorScheme::Selection)
34  , m_background(m_view.background().color())
35  , m_foreground(m_view.foreground().color())
36  , m_backgroundLuma(KColorUtils::luma(m_background))
37  , m_foregroundLuma(KColorUtils::luma(m_foreground))
38 {
39 }
40 
41 QColor KateDefaultColors::color(ColorRole role) const
42 {
43  switch(role) {
44  case Background:
45  return m_background;
46  case SelectionBackground:
47  return m_selection.background().color();
48  case HighlightedLineBackground:
49  return m_view.background(KColorScheme::AlternateBackground).color();
50  case HighlightedBracket:
51  return KColorUtils::tint(m_background, m_view.decoration(KColorScheme::HoverColor).color());
52  case WordWrapMarker:
53  return KColorUtils::shade(m_background, m_backgroundLuma > 0.3 ? -0.15 : 0.03);
54  case TabMarker:
55  return KColorUtils::shade(m_background, m_backgroundLuma > 0.7 ? -0.35 : 0.3);
56  case IndentationLine:
57  return KColorUtils::shade(m_background, m_backgroundLuma > 0.7 ? -0.35 : 0.3);
58  case IconBar:
59  return m_window.background().color();
60  case CodeFolding:
61  return m_inactiveSelection.background().color();
62  case LineNumber:
63  return m_window.foreground().color();
64  case Separator:
65  return m_view.foreground(KColorScheme::InactiveText).color();
66  case SpellingMistakeLine:
67  return m_view.foreground(KColorScheme::NegativeText).color();
68  case ModifiedLine:
69  return m_view.background(KColorScheme::NegativeBackground).color();
70  case SavedLine:
71  return m_view.background(KColorScheme::PositiveBackground).color();
72  case SearchHighlight:
73  return adaptToScheme(Qt::yellow, BackgroundColor);
74  case ReplaceHighlight:
75  return adaptToScheme(Qt::green, BackgroundColor);
76  case TemplateBackground:
77  return m_window.background().color();
78  case TemplateFocusedEditablePlaceholder:
79  return m_view.background(KColorScheme::PositiveBackground).color();
80  case TemplateEditablePlaceholder:
81  return m_view.background(KColorScheme::PositiveBackground).color();
82  case TemplateNotEditablePlaceholder:
83  return m_view.background(KColorScheme::NegativeBackground).color();
84  }
85  qFatal("Unhandled color requested: %d\n", role);
86  return QColor();
87 }
88 
89 QColor KateDefaultColors::mark(Mark mark) const
90 {
91  // note: the mark color is used as background color at very low opacity (around 0.1)
92  // hence, make sure the color returned here has a high saturation
93  switch (mark) {
94  case Bookmark:
95  return adaptToScheme(Qt::blue, BackgroundColor);
96  case ActiveBreakpoint:
97  return adaptToScheme(Qt::red, BackgroundColor);
98  case ReachedBreakpoint:
99  return adaptToScheme(Qt::yellow, BackgroundColor);
100  case DisabledBreakpoint:
101  return adaptToScheme(Qt::magenta, BackgroundColor);
102  case Execution:
103  return adaptToScheme(Qt::gray, BackgroundColor);
104  case Warning:
105  return m_view.foreground(KColorScheme::NeutralText).color();
106  case Error:
107  return m_view.foreground(KColorScheme::NegativeText).color();
108  }
109  qFatal("Unhandled color for mark requested: %d\n", mark);
110  return QColor();
111 }
112 
113 QColor KateDefaultColors::mark(int i) const
114 {
115  Q_ASSERT(i >= FIRST_MARK && i <= LAST_MARK);
116  return mark(static_cast<Mark>(i));
117 }
118 
119 QColor KateDefaultColors::adaptToScheme(const QColor& color, ColorType type) const
120 {
121  if (m_foregroundLuma > m_backgroundLuma) {
122  // for dark color schemes, produce a fitting color by tinting with the foreground/background color
123  return KColorUtils::tint(type == ForegroundColor ? m_foreground : m_background, color, 0.5);
124  }
125  return color;
126 }
Kate::SearchHighlight
Definition: katedefaultcolors.h:33
KateDefaultColors::adaptToScheme
QColor adaptToScheme(const QColor &color, ColorType type) const
Definition: katedefaultcolors.cpp:119
KateDefaultColors::KateDefaultColors
KateDefaultColors()
Definition: katedefaultcolors.cpp:29
Kate::TemplateNotEditablePlaceholder
Definition: katedefaultcolors.h:52
KateDefaultColors::BackgroundColor
Definition: katedefaultcolors.h:81
KateDefaultColors::color
QColor color(Kate::ColorRole color) const
Definition: katedefaultcolors.cpp:41
Kate::LAST_MARK
Definition: katedefaultcolors.h:65
Kate::IndentationLine
Definition: katedefaultcolors.h:38
Kate::TemplateFocusedEditablePlaceholder
Definition: katedefaultcolors.h:50
Kate::Background
Definition: katedefaultcolors.h:30
Kate::FIRST_MARK
Definition: katedefaultcolors.h:64
Kate::Bookmark
Definition: katedefaultcolors.h:56
Kate::HighlightedLineBackground
Definition: katedefaultcolors.h:32
Kate::HighlightedBracket
Definition: katedefaultcolors.h:36
Kate::ModifiedLine
Definition: katedefaultcolors.h:46
Kate::TemplateBackground
Definition: katedefaultcolors.h:49
Kate::IconBar
Definition: katedefaultcolors.h:42
Kate::ColorRole
ColorRole
Definition: katedefaultcolors.h:28
Kate::ActiveBreakpoint
Definition: katedefaultcolors.h:57
QColor
Kate::TemplateEditablePlaceholder
Definition: katedefaultcolors.h:51
Kate::SavedLine
Definition: katedefaultcolors.h:47
Kate::Mark
Mark
Definition: katedefaultcolors.h:55
Kate::SpellingMistakeLine
Definition: katedefaultcolors.h:39
Kate::CodeFolding
Definition: katedefaultcolors.h:43
KateDefaultColors::mark
QColor mark(Kate::Mark mark) const
Definition: katedefaultcolors.cpp:89
Kate::Separator
Definition: katedefaultcolors.h:45
Kate::ReplaceHighlight
Definition: katedefaultcolors.h:34
Kate::TabMarker
Definition: katedefaultcolors.h:37
Kate::ReachedBreakpoint
Definition: katedefaultcolors.h:58
KateDefaultColors::ColorType
ColorType
Definition: katedefaultcolors.h:79
Kate::WordWrapMarker
Definition: katedefaultcolors.h:41
Kate::Error
Definition: katedefaultcolors.h:62
Kate::Warning
Definition: katedefaultcolors.h:61
Kate::Execution
Definition: katedefaultcolors.h:60
QPalette
KateDefaultColors::ForegroundColor
Definition: katedefaultcolors.h:80
Kate::SelectionBackground
Definition: katedefaultcolors.h:31
Kate::LineNumber
Definition: katedefaultcolors.h:44
Kate::DisabledBreakpoint
Definition: katedefaultcolors.h:59
katedefaultcolors.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal