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

◆ 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.

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 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.

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 /‍** *‍/ comments.

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 75 of file theme.h.

Property Documentation

◆ name

QString KSyntaxHighlighting::Theme::name
read

Definition at line 67 of file theme.h.

◆ translatedName

QString KSyntaxHighlighting::Theme::translatedName
read

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)
default

Copy constructor, sharing the Theme data with copy.

◆ ~Theme()

Theme::~Theme ( )
default

Destructor.

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
translatedName()

Definition at line 42 of file theme.cpp.

◆ operator=()

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

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 Nov 22 2024 12:10:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.