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