File indexing completed on 2024-05-12 15:50:07

0001 /*
0002     SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
0003     SPDX-FileCopyrightText: 2016 Dominik Haumann <dhaumann@kde.org>
0004 
0005     SPDX-License-Identifier: MIT
0006 */
0007 
0008 #ifndef KSYNTAXHIGHLIGHTING_THEMEDATA_P_H
0009 #define KSYNTAXHIGHLIGHTING_THEMEDATA_P_H
0010 
0011 #include "textstyledata_p.h"
0012 #include "theme.h"
0013 
0014 #include <QHash>
0015 #include <QSharedData>
0016 
0017 #include <vector>
0018 
0019 namespace KSyntaxHighlighting
0020 {
0021 /**
0022  * Data container for a Theme.
0023  */
0024 class ThemeData : public QSharedData
0025 {
0026 public:
0027     static ThemeData *get(const Theme &theme);
0028 
0029     /**
0030      * Default constructor, creating an uninitialized ThemeData instance.
0031      */
0032     ThemeData();
0033 
0034     /**
0035      * Load the Theme data from the file @p filePath.
0036      * Note, that @p filePath either is a local file, or a qt resource location.
0037      */
0038     bool load(const QString &filePath);
0039 
0040     /**
0041      * Returns the unique name of this Theme.
0042      */
0043     QString name() const;
0044 
0045     /**
0046      * Returns the revision of this Theme.
0047      * The revision in a .theme file should be increased with every change.
0048      */
0049     int revision() const;
0050 
0051     /**
0052      * Returns @c true if this Theme is read-only.
0053      * Typically, themes that are shipped by default are read-only.
0054      */
0055     bool isReadOnly() const;
0056 
0057     /**
0058      * Returns the full path and filename to this Theme.
0059      * Themes from the Qt resource return the Qt resource path.
0060      * Themes from disk return the local path.
0061      *
0062      * If the theme is invalid (isValid()), an empty string is returned.
0063      */
0064     QString filePath() const;
0065 
0066     /**
0067      * Returns the text color to be used for @p style.
0068      * @c 0 is returned for styles that do not specify a text color,
0069      * use the default text color in that case.
0070      */
0071     QRgb textColor(Theme::TextStyle style) const;
0072 
0073     /**
0074      * Returns the text color for selected to be used for @p style.
0075      * @c 0 is returned for styles that do not specify a selected text color,
0076      * use the textColor() in that case.
0077      */
0078     QRgb selectedTextColor(Theme::TextStyle style) const;
0079 
0080     /**
0081      * Returns the background color to be used for @p style.
0082      * @c 0 is returned for styles that do not specify a background color,
0083      * use the default background color in that case.
0084      */
0085     QRgb backgroundColor(Theme::TextStyle style) const;
0086 
0087     /**
0088      * Returns the background color for selected text to be used for @p style.
0089      * @c 0 is returned for styles that do not specify a selected background
0090      * color, use the default backgroundColor() in that case.
0091      */
0092     QRgb selectedBackgroundColor(Theme::TextStyle style) const;
0093 
0094     /**
0095      * Returns whether the given style should be shown in bold.
0096      */
0097     bool isBold(Theme::TextStyle style) const;
0098 
0099     /**
0100      * Returns whether the given style should be shown in italic.
0101      */
0102     bool isItalic(Theme::TextStyle style) const;
0103 
0104     /**
0105      * Returns whether the given style should be shown underlined.
0106      */
0107     bool isUnderline(Theme::TextStyle style) const;
0108 
0109     /**
0110      * Returns whether the given style should be shown struck through.
0111      */
0112     bool isStrikeThrough(Theme::TextStyle style) const;
0113 
0114 public:
0115     /**
0116      * Returns the editor color for the requested @p role.
0117      */
0118     QRgb editorColor(Theme::EditorColorRole role) const;
0119 
0120     /**
0121      * Returns the TextStyle override of a specific "itemData" with attributeName
0122      * in the syntax definition called definitionName.
0123      *
0124      * If no override exists, a valid TextStyleData with the respective default
0125      * TextStyle will be used, so the returned value is always valid.
0126      */
0127     TextStyleData textStyleOverride(const QString &definitionName, const QString &attributeName) const;
0128 
0129     /**
0130      * Returns the TextStyle data for the given @p style.
0131      */
0132     TextStyleData textStyle(Theme::TextStyle style) const;
0133 
0134 private:
0135     int m_revision = 0;
0136     QString m_name;
0137 
0138     //! Path to the file where the theme came from.
0139     //! This is either a resource location (":/themes/Default.theme"), or a file
0140     //! on disk (in a read-only or a writeable location).
0141     QString m_filePath;
0142 
0143     //! TextStyles
0144     std::vector<TextStyleData> m_textStyles;
0145 
0146     //! style overrides for individual itemData entries
0147     //! definition name -> attribute name -> style
0148     QHash<QString, QHash<QString, TextStyleData>> m_textStyleOverrides;
0149 
0150     //! Editor area colors
0151     QRgb m_editorColors[Theme::TemplateReadOnlyPlaceholder + 1];
0152 };
0153 
0154 }
0155 
0156 QT_BEGIN_NAMESPACE
0157 Q_DECLARE_TYPEINFO(KSyntaxHighlighting::TextStyleData, Q_MOVABLE_TYPE);
0158 QT_END_NAMESPACE
0159 
0160 #endif // KSYNTAXHIGHLIGHTING_THEMEDATA_P_H