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