KSyntaxHighlighting::Theme
#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 ©) | |
~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 |
Theme & | operator= (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
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.
◆ 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. |
Property Documentation
◆ name
◆ translatedName
Constructor & Destructor Documentation
◆ Theme() [1/2]
Theme::Theme | ( | ) |
◆ Theme() [2/2]
◆ ~Theme()
|
default |
Destructor.
Member Function Documentation
◆ backgroundColor()
QRgb Theme::backgroundColor | ( | TextStyle | style | ) | const |
◆ editorColor()
QRgb Theme::editorColor | ( | EditorColorRole | role | ) | const |
◆ filePath()
QString Theme::filePath | ( | ) | const |
◆ isBold()
bool Theme::isBold | ( | TextStyle | style | ) | const |
◆ isItalic()
bool Theme::isItalic | ( | TextStyle | style | ) | const |
◆ 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/).
◆ isStrikeThrough()
bool Theme::isStrikeThrough | ( | TextStyle | style | ) | const |
◆ isUnderline()
bool Theme::isUnderline | ( | TextStyle | style | ) | const |
◆ isValid()
bool Theme::isValid | ( | ) | const |
◆ name()
QString Theme::name | ( | ) | const |
◆ operator=()
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.
◆ 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.
◆ textColor()
QRgb Theme::textColor | ( | TextStyle | style | ) | const |
◆ translatedName()
QString Theme::translatedName | ( | ) | const |
The documentation for this class was generated from the following files:
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.