edbee - Qt Editor Library v0.11.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
texttheme.h
Go to the documentation of this file.
1// edbee - Copyright (c) 2012-2025 by Rick Blommers and contributors
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include "edbee/exports.h"
7
8#include <QCache>
9#include <QTextLayout>
10#include <QTextCharFormat>
11
12class QTextFormat;
13
14namespace edbee {
15
17class ScopedTextRange;
19class TextDocument;
21class Edbee;
22class TextScopeList;
24
26//class TextStyle
27//{
28// bool bold_, italic_, underline_;
29// QColor foreground_;
30// QColor background_;
31//};
32
33//=================================================
34
36public:
37 TextThemeRule(const QString& name, const QString& selector, QColor foreground=QColor(), QColor background=QColor(), bool bold=false, bool italic=false, bool underline=false );
38 virtual ~TextThemeRule();
39 bool matchesScopeList(const TextScopeList *scopes );
40 void fillFormat( QTextCharFormat* format );
41
42 QString name() { return name_; }
43 TextScopeSelector* scopeSelector() { return scopeSelector_; }
44 QColor foregroundColor() { return foregroundColor_; }
45 QColor backgroundColor() { return backgroundColor_; }
46 bool bold() { return bold_; }
47 bool italic() { return italic_; }
48 bool underline() { return underline_; }
49
50private:
51
52 QString name_;
53 TextScopeSelector* scopeSelector_;
54// QString comment_; ///< The comment for this theme
55
56 QColor foregroundColor_;
57 QColor backgroundColor_;
58 bool bold_;
59 bool italic_;
60 bool underline_;
61};
62
63
64//=================================================
65
67class EDBEE_EXPORT TextTheme : public QObject
68{
69public:
70 TextTheme();
71 virtual ~TextTheme();
72
73 const QList<TextThemeRule*>& rules() { return themeRules_; }
74 void giveThemeRule( TextThemeRule* rule );
75
76 void fillFormatForTextScopeList(const TextScopeList *scopeList, QTextCharFormat* format );
77
78 QString name() { return name_; }
79 void setName( const QString& name ) { name_ = name; }
80 QString uuid() { return uuid_; }
81 void setUuid( const QString& uuid ) { uuid_ = uuid; }
82
83 QColor backgroundColor() { return backgroundColor_; }
84 void setBackgroundColor( const QColor& color ) { backgroundColor_ = color ; }
85 QColor caretColor() { return caretColor_; }
86 void setCaretColor( const QColor& color ) { caretColor_=color; }
87 QColor foregroundColor() { return foregroundColor_; }
88 void setForegroundColor( const QColor& color ) { foregroundColor_=color; }
89 QColor invisiblesColor() { return invisiblesColor_; }
90 void setInvisiblesColor( const QColor& color ) { invisiblesColor_=color; }
91 QColor lineHighlightColor() { return lineHighlightColor_; }
92 void setLineHighlightColor( const QColor& color ) { lineHighlightColor_=color; }
93 QColor selectionColor() { return selectionColor_; }
94 void setSelectionColor( const QColor& color ) { selectionColor_=color; }
95 QColor findHighlightBackgroundColor() { return findHighlightBackgroundColor_; }
96 void setFindHighlightBackgroundColor( const QColor& color ) { findHighlightBackgroundColor_=color; }
97 QColor findHighlightForegroundColor() { return findHighlightForegroundColor_; }
98 void setFindHighlightForegroundColor( const QColor& color ) { findHighlightForegroundColor_=color; }
99 QColor selectionBorderColor() { return selectionBorderColor_; }
100 void setSelectionBorderColor( const QColor& color ) { selectionBorderColor_=color; }
101 QColor activeGuideColor() { return activeGuideColor_; }
102 void setActiveGuideColor( const QColor& color ) { activeGuideColor_=color; }
103
104 QColor bracketForegroundColor() { return bracketForegroundColor_;}
105 void setBracketForegroundColor( const QColor& color ) { bracketForegroundColor_=color;}
106 QString bracketOptions() { return bracketOptions_; }
107 void setBracketOptions( const QString& str ) { bracketOptions_=str; }
108
109 QColor bracketContentsForegroundColor() { return bracketContentsForegroundColor_;}
110 void setBracketContentsForegroundColor( const QColor& color ) { bracketContentsForegroundColor_=color;}
111 QString bracketContentsOptions() { return bracketContentsOptions_; }
112 void setBracketContentsOptions(const QString& str ) { bracketContentsOptions_=str; }
113
114 QString tagsOptions() { return tagsOptions_; }
115 void setTagsOptions(const QString& str ) { tagsOptions_=str; }
116
117
118private:
119
120 QString name_;
121 QString uuid_;
122
123
124 // thTheme settings
125 QColor backgroundColor_;
126 QColor caretColor_;
127 QColor foregroundColor_;
128 QColor invisiblesColor_;
129 QColor lineHighlightColor_;
130 QColor selectionColor_;
131 QColor findHighlightBackgroundColor_;
132 QColor findHighlightForegroundColor_;
133 QColor selectionBorderColor_;
134 QColor activeGuideColor_;
135
136 QColor bracketForegroundColor_;
137 QString bracketOptions_;
138
139 QColor bracketContentsForegroundColor_;
140 QString bracketContentsOptions_;
141
142 QString tagsOptions_;
143
144
145 // The selectos
146 QList<TextThemeRule*> themeRules_;
147
148};
149
150
151
152//================================
153
154
156class EDBEE_EXPORT TextThemeStyler : public QObject
157{
158Q_OBJECT
159
160public:
162 virtual ~TextThemeStyler();
163
164 QVector<QTextLayout::FormatRange> getLineFormatRanges( int lineIdx );
165
166 TextEditorController* controller() { return controllerRef_; }
167
168// void giveTextTheme( TextTheme* theme );
169 void setThemeByName( const QString& themeName );
170 QString themeName() const;
171
172 void setTheme( TextTheme* theme );
173 TextTheme* theme() const;
174
175private:
176 QTextCharFormat getTextScopeFormat(QVector<ScopedTextRange *> &activeRanges);
177 void appendFormatRange(QVector<QTextLayout::FormatRange>& rangeList, int start, int end, QVector<edbee::ScopedTextRange *> &activeRanges );
178
179private slots:
180
181 void textDocumentChanged(edbee::TextDocument* oldDocument, edbee::TextDocument* newDocument);
182 void invalidateLayouts();
183 void themePointerChanged( const QString& name, TextTheme* oldTheme, TextTheme* newTheme );
184
185
186private:
187
188 TextEditorController* controllerRef_;
189 QString themeName_;
190 TextTheme* themeRef_;
191
192
193};
194
195
196//================================
197
198
202class EDBEE_EXPORT TextThemeManager : public QObject
203{
204Q_OBJECT
205
206protected:
208 virtual ~TextThemeManager();
209
210public:
211 void clear();
212
213 TextTheme* readThemeFile( const QString& fileName, const QString& name=QString() );
214 void listAllThemes( const QString& themePath=QString() );
215 int themeCount() { return themeNames_.size(); }
216 QString themeName( int idx );
217 TextTheme* theme( const QString& name );
218 TextTheme* fallbackTheme() const { return fallbackTheme_; }
219 QString lastErrorMessage() const;
220 void setTheme( const QString& name, TextTheme* theme );
221
222signals:
223 void themePointerChanged( const QString& name, TextTheme* oldTheme, TextTheme* newTheme );
224
225
226private:
227
228 QString themePath_;
229 QStringList themeNames_;
230 QHash<QString,TextTheme*> themeMap_;
231 TextTheme* fallbackTheme_;
232 QString lastErrorMessage_;
233
234 friend class Edbee;
235
236};
237
238
239} // edbee
The texteditor manager, It manages all singleton objects for the editor It performs the initializatio...
Definition edbee.h:27
This class 'defines' a single document scope.
Definition textdocumentscopes.h:254
A base scoped text range.
Definition textdocumentscopes.h:176
This clas represents a text buffer change and is used to pass around between events This is a sharedd...
Definition textbuffer.h:45
This is the base and abstract class of a text document A TextDocument is the model part of the editor...
Definition textdocument.h:42
The texteditor works via the controller. The controller is the central point/mediator which maps/cont...
Definition texteditorcontroller.h:39
A list of text-scopes. on a certian location, usually more then one scope is available on a given loc...
Definition textdocumentscopes.h:61
Our first version of scope-selector only support a list of scopes Thus the Descendant (space) selecto...
Definition textdocumentscopes.h:112
This class defines a single theme.
Definition texttheme.h:68
QColor activeGuideColor()
Definition texttheme.h:101
QColor backgroundColor()
Definition texttheme.h:83
void setFindHighlightBackgroundColor(const QColor &color)
Definition texttheme.h:96
void setActiveGuideColor(const QColor &color)
Definition texttheme.h:102
QColor invisiblesColor()
Definition texttheme.h:89
void setUuid(const QString &uuid)
Definition texttheme.h:81
QString bracketContentsOptions()
Definition texttheme.h:111
QColor selectionBorderColor()
Definition texttheme.h:99
QColor caretColor()
Definition texttheme.h:85
void setCaretColor(const QColor &color)
Definition texttheme.h:86
QColor findHighlightBackgroundColor()
Definition texttheme.h:95
const QList< TextThemeRule * > & rules()
Definition texttheme.h:73
void setBracketForegroundColor(const QColor &color)
Definition texttheme.h:105
void setBracketContentsForegroundColor(const QColor &color)
Definition texttheme.h:110
void setBracketOptions(const QString &str)
Definition texttheme.h:107
void setInvisiblesColor(const QColor &color)
Definition texttheme.h:90
void setTagsOptions(const QString &str)
Definition texttheme.h:115
QString uuid()
Definition texttheme.h:80
void setBackgroundColor(const QColor &color)
Definition texttheme.h:84
QColor selectionColor()
Definition texttheme.h:93
void setSelectionColor(const QColor &color)
Definition texttheme.h:94
QColor lineHighlightColor()
Definition texttheme.h:91
void setName(const QString &name)
Definition texttheme.h:79
TextTheme()
Definition texttheme.cpp:60
void setBracketContentsOptions(const QString &str)
Definition texttheme.h:112
QString tagsOptions()
Definition texttheme.h:114
QColor foregroundColor()
Definition texttheme.h:87
QString name()
Definition texttheme.h:78
void setLineHighlightColor(const QColor &color)
Definition texttheme.h:92
QColor bracketContentsForegroundColor()
Definition texttheme.h:109
QColor bracketForegroundColor()
Definition texttheme.h:104
void setFindHighlightForegroundColor(const QColor &color)
Definition texttheme.h:98
void setSelectionBorderColor(const QColor &color)
Definition texttheme.h:100
QString bracketOptions()
Definition texttheme.h:106
void setForegroundColor(const QColor &color)
Definition texttheme.h:88
QColor findHighlightForegroundColor()
Definition texttheme.h:97
TextThemeManager()
Constructs the theme manager And intialises a fallback theme.
Definition texttheme.cpp:321
void clear()
clears all items
Definition texttheme.cpp:339
TextTheme * readThemeFile(const QString &fileName, const QString &name=QString())
This method loads the given theme file. The theme manager stays owner of the given theme.
Definition texttheme.cpp:376
int themeCount()
Definition texttheme.h:215
TextTheme * fallbackTheme() const
Definition texttheme.h:218
friend class Edbee
Definition texttheme.h:234
void listAllThemes(const QString &themePath=QString())
This method loads all theme names from the given theme path (*.tmTheme files)
Definition texttheme.cpp:349
The styles available in tmTheme files.
Definition texttheme.h:35
bool matchesScopeList(const TextScopeList *scopes)
This method checks if the given scopelist matches the scope selector.
Definition texttheme.cpp:43
QColor foregroundColor()
Definition texttheme.h:44
QString name()
Definition texttheme.h:42
QColor backgroundColor()
Definition texttheme.h:45
bool italic()
Definition texttheme.h:47
void fillFormat(QTextCharFormat *format)
Definition texttheme.cpp:48
TextScopeSelector * scopeSelector()
Definition texttheme.h:43
bool underline()
Definition texttheme.h:48
TextThemeRule(const QString &name, const QString &selector, QColor foreground=QColor(), QColor background=QColor(), bool bold=false, bool italic=false, bool underline=false)
Definition texttheme.cpp:25
bool bold()
Definition texttheme.h:46
TextThemeStyler(TextEditorController *controller)
Constructs the theme styler.
Definition texttheme.cpp:125
TextEditorController * controller()
Definition texttheme.h:166
QVector< QTextLayout::FormatRange > getLineFormatRanges(int lineIdx)
This method returns a reference to the given line format. WARNING this reference is ONLY valid very s...
Definition texttheme.cpp:148
#define EDBEE_EXPORT
Definition exports.h:15
QT Acessibility has an issue with reporting blank lines between elements lines. defining 'WINDOWS_EMP...
Definition commentcommand.cpp:20