diff --git a/data/themes/breeze-dark.theme b/data/themes/breeze-dark.theme index 7423d1d..dd4d3ff 100644 --- a/data/themes/breeze-dark.theme +++ b/data/themes/breeze-dark.theme @@ -1,177 +1,177 @@ { "metadata" : { "revision" : 1, "name" : "Breeze Dark", "author" : "Dominik Haumann", "license" : "MIT", "read-only" : true }, "text-styles": { "Normal" : { "text-color" : "#cfcfc2", "selected-text-color" : "#cfcfc2", "bold" : false, "italic" : false, "underline" : false, "strike-through" : false }, "Keyword" : { "text-color" : "#cfcfc2", "selected-text-color" : "#cfcfc2", "bold" : true }, "Function" : { "text-color" : "#8e44ad", "selected-text-color" : "#af81ff" }, "Variable" : { "text-color" : "#27aeae", "selected-text-color" : "#27aeae" }, "ControlFlow" : { "text-color" : "#fdbc4b", "selected-text-color" : "#fdbc4b", "bold" : true }, "Operator" : { "text-color" : "#cfcfc2", "selected-text-color" : "#cfcfc2" }, "BuiltIn" : { "text-color" : "#7f8c8d", "selected-text-color" : "#bdc3c7" }, "Extension" : { "text-color" : "#0099ff", "selected-text-color" : "#bdc3c7", "bold" : true }, "Preprocessor" : { "text-color" : "#27ae60", "selected-text-color" : "#27ae60" }, "Attribute" : { "text-color" : "#2980b9", "selected-text-color" : "#fdbc4b" }, "Char" : { "text-color" : "#3daee9", "selected-text-color" : "#3daee9" }, "SpecialChar" : { "text-color" : "#3daee9", "selected-text-color" : "#3daee9" }, "String" : { "text-color" : "#f44f4f", "selected-text-color" : "#f44f4f" }, "VerbatimString" : { "text-color" : "#da4453", "selected-text-color" : "#da4453" }, "SpecialString" : { "text-color" : "#da4453", "selected-text-color" : "#da4453" }, "Import" : { "text-color" : "#27ae60", "selected-text-color" : "#27ae60" }, "DataType" : { "text-color" : "#2980b9", "selected-text-color" : "#fdbc4b" }, "DecVal" : { "text-color" : "#f67400", "selected-text-color" : "#f67400" }, "BaseN" : { "text-color" : "#f67400", "selected-text-color" : "#f67400" }, "Float" : { "text-color" : "#f67400", "selected-text-color" : "#f67400" }, "Constant" : { "text-color" : "#27aeae", "selected-text-color" : "#27aeae", "bold" : true }, "Comment" : { "text-color" : "#606060", "selected-text-color" : "#808080" }, "Documentation" : { "text-color" : "#a43340", "selected-text-color" : "#da4453" }, "Annotation" : { "text-color" : "#3f8058", "selected-text-color" : "#54aa75" }, "CommentVar" : { "text-color" : "#7f8c8d", "selected-text-color" : "#94a3a4" }, "RegionMarker" : { "text-color" : "#2980b9", "selected-text-color" : "#3daee9", "background-color" : "#153042" }, "Information" : { "text-color" : "#c45b00", "selected-text-color" : "#e46700" }, "Warning" : { "text-color" : "#da4453", "selected-text-color" : "#da4453" }, "Alert" : { "text-color" : "#95da4c", "selected-text-color" : "#95da4c", "background-color" : "#4d1f24", "bold" : true }, "Error" : { "text-color" : "#da4453", "selected-text-color" : "#da4453", "underline" : true }, "Others" : { "text-color" : "#27ae60", "selected-text-color" : "#27ae60" } }, "editor-colors": { "background-color" : "#232629", "code-folding" : "#224e65", "bracket-matching" : "#8e44ad", "current-line" : "#31363b", "icon-border" : "#31363b", "indentation-line" : "#3a3f44", "line-numbers" : "#7a7c7d", "current-line-number" : "#a5a6a8", "mark-bookmark" : "#0404bf", "mark-breakpoint-active" : "#8b0607", "mark-breakpoint-reached" : "#6d6e07", "mark-breakpoint-disabled" : "#820683", "mark-execution" : "#4d4e50", "mark-warning" : "#f67400", "mark-error" : "#da4453", "modified-lines" : "#c04900", "replace-highlight" : "#808021", "saved-lines" : "#1c8042", "search-highlight" : "#218058", "selection" : "#2d5c76", "separator" : "#7a7c7d", "spell-checking" : "#c0392b", "tab-marker" : "#4d4d4d", "template-background" : "#31363b", - "template-editable-placeholder" : "#123723", - "template-focused-editable-placeholder" : "#123723", - "template-not-editable-placeholder" : "#4d1f24", + "template-placeholder" : "#123723", + "template-focused-placeholder" : "#123723", + "template-read-only-placeholder" : "#4d1f24", "word-wrap-marker" : "#3a3f44" } } diff --git a/data/themes/default.theme b/data/themes/default.theme index 18aac46..f0be510 100644 --- a/data/themes/default.theme +++ b/data/themes/default.theme @@ -1,182 +1,182 @@ { "metadata" : { "revision" : 1, "name" : "Default", "author" : "Kate Authors", "license" : "MIT", "read-only" : true }, "text-styles": { "Normal" : { "text-color" : "#1f1c1b", "selected-text-color" : "#ffffff", "bold" : false, "italic" : false, "underline" : false, "strike-through" : false }, "Keyword" : { "text-color" : "#1f1c1b", "selected-text-color" : "#ffffff", "bold" : true }, "Function" : { "text-color" : "#644a9b", "selected-text-color" : "#452886" }, "Variable" : { "text-color" : "#0057ae", "selected-text-color" : "#00316e" }, "ControlFlow" : { "text-color" : "#1f1c1b", "selected-text-color" : "#ffffff", "bold" : true }, "Operator" : { "text-color" : "#1f1c1b", "selected-text-color" : "#ffffff" }, "BuiltIn" : { "text-color" : "#644a9b", "selected-text-color" : "#452886", "bold" : true }, "Extension" : { "text-color" : "#0095ff", "selected-text-color" : "#ffffff", "bold" : true }, "Preprocessor" : { "text-color" : "#006e28", "selected-text-color" : "#006e28" }, "Attribute" : { "text-color" : "#0057ae", "selected-text-color" : "#00316e" }, "Char" : { "text-color" : "#924c9d", "selected-text-color" : "#6c2477" }, "SpecialChar" : { "text-color" : "#3daee9", "selected-text-color" : "#fcfcfc" }, "String" : { "text-color" : "#bf0303", "selected-text-color" : "#9c0e0e" }, "VerbatimString" : { "text-color" : "#bf0303", "selected-text-color" : "#9c0e0e" }, "SpecialString" : { "text-color" : "#ff5500", "selected-text-color" : "#ff5500" }, "Import" : { "text-color" : "#ff5500", "selected-text-color" : "#ff5500" }, "DataType" : { "text-color" : "#0057ae", "selected-text-color" : "#00316e" }, "DecVal" : { "text-color" : "#b08000", "selected-text-color" : "#805c00" }, "BaseN" : { "text-color" : "#b08000", "selected-text-color" : "#805c00" }, "Float" : { "text-color" : "#b08000", "selected-text-color" : "#805c00" }, "Constant" : { "text-color" : "#aa5500", "selected-text-color" : "#5e2f00" }, "Comment" : { "text-color" : "#898887", "selected-text-color" : "#5e5d5d" }, "Documentation" : { "text-color" : "#607880", "selected-text-color" : "#46585e" }, "Annotation" : { "text-color" : "#ca60ca", "selected-text-color" : "#a44ea4" }, "CommentVar" : { "text-color" : "#0095ff", "selected-text-color" : "#ffffff" }, "RegionMarker" : { "text-color" : "#0057ae", "selected-text-color" : "#00316e", "background-color" : "#e0e9f8" }, "Information" : { "text-color" : "#b08000", "selected-text-color" : "#805c00" }, "Warning" : { "text-color" : "#bf0303", "selected-text-color" : "#9c0e0e" }, "Alert" : { "text-color" : "#bf0303", "selected-text-color" : "#9c0e0e", "background-color" : "#f7e6e6", "bold" : true }, "Error" : { "text-color" : "#bf0303", "selected-text-color" : "#9c0e0e", "underline" : true }, "Others" : { "text-color" : "#006e28", "selected-text-color" : "#006e28" } }, "editor-colors": { "background-color" : "#ffffff", "code-folding" : "#94caef", "bracket-matching" : "#ffff00", "current-line" : "#f8f7f6", "icon-border" : "#f0f0f0", "indentation-line" : "#d2d2d2", "line-numbers" : "#a0a0a0", "current-line-number" : "#1e1e1e", "mark-bookmark" : "#0000ff", "mark-breakpoint-active" : "#ff0000", "mark-breakpoint-reached" : "#ffff00", "mark-breakpoint-disabled" : "#ff00ff", "mark-execution" : "#a0a0a4", "mark-warning" : "#00ff00", "mark-error" : "#ff0000", "modified-lines" : "#fdbc4b", "replace-highlight" : "#00ff00", "saved-lines" : "#2ecc71", "search-highlight" : "#ffff00", "selection" : "#94caef", "separator" : "#898887", "spell-checking" : "#bf0303", "tab-marker" : "#d2d2d2", "template-background" : "#d6d2d0", - "template-editable-placeholder" : "#baf8ce", - "template-focused-editable-placeholder" : "#76da98", - "template-not-editable-placeholder" : "#f6e6e6", + "template-placeholder" : "#baf8ce", + "template-focused-placeholder" : "#76da98", + "template-read-only-placeholder" : "#f6e6e6", "word-wrap-marker" : "#ededed" }, "custom-stylesX": { "ISO C++": { "Preprocessor": { "text-color": "#0000ff", "underline": true } }, "C++": { "Preprocessor": { "text-color": "#0000ff", "underline": true } }, "C": { "Preprocessor": { "text-color": "#0000ff", "underline": true } } } } diff --git a/data/themes/printing.theme b/data/themes/printing.theme index 5e44ded..b2e88f9 100644 --- a/data/themes/printing.theme +++ b/data/themes/printing.theme @@ -1,176 +1,176 @@ { "metadata" : { "revision" : 1, "name" : "Printing", "author" : "Kate Authors", "license" : "MIT", "read-only" : true }, "text-styles": { "Normal" : { "text-color" : "#000000", "selected-text-color" : "#ffffff", "bold" : false, "italic" : false, "underline" : false, "strike-through" : false }, "Keyword" : { "text-color" : "#000000", "selected-text-color" : "#ffffff", "bold" : true }, "Function" : { "text-color" : "#644a9b", "selected-text-color" : "#452886" }, "Variable" : { "text-color" : "#0057ae", "selected-text-color" : "#00316e" }, "ControlFlow" : { "text-color" : "#000000", "selected-text-color" : "#ffffff", "bold" : true }, "Operator" : { "text-color" : "#000000", "selected-text-color" : "#ffffff" }, "BuiltIn" : { "text-color" : "#644a9b", "selected-text-color" : "#452886" }, "Extension" : { "text-color" : "#0095ff", "selected-text-color" : "#ffffff", "bold" : true }, "Preprocessor" : { "text-color" : "#006e28", "selected-text-color" : "#006e28" }, "Attribute" : { "text-color" : "#0057ae", "selected-text-color" : "#00316e" }, "Char" : { "text-color" : "#924c9d", "selected-text-color" : "#6c2477" }, "SpecialChar" : { "text-color" : "#ff5500", "selected-text-color" : "#ff5500" }, "String" : { "text-color" : "#bf0303", "selected-text-color" : "#9c0e0e" }, "VerbatimString" : { "text-color" : "#bf0303", "selected-text-color" : "#9c0e0e" }, "SpecialString" : { "text-color" : "#ff5500", "selected-text-color" : "#ff5500" }, "Import" : { "text-color" : "#644a9b", "selected-text-color" : "#452886" }, "DataType" : { "text-color" : "#0057ae", "selected-text-color" : "#00316e" }, "DecVal" : { "text-color" : "#b08000", "selected-text-color" : "#805c00" }, "BaseN" : { "text-color" : "#b08000", "selected-text-color" : "#805c00" }, "Float" : { "text-color" : "#b08000", "selected-text-color" : "#805c00" }, "Constant" : { "text-color" : "#aa5500", "selected-text-color" : "#5e2f00" }, "Comment" : { "text-color" : "#898887", "selected-text-color" : "#5e5d5d" }, "Documentation" : { "text-color" : "#607880", "selected-text-color" : "#46585e" }, "Annotation" : { "text-color" : "#ca60ca", "selected-text-color" : "#a44ea4" }, "CommentVar" : { "text-color" : "#0095ff", "selected-text-color" : "#ffffff" }, "RegionMarker" : { "text-color" : "#0057ae", "selected-text-color" : "#00316e", "background-color" : "#e0e9f8" }, "Information" : { "text-color" : "#b08000", "selected-text-color" : "#805c00" }, "Warning" : { "text-color" : "#bf0303", "selected-text-color" : "#9c0e0e" }, "Alert" : { "text-color" : "#bf0303", "selected-text-color" : "#9c0e0e", "background-color" : "#f7e6e6", "bold" : true }, "Error" : { "text-color" : "#bf0303", "selected-text-color" : "#9c0e0e", "underline" : true }, "Others" : { "text-color" : "#006e28", "selected-text-color" : "#006e28" } }, "editor-colors": { "background-color" : "#ffffff", "code-folding" : "#94caef", "bracket-matching" : "#edf9ff", "current-line" : "#f8f7f6", "icon-border" : "#d6d2d0", "indentation-line" : "#d2d2d2", "line-numbers" : "#221f1e", "current-line-number" : "#221f1e", "mark-bookmark" : "#0000ff", "mark-breakpoint-active" : "#ff0000", "mark-breakpoint-reached" : "#ffff00", "mark-breakpoint-disabled" : "#ff00ff", "mark-execution" : "#a0a0a4", "mark-warning" : "#00ff00", "mark-error" : "#ff0000", "modified-lines" : "#f6e6e6", "replace-highlight" : "#00ff00", "saved-lines" : "#baf8ce", "search-highlight" : "#ffff00", "selection" : "#94caef", "separator" : "#898887", "spell-checking" : "#bf0303", "tab-marker" : "#d2d2d2", "template-background" : "#d6d2d0", - "template-editable-placeholder" : "#baf8ce", - "template-focused-editable-placeholder" : "#76da98", - "template-not-editable-placeholder" : "#f6e6e6", + "template-placeholder" : "#baf8ce", + "template-focused-placeholder" : "#76da98", + "template-read-only-placeholder" : "#f6e6e6", "word-wrap-marker" : "#ededed" } } diff --git a/src/lib/theme.h b/src/lib/theme.h index 4ef6023..81fa6d6 100644 --- a/src/lib/theme.h +++ b/src/lib/theme.h @@ -1,314 +1,315 @@ /* Copyright (C) 2016 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef SYNTAXHIGHLIGHTING_THEME_H #define SYNTAXHIGHLIGHTING_THEME_H #include "kf5syntaxhighlighting_export.h" #include #include #include #include namespace SyntaxHighlighting { class ThemeData; class RepositoryPrivate; /** * Color theme definition used for highlighting. * * @section theme_intro 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. * * @section theme_text_colors Text Colors and the Class Format * * The text colors are used for syntax highlighting. * // TODO: elaborate more and explain relation to Format class * * @section theme_editor_colors 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". * * @section theme_access Accessing a Theme * * All available Theme%s are accessed through the Repository. These themes are * typically valid themes. If you create a Theme on your own, isValid() will * return @e false, and all colors provided by this Theme are in fact invalid * and therefore unusable. * * @see Format */ class KF5SYNTAXHIGHLIGHTING_EXPORT Theme { Q_GADGET public: /** * 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 EditorColorRole%s. */ 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 }; Q_ENUM(TextStyle) /** * Editor color roles, used to paint line numbers, editor background etc. * The colors typically should have good contrast with the colors used * in the TextStyle%s. */ enum EditorColorRole { //! Background color for the editing area. BackgroundColor = 0, //! Background color for selected text. TextSelection, //! Background color for the line of the current text cursor. CurrentLine, //! Background color for matching text while searching. SearchHighlight, //! Background color for replaced text for a search & replace action. ReplaceHighlight, //! Background color for matching bracket pairs (including quotes) BracketMatching, //! Foreground color for visualizing tabs and trailing spaces. TabMarker, //! Color used to underline spell check errors. SpellChecking, //! Color used to draw vertical indentation levels, typically a line. IndentationLine, //! Background color for the icon border. IconBorder, //! Background colors for code folding regions in the text area, as well //! as code folding indicators in the code folding border. CodeFolding, //! Foreground color for drawing the line numbers. This should have a //! good contrast with the IconBorder background color. LineNumbers, //! Foreground color for drawing the current line number. This should //! have a good contrast with the IconBorder background color. CurrentLineNumber, //! Color used in the icon border to indicate dynamically wrapped lines. //! This color should have a good contrast with the IconBorder //! background color. WordWrapMarker, //! Color used to draw a vertical line for marking changed lines. ModifiedLines, //! Color used to draw a vertical line for marking saved lines. SavedLines, //! Line color used to draw separator lines, e.g. at column 80 in the //! text editor area. Separator, //! Background color for bookmarks. MarkBookmark, //! Background color for active breakpoints. MarkBreakpointActive, //! Background color for a reached breakpoint. MarkBreakpointReached, //! Background color for inactive (disabled) breakpoints. MarkBreakpointDisabled, //! Background color for marking the current execution position. MarkExecution, //! Background color for general warning marks. MarkWarning, //! Background color for general error marks. MarkError, //! Background color for text templates (snippets). TemplateBackground, - //! Background color for all placeholders in text templates. + //! Background color for all editable placeholders in text templates. TemplatePlaceholder, - //! Background color for the current placeholder in text templates. + //! Background color for the currently active placeholder in text + //! templates. TemplateFocusedPlaceholder, //! Background color for read-only placeholders in text templates. TemplateReadOnlyPlaceholder }; Q_ENUM(EditorColorRole) /** * Default constructor, creating an invalid Theme, see isValid(). */ Theme(); /** * Copy constructor, sharing the Theme data with @p copy. */ Theme(const Theme ©); /** * Destructor. */ ~Theme(); /** * Assignment operator, sharing the Theme data with @p other. */ Theme &operator=(const Theme &other); /** * Returns @c true if this is a valid Theme. * If the theme is invalid, none of the returned colors are well-defined. */ bool isValid() const; /** * Returns the unique name of this Theme. * @see translatedName() */ QString name() const; /** * Returns the translated name of this Theme. The translated name can be * used in the user interface. */ QString translatedName() const; /** * Returns @c true if this Theme is read-only. * Typically, themes that are shipped by default are read-only. */ bool isReadOnly() const; /** * Returns the full path and filename to this Theme. * Themes from the Qt resource return the Qt resource path. * Themes from disk return the local path. * * If the theme is invalid (isValid()), an empty string is returned. */ QString filePath() const; /** * Returns the text color to be used for @p style. * @c 0 is returned for styles that do not specify a text color, * use the default text color in that case. */ QRgb textColor(TextStyle style) const; /** * Returns the selected text color to be used for @p style. * @c 0 is returned for styles that do not specify a selected text color, * use the default textColor() in that case. */ QRgb selectedTextColor(TextStyle style) const; /** * Returns the background color to be used for @p style. * @c 0 is returned for styles that do not specify a background color, * use the default background color in that case. */ QRgb backgroundColor(TextStyle style) const; /** * Returns the background color to be used for selected text for @p style. * @c 0 is returned for styles that do not specify a background color, * use the default backgroundColor() in that case. */ QRgb selectedBackgroundColor(TextStyle style) const; /** * Returns whether the given style should be shown in bold. */ bool isBold(TextStyle style) const; /** * Returns whether the given style should be shown in italic. */ bool isItalic(TextStyle style) const; /** * Returns whether the given style should be shown underlined. */ bool isUnderline(TextStyle style) const; /** * Returns whether the given style should be shown striked through. */ bool isStrikeThrough(TextStyle style) const; public: /** * Returns the editor color for the requested @p role. */ QRgb editorColor(EditorColorRole role) const; private: /** * Constructor taking a shared ThemeData instance. */ Theme(ThemeData* data); friend class RepositoryPrivate; friend class ThemeData; private: /** * Shared data holder. */ QExplicitlySharedDataPointer m_data; }; } Q_DECLARE_TYPEINFO(SyntaxHighlighting::Theme, Q_MOVABLE_TYPE); #endif // SYNTAXHIGHLIGHTING_THEME_H diff --git a/src/lib/themedata.cpp b/src/lib/themedata.cpp index 1f2da8e..3786d0e 100644 --- a/src/lib/themedata.cpp +++ b/src/lib/themedata.cpp @@ -1,253 +1,253 @@ /* Copyright (C) 2016 Volker Krause Copyright (C) 2016 Dominik Haumann This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "themedata_p.h" #include "syntaxhighlighting_logging.h" #include #include #include #include #include #include using namespace SyntaxHighlighting; ThemeData* ThemeData::get(const Theme &theme) { return theme.m_data.data(); } ThemeData::ThemeData() : m_revision(0) , m_readOnly(true) { memset(m_editorColors, 0, sizeof(m_editorColors)); } /** * Convert QJsonValue @p val into a color, if possible. Valid colors are only * in hex format: #rrggbb. On error, returns 0x00000000. */ static inline QRgb readColor(const QJsonValue &val) { const QRgb unsetColor = 0; if (!val.isString()) { return unsetColor; } const QString str = val.toString(); if (str.isEmpty() || str[0] != QLatin1Char('#')) { return unsetColor; } const QColor color(str); return color.isValid() ? color.rgb() : unsetColor; } static inline TextStyleData readThemeData(const QJsonObject &obj) { TextStyleData td; td.textColor = readColor(obj.value(QLatin1String("text-color"))); td.backgroundColor = readColor(obj.value(QLatin1String("background-color"))); td.selectedTextColor = readColor(obj.value(QLatin1String("selected-text-color"))); td.selectedBackgroundColor = readColor(obj.value(QLatin1String("selected-background-color"))); auto val = obj.value(QLatin1String("bold")); if (val.isBool()) { td.bold = val.toBool(); td.hasBold = true; } val = obj.value(QLatin1String("italic")); if (val.isBool()) { td.italic = val.toBool(); td.hasItalic = true; } val = obj.value(QLatin1String("underline")); if (val.isBool()) { td.underline = val.toBool(); td.hasUnderline = true; } val = obj.value(QLatin1String("strike-through")); if (val.isBool()) { td.strikeThrough = val.toBool(); td.hasStrikeThrough = true; } return td; } bool ThemeData::load(const QString &filePath) { QFile loadFile(filePath); if (!loadFile.open(QIODevice::ReadOnly)) { return false; } const QByteArray jsonData = loadFile.readAll(); QJsonParseError parseError; QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &parseError); if (parseError.error != QJsonParseError::NoError) { qCWarning(Log) << "Failed to parse theme file" << filePath << ":" << parseError.errorString(); return false; } m_filePath = filePath; QJsonObject obj = jsonDoc.object(); // read metadata const QJsonObject metadata = obj.value(QLatin1String("metadata")).toObject(); m_name = metadata.value(QLatin1String("name")).toString(); m_revision = metadata.value(QLatin1String("revision")).toInt(); m_author = metadata.value(QLatin1String("author")).toString(); m_license = metadata.value(QLatin1String("license")).toString(); m_readOnly = metadata.value(QLatin1String("read-only")).toBool(); // read text styles static const auto idx = Theme::staticMetaObject.indexOfEnumerator("TextStyle"); Q_ASSERT(idx >= 0); const auto metaEnum = Theme::staticMetaObject.enumerator(idx); const QJsonObject textStyles = obj.value(QLatin1String("text-styles")).toObject(); for (int i = 0; i < metaEnum.keyCount(); ++i) { Q_ASSERT(i == metaEnum.value(i)); m_textStyles[i] = readThemeData(textStyles.value(QLatin1String(metaEnum.key(i))).toObject()); } // read editor area colors const QJsonObject editorColors = obj.value(QLatin1String("editor-colors")).toObject(); m_editorColors[Theme::BackgroundColor] = readColor(editorColors.value(QLatin1String("background-color"))); m_editorColors[Theme::TextSelection] = readColor(editorColors.value(QLatin1String("selection"))); m_editorColors[Theme::CurrentLine] = readColor(editorColors.value(QLatin1String("current-line"))); m_editorColors[Theme::SearchHighlight] = readColor(editorColors.value(QLatin1String("search-highlight"))); m_editorColors[Theme::ReplaceHighlight] = readColor(editorColors.value(QLatin1String("replace-highlight"))); m_editorColors[Theme::BracketMatching] = readColor(editorColors.value(QLatin1String("bracket-matching"))); m_editorColors[Theme::TabMarker] = readColor(editorColors.value(QLatin1String("tab-marker"))); m_editorColors[Theme::SpellChecking] = readColor(editorColors.value(QLatin1String("spell-checking"))); m_editorColors[Theme::IndentationLine] = readColor(editorColors.value(QLatin1String("indentation-line"))); m_editorColors[Theme::IconBorder] = readColor(editorColors.value(QLatin1String("icon-border"))); m_editorColors[Theme::CodeFolding] = readColor(editorColors.value(QLatin1String("code-folding"))); m_editorColors[Theme::LineNumbers] = readColor(editorColors.value(QLatin1String("line-numbers"))); m_editorColors[Theme::CurrentLineNumber] = readColor(editorColors.value(QLatin1String("current-line-number"))); m_editorColors[Theme::WordWrapMarker] = readColor(editorColors.value(QLatin1String("word-wrap-marker"))); m_editorColors[Theme::ModifiedLines] = readColor(editorColors.value(QLatin1String("modified-lines"))); m_editorColors[Theme::SavedLines] = readColor(editorColors.value(QLatin1String("saved-lines"))); m_editorColors[Theme::Separator] = readColor(editorColors.value(QLatin1String("separator"))); m_editorColors[Theme::MarkBookmark] = readColor(editorColors.value(QLatin1String("mark-bookmark"))); m_editorColors[Theme::MarkBreakpointActive] = readColor(editorColors.value(QLatin1String("mark-breakpoint-active"))); m_editorColors[Theme::MarkBreakpointReached] = readColor(editorColors.value(QLatin1String("mark-breakpoint-reached"))); m_editorColors[Theme::MarkBreakpointDisabled] = readColor(editorColors.value(QLatin1String("mark-breakpoint-disabled"))); m_editorColors[Theme::MarkExecution] = readColor(editorColors.value(QLatin1String("mark-execution"))); m_editorColors[Theme::MarkWarning] = readColor(editorColors.value(QLatin1String("mark-warning"))); m_editorColors[Theme::MarkError] = readColor(editorColors.value(QLatin1String("mark-error"))); m_editorColors[Theme::TemplateBackground] = readColor(editorColors.value(QLatin1String("template-background"))); - m_editorColors[Theme::TemplatePlaceholder] = readColor(editorColors.value(QLatin1String("template-editable-placeholder"))); - m_editorColors[Theme::TemplateFocusedPlaceholder] = readColor(editorColors.value(QLatin1String("template-focused-editable-placeholder"))); - m_editorColors[Theme::TemplateReadOnlyPlaceholder] = readColor(editorColors.value(QLatin1String("template-not-editable-placeholder"))); + m_editorColors[Theme::TemplatePlaceholder] = readColor(editorColors.value(QLatin1String("template-placeholder"))); + m_editorColors[Theme::TemplateFocusedPlaceholder] = readColor(editorColors.value(QLatin1String("template-focused-placeholder"))); + m_editorColors[Theme::TemplateReadOnlyPlaceholder] = readColor(editorColors.value(QLatin1String("template-read-only-placeholder"))); // read per-definition style overrides const auto customStyles = obj.value(QLatin1String("custom-styles")).toObject(); for (auto it = customStyles.begin(); it != customStyles.end(); ++it) { const auto obj = it.value().toObject(); QHash overrideStyle; for (auto it2 = obj.begin(); it2 != obj.end(); ++it2) overrideStyle.insert(it2.key(), readThemeData(it2.value().toObject())); m_textStyleOverrides.insert(it.key(), overrideStyle); } return true; } QString ThemeData::name() const { return m_name; } int ThemeData::revision() const { return m_revision; } bool ThemeData::isReadOnly() const { return m_readOnly; } QString ThemeData::filePath() const { return m_filePath; } QRgb ThemeData::textColor(Theme::TextStyle style) const { Q_ASSERT(static_cast(style) >= 0 && static_cast(style) <= static_cast(Theme::Others)); return m_textStyles[style].textColor; } QRgb ThemeData::selectedTextColor(Theme::TextStyle style) const { Q_ASSERT(static_cast(style) >= 0 && static_cast(style) <= static_cast(Theme::Others)); return m_textStyles[style].selectedTextColor; } QRgb ThemeData::backgroundColor(Theme::TextStyle style) const { Q_ASSERT(static_cast(style) >= 0 && static_cast(style) <= static_cast(Theme::Others)); return m_textStyles[style].backgroundColor; } QRgb ThemeData::selectedBackgroundColor(Theme::TextStyle style) const { Q_ASSERT(static_cast(style) >= 0 && static_cast(style) <= static_cast(Theme::Others)); return m_textStyles[style].selectedBackgroundColor; } bool ThemeData::isBold(Theme::TextStyle style) const { Q_ASSERT(static_cast(style) >= 0 && static_cast(style) <= static_cast(Theme::Others)); return m_textStyles[style].bold; } bool ThemeData::isItalic(Theme::TextStyle style) const { Q_ASSERT(static_cast(style) >= 0 && static_cast(style) <= static_cast(Theme::Others)); return m_textStyles[style].italic; } bool ThemeData::isUnderline(Theme::TextStyle style) const { Q_ASSERT(static_cast(style) >= 0 && static_cast(style) <= static_cast(Theme::Others)); return m_textStyles[style].underline; } bool ThemeData::isStrikeThrough(Theme::TextStyle style) const { Q_ASSERT(static_cast(style) >= 0 && static_cast(style) <= static_cast(Theme::Others)); return m_textStyles[style].strikeThrough; } QRgb ThemeData::editorColor(Theme::EditorColorRole role) const { Q_ASSERT(static_cast(role) >= 0 && static_cast(role) <= static_cast(Theme::TemplateReadOnlyPlaceholder)); return m_editorColors[role]; } TextStyleData ThemeData::textStyleOverride(const QString& definitionName, const QString& attributeName) const { return m_textStyleOverrides.value(definitionName).value(attributeName); }