Search for usage in LXR

KSyntaxHighlighting::Theme Class Reference

#include <theme.h>

Public Types

enum  EditorColorRole {
  BackgroundColor = 0 , TextSelection , CurrentLine , SearchHighlight ,
  ReplaceHighlight , BracketMatching , TabMarker , SpellChecking ,
  IndentationLine , IconBorder , CodeFolding , LineNumbers ,
  CurrentLineNumber , WordWrapMarker , ModifiedLines , SavedLines ,
  Separator , MarkBookmark , MarkBreakpointActive , MarkBreakpointReached ,
  MarkBreakpointDisabled , MarkExecution , MarkWarning , MarkError ,
  TemplateBackground , TemplatePlaceholder , TemplateFocusedPlaceholder , TemplateReadOnlyPlaceholder
enum  TextStyle {
  Normal = 0 , Keyword , Function , Variable ,
  ControlFlow , Operator , BuiltIn , Extension ,
  Preprocessor , Attribute , Char , SpecialChar ,
  String , VerbatimString , SpecialString , Import ,
  DataType , DecVal , BaseN , Float ,
  Constant , Comment , Documentation , Annotation ,
  CommentVar , RegionMarker , Information , Warning ,
  Alert , Error , Others


QString name
QString translatedName

Public Member Functions

 Theme ()
 Theme (const Theme &copy)
 ~Theme ()
QRgb backgroundColor (TextStyle style) const
QRgb editorColor (EditorColorRole role) const
QString filePath () const
bool isBold (TextStyle style) const
bool isItalic (TextStyle style) const
bool isReadOnly () const
bool isStrikeThrough (TextStyle style) const
bool isUnderline (TextStyle style) const
bool isValid () const
QString name () const
Themeoperator= (const Theme &other)
QRgb selectedBackgroundColor (TextStyle style) const
QRgb selectedTextColor (TextStyle style) const
QRgb textColor (TextStyle style) const
QString translatedName () const

Detailed Description

Color theme definition used for highlighting.


The Theme provides a full color theme for painting the highlighted text. One Theme is defined either as a *.theme file on disk, or as a file compiled into the SyntaxHighlighting library by using Qt's resource system. Each Theme has a unique name(), including a translatedName() if put into the UI. Themes shipped by default are typically read-only, see isReadOnly().

A Theme defines two sets of colors:

