1 | /* |
2 | SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> |
3 | SPDX-FileCopyrightText: 2016 Dominik Haumann <dhaumann@kde.org> |
4 | |
5 | SPDX-License-Identifier: MIT |
6 | */ |
7 | |
8 | #ifndef KSYNTAXHIGHLIGHTING_THEMEDATA_P_H |
9 | #define KSYNTAXHIGHLIGHTING_THEMEDATA_P_H |
10 | |
11 | #include "textstyledata_p.h" |
12 | #include "theme.h" |
13 | |
14 | #include <QHash> |
15 | #include <QSharedData> |
16 | |
17 | #include <vector> |
18 | |
19 | namespace KSyntaxHighlighting |
20 | { |
21 | /** |
22 | * Data container for a Theme. |
23 | */ |
24 | class ThemeData : public QSharedData |
25 | { |
26 | public: |
27 | static ThemeData *get(const Theme &theme) |
28 | { |
29 | return theme.m_data.data(); |
30 | } |
31 | |
32 | /** |
33 | * Default constructor, creating an uninitialized ThemeData instance. |
34 | */ |
35 | ThemeData(); |
36 | |
37 | /** |
38 | * Load the Theme data from the file @p filePath. |
39 | * Note, that @p filePath either is a local file, or a qt resource location. |
40 | */ |
41 | bool load(const QString &filePath); |
42 | |
43 | void loadComplete(); |
44 | |
45 | /** |
46 | * Returns the unique name of this Theme. |
47 | */ |
48 | QString name() const; |
49 | |
50 | /** |
51 | * Returns the revision of this Theme. |
52 | * The revision in a .theme file should be increased with every change. |
53 | */ |
54 | int revision() const; |
55 | |
56 | /** |
57 | * Returns @c true if this Theme is read-only. |
58 | * Typically, themes that are shipped by default are read-only. |
59 | */ |
60 | bool isReadOnly() const; |
61 | |
62 | /** |
63 | * Returns the full path and filename to this Theme. |
64 | * Themes from the Qt resource return the Qt resource path. |
65 | * Themes from disk return the local path. |
66 | * |
67 | * If the theme is invalid (isValid()), an empty string is returned. |
68 | */ |
69 | QString filePath() const; |
70 | |
71 | /** |
72 | * Returns the text color to be used for @p style. |
73 | * @c 0 is returned for styles that do not specify a text color, |
74 | * use the default text color in that case. |
75 | */ |
76 | QRgb textColor(Theme::TextStyle style) const; |
77 | |
78 | /** |
79 | * Returns the text color for selected to be used for @p style. |
80 | * @c 0 is returned for styles that do not specify a selected text color, |
81 | * use the textColor() in that case. |
82 | */ |
83 | QRgb selectedTextColor(Theme::TextStyle style) const; |
84 | |
85 | /** |
86 | * Returns the background color to be used for @p style. |
87 | * @c 0 is returned for styles that do not specify a background color, |
88 | * use the default background color in that case. |
89 | */ |
90 | QRgb backgroundColor(Theme::TextStyle style) const; |
91 | |
92 | /** |
93 | * Returns the background color for selected text to be used for @p style. |
94 | * @c 0 is returned for styles that do not specify a selected background |
95 | * color, use the default backgroundColor() in that case. |
96 | */ |
97 | QRgb selectedBackgroundColor(Theme::TextStyle style) const; |
98 | |
99 | /** |
100 | * Returns whether the given style should be shown in bold. |
101 | */ |
102 | bool isBold(Theme::TextStyle style) const; |
103 | |
104 | /** |
105 | * Returns whether the given style should be shown in italic. |
106 | */ |
107 | bool isItalic(Theme::TextStyle style) const; |
108 | |
109 | /** |
110 | * Returns whether the given style should be shown underlined. |
111 | */ |
112 | bool isUnderline(Theme::TextStyle style) const; |
113 | |
114 | /** |
115 | * Returns whether the given style should be shown struck through. |
116 | */ |
117 | bool isStrikeThrough(Theme::TextStyle style) const; |
118 | |
119 | public: |
120 | /** |
121 | * Returns the editor color for the requested @p role. |
122 | */ |
123 | QRgb editorColor(Theme::EditorColorRole role) const; |
124 | |
125 | /** |
126 | * Returns the TextStyle override of a specific "itemData" with attributeName |
127 | * in the syntax definition called definitionName. |
128 | * |
129 | * If no override exists, a valid TextStyleData with the respective default |
130 | * TextStyle will be used, so the returned value is always valid. |
131 | */ |
132 | TextStyleData textStyleOverride(const QString &definitionName, const QString &attributeName) const; |
133 | |
134 | /** |
135 | * Returns the TextStyle data for the given @p style. |
136 | */ |
137 | TextStyleData textStyle(Theme::TextStyle style) const; |
138 | |
139 | private: |
140 | int m_revision = 0; |
141 | QString m_name; |
142 | |
143 | //! Path to the file where the theme came from. |
144 | //! This is either a resource location (":/themes/Default.theme"), or a file |
145 | //! on disk (in a read-only or a writeable location). |
146 | QString m_filePath; |
147 | |
148 | bool m_completelyLoaded = false; |
149 | |
150 | //! TextStyles |
151 | std::vector<TextStyleData> m_textStyles; |
152 | |
153 | //! style overrides for individual itemData entries |
154 | //! definition name -> attribute name -> style |
155 | QHash<QString, QHash<QString, TextStyleData>> m_textStyleOverrides; |
156 | |
157 | //! Editor area colors |
158 | QRgb m_editorColors[Theme::TemplateReadOnlyPlaceholder + 1]; |
159 | }; |
160 | |
161 | } |
162 | |
163 | QT_BEGIN_NAMESPACE |
164 | Q_DECLARE_TYPEINFO(KSyntaxHighlighting::TextStyleData, Q_RELOCATABLE_TYPE); |
165 | QT_END_NAMESPACE |
166 | |
167 | #endif // KSYNTAXHIGHLIGHTING_THEMEDATA_P_H |
168 | |