KSyntaxHighlighting::Theme

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
}
 

Properties

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.

Introduction

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
Format
Since
5.28

Definition at line 64 of file theme.h.

Member Enumeration Documentation

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.

Enumerator
BackgroundColor 

Background color for the editing area.

TextSelection 

Background color for selected text.

CurrentLine 

Background color for the line of the current text cursor.

SearchHighlight 

Background color for matching text while searching.

ReplaceHighlight 

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

BracketMatching 

Background color for matching bracket pairs (including quotes)

TabMarker 

Foreground color for visualizing tabs and trailing spaces.

SpellChecking 

Color used to underline spell check errors.

IndentationLine 

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

IconBorder 

Background color for the icon border.

CodeFolding 

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

LineNumbers 

Foreground color for drawing the line numbers.

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

CurrentLineNumber 

Foreground color for drawing the current line number.

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

WordWrapMarker 

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

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

ModifiedLines 

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

SavedLines 

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

Separator 

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

at column 80 in the text editor area.

MarkBookmark 

Background color for bookmarks.

MarkBreakpointActive 

Background color for active breakpoints.

MarkBreakpointReached 

Background color for a reached breakpoint.

MarkBreakpointDisabled 

Background color for inactive (disabled) breakpoints.

MarkExecution 

Background color for marking the current execution position.

MarkWarning 

Background color for general warning marks.

MarkError 

Background color for general error marks.

TemplateBackground 

Background color for text templates (snippets).

TemplatePlaceholder 

Background color for all editable placeholders in text templates.

TemplateFocusedPlaceholder 

Background color for the currently active placeholder in text templates.

TemplateReadOnlyPlaceholder 

Background color for read-only placeholders in text templates.

Definition at line 163 of file theme.h.

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.

Enumerator
Normal 

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

Keyword 

Text style for language keywords.

Function 

Text style for function definitions and function calls.

Variable 

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.

ControlFlow 

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

Operator 

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

BuiltIn 

Text style for built-in language classes and functions.

Extension 

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

Preprocessor 

Text style for preprocessor statements.

Attribute 

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

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

Char 

Text style for single characters such as 'a'.

SpecialChar 

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

String 

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

VerbatimString 

Text style for verbatim strings such as HERE docs.

SpecialString 

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

Import 

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

DataType 

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

DecVal 

Text style for decimal values.

BaseN 

Text style for numbers with base other than 10.

Float 

Text style for floating point numbers.

Constant 

Text style for language constants, e.g.

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

Comment 

Text style for normal comments.

Documentation 

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

Annotation 

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

CommentVar 

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

RegionMarker 

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

Information 

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

Warning 

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

Alert 

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

Error 

Text style indicating wrong syntax.

Others 

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

Definition at line 80 of file theme.h.

Constructor & Destructor Documentation

Theme::Theme ( )

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

Definition at line 14 of file theme.cpp.

Theme::Theme ( const Theme copy)

Copy constructor, sharing the Theme data with copy.

Definition at line 18 of file theme.cpp.

Theme::~Theme ( )

Destructor.

Definition at line 28 of file theme.cpp.

Member Function Documentation

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 73 of file theme.cpp.

QRgb Theme::editorColor ( EditorColorRole  role) const

Returns the editor color for the requested role.

Definition at line 103 of file theme.cpp.

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 58 of file theme.cpp.

bool Theme::isBold ( TextStyle  style) const

Returns whether the given style should be shown in bold.

Definition at line 83 of file theme.cpp.

bool Theme::isItalic ( TextStyle  style) const

Returns whether the given style should be shown in italic.

Definition at line 88 of file theme.cpp.

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 53 of file theme.cpp.

bool Theme::isStrikeThrough ( TextStyle  style) const

Returns whether the given style should be shown struck through.

Definition at line 98 of file theme.cpp.

bool Theme::isUnderline ( TextStyle  style) const

Returns whether the given style should be shown underlined.

Definition at line 93 of file theme.cpp.

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 38 of file theme.cpp.

QString KSyntaxHighlighting::Theme::name ( ) const

Returns the unique name of this Theme.

See also
translatedName()
Theme & Theme::operator= ( const Theme other)

Assignment operator, sharing the Theme data with other.

Definition at line 32 of file theme.cpp.

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 78 of file theme.cpp.

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 68 of file theme.cpp.

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 63 of file theme.cpp.

QString KSyntaxHighlighting::Theme::translatedName ( ) const

Returns the translated name of this Theme.

The translated name can be used in the user interface.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Sep 19 2021 23:00:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.