  • Text colors, including foreground and background colors, colors for selected text, and properties such as bold and italic. These colors are used e.g. by the SyntaxHighlighter.
  • Editor colors, including a background color for the entire editor widget, the line number color, code folding colors, etc.

Text Colors and the Class Format

The text colors are used for syntax highlighting. // TODO: elaborate more and explain relation to Format class

Editor Colors

If you want to use the SyntaxHighlighting framework to write your own text editor, you also need to paint the background of the editing widget. In addition, the editor may support showing line numbers, a folding bar, a highlight for the current text line, and similar features. All these colors are defined in terms of the "editor colors" and accessible by calling editorColor() with the desired enum EditorColorRole.

Accessing a Theme

All available Themes are accessed through the Repository. These themes are typically valid themes. If you create a Theme on your own, isValid() will return false, and all colors provided by this Theme are in fact invalid and therefore unusable.

See also

Definition at line 64 of file theme.h.

Member Enumeration Documentation

◆ EditorColorRole

Editor color roles, used to paint line numbers, editor background etc.

The colors typically should have good contrast with the colors used in the TextStyles.


Background color for the editing area.


Background color for selected text.


Background color for the line of the current text cursor.


Background color for matching text while searching.


Background color for replaced text for a search & replace action.


Background color for matching bracket pairs (including quotes)


Foreground color for visualizing tabs and trailing spaces.


Color used to underline spell check errors.


Color used to draw vertical indentation levels, typically a line.


Background color for the icon border.


Background colors for code folding regions in the text area, as well as code folding indicators in the code folding border.


Foreground color for drawing the line numbers.

This should have a good contrast with the IconBorder background color.


Foreground color for drawing the current line number.

This should have a good contrast with the IconBorder background color.


Color used in the icon border to indicate dynamically wrapped lines.

This color should have a good contrast with the IconBorder background color.


Color used to draw a vertical line for marking changed lines.


Color used to draw a vertical line for marking saved lines.


Line color used to draw separator lines, e.g.

at column 80 in the text editor area.


Background color for bookmarks.


Background color for active breakpoints.


Background color for a reached breakpoint.


Background color for inactive (disabled) breakpoints.


Background color for marking the current execution position.


Background color for general warning marks.


Background color for general error marks.


Background color for text templates (snippets).


Background color for all editable placeholders in text templates.


Background color for the currently active placeholder in text templates.


Background color for read-only placeholders in text templates.

Definition at line 158 of file theme.h.

◆ TextStyle

Default styles that can be referenced from syntax definition XML files.

Make sure to choose readable colors with good contrast especially in combination with the EditorColorRoles.


Default text style for normal text and source code without special highlighting.


Text style for language keywords.


Text style for function definitions and function calls.


Text style for variables, if applicable.

For instance, variables in PHP typically start with a '$', so all identifiers following the pattern $foo are highlighted as variable.


Text style for control flow highlighting, such as if, then, else, return, or continue.


Text style for operators such as +, -, *, / and :: etc.


Text style for built-in language classes and functions.


Text style for well-known extensions, such as Qt or boost.


Text style for preprocessor statements.


Text style for attributes of functions or objects, e.g.

@override in Java, or declspec(...) and __attribute((...)) in C++.


Text style for single characters such as 'a'.


Text style for escaped characters in strings, such as "hello\n".


Text style for strings, for instance "hello world".


Text style for verbatim strings such as HERE docs.


Text style for special strings such as regular expressions in ECMAScript or the LaTeX math mode.


Text style for includes, imports, modules, or LaTeX packages.


Text style for data types such as int, char, float etc.


Text style for decimal values.


Text style for numbers with base other than 10.


Text style for floating point numbers.


Text style for language constants, e.g.

True, False, None in Python or nullptr in C/C++.


Text style for normal comments.


Text style for comments that reflect API documentation, such as doxygen /‍** *‍/ comments.


Text style for annotations in comments, such as @param in Doxygen or JavaDoc.


Text style that refers to variables in a comment, such as after @param <identifier> in Doxygen or JavaDoc.


Text style for region markers, typically defined by BEGIN/END.


Text style for information, such as the keyword @note in Doxygen.


Text style for warnings, such as the keyword @warning in Doxygen.


Text style for comment specials such as TODO and WARNING in comments.


Text style indicating wrong syntax.


Text style for attributes that do not match any of the other default styles.

Definition at line 75 of file theme.h.

Property Documentation

◆ name

QString KSyntaxHighlighting::Theme::name

Definition at line 67 of file theme.h.

◆ translatedName

QString KSyntaxHighlighting::Theme::translatedName

Definition at line 68 of file theme.h.

Constructor & Destructor Documentation

◆ Theme() [1/2]

Theme::Theme ( )

Default constructor, creating an invalid Theme, see isValid().

Definition at line 21 of file theme.cpp.

◆ Theme() [2/2]

Theme::Theme ( const Theme & copy)

Copy constructor, sharing the Theme data with copy.

◆ ~Theme()

Theme::~Theme ( )


Member Function Documentation

◆ backgroundColor()

QRgb Theme::backgroundColor ( TextStyle style) const

Returns the background color to be used for style.

0 is returned for styles that do not specify a background color, use the default background color in that case.

Definition at line 72 of file theme.cpp.

◆ editorColor()

QRgb Theme::editorColor ( EditorColorRole role) const

Returns the editor color for the requested role.

Definition at line 102 of file theme.cpp.

◆ filePath()

QString Theme::filePath ( ) const

Returns the full path and file name to this Theme.

Themes from the Qt resource return the Qt resource path. Themes from disk return the local path.

If the theme is invalid (isValid()), an empty string is returned.

Definition at line 57 of file theme.cpp.

◆ isBold()

bool Theme::isBold ( TextStyle style) const

Returns whether the given style should be shown in bold.

Definition at line 82 of file theme.cpp.

◆ isItalic()

bool Theme::isItalic ( TextStyle style) const

Returns whether the given style should be shown in italic.

Definition at line 87 of file theme.cpp.

◆ isReadOnly()

bool Theme::isReadOnly ( ) const

Returns true if this Theme is read-only.

A Theme is read-only, if the filePath() points to a non-writable file. This is typically the case for Themes that are compiled into the executable as resource file, as well as for theme files that are installed in read-only system locations (e.g. /usr/share/).

Definition at line 52 of file theme.cpp.

◆ isStrikeThrough()

bool Theme::isStrikeThrough ( TextStyle style) const

Returns whether the given style should be shown struck through.

Definition at line 97 of file theme.cpp.

◆ isUnderline()

bool Theme::isUnderline ( TextStyle style) const

Returns whether the given style should be shown underlined.

Definition at line 92 of file theme.cpp.

◆ isValid()

bool Theme::isValid ( ) const

Returns true if this is a valid Theme.

If the theme is invalid, none of the returned colors are well-defined.

Definition at line 37 of file theme.cpp.

◆ name()

QString Theme::name ( ) const

Returns the unique name of this Theme.

See also

Definition at line 42 of file theme.cpp.

◆ operator=()

Theme & Theme::operator= ( const Theme & other)

Assignment operator, sharing the Theme data with other.

◆ selectedBackgroundColor()

QRgb Theme::selectedBackgroundColor ( TextStyle style) const

Returns the background color to be used for selected text for style.

0 is returned for styles that do not specify a background color, use the default backgroundColor() in that case.

Definition at line 77 of file theme.cpp.

◆ selectedTextColor()

QRgb Theme::selectedTextColor ( TextStyle style) const

Returns the selected text color to be used for style.

0 is returned for styles that do not specify a selected text color, use the default textColor() in that case.

Definition at line 67 of file theme.cpp.

◆ textColor()

QRgb Theme::textColor ( TextStyle style) const

Returns the text color to be used for style.

0 is returned for styles that do not specify a text color, use the default text color in that case.

Definition at line 62 of file theme.cpp.

◆ translatedName()

QString Theme::translatedName ( ) const

Returns the translated name of this Theme.

The translated name can be used in the user interface.

Definition at line 47 of file theme.cpp.

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 12 2024 12:01:42 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.