aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/3rdparty/syntax-highlighting/src/lib/themedata_p.h
blob: 6ee772f172c3b25dab2c1ae47f1e91772f3eb2b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
    SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
    SPDX-FileCopyrightText: 2016 Dominik Haumann <dhaumann@kde.org>

    SPDX-License-Identifier: MIT
*/

#ifndef KSYNTAXHIGHLIGHTING_THEMEDATA_P_H
#define KSYNTAXHIGHLIGHTING_THEMEDATA_P_H

#include "textstyledata_p.h"
#include "theme.h"

#include <QHash>
#include <QSharedData>

#include <vector>

namespace KSyntaxHighlighting
{
/**
 * Data container for a Theme.
 */
class ThemeData : public QSharedData
{
public:
    static ThemeData *get(const Theme &theme)
    {
        return theme.m_data.data();
    }

    /**
     * Default constructor, creating an uninitialized ThemeData instance.
     */
    ThemeData();

    /**
     * Load the Theme data from the file @p filePath.
     * Note, that @p filePath either is a local file, or a qt resource location.
     */
    bool load(const QString &filePath);

    void loadComplete();

    /**
     * Returns the unique name of this Theme.
     */
    QString name() const;

    /**
     * Returns the revision of this Theme.
     * The revision in a .theme file should be increased with every change.
     */
    int revision() 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(Theme::TextStyle style) const;

    /**
     * Returns the text color for selected to be used for @p style.
     * @c 0 is returned for styles that do not specify a selected text color,
     * use the textColor() in that case.
     */
    QRgb selectedTextColor(Theme::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(Theme::TextStyle style) const;

    /**
     * Returns the background color for selected text to be used for @p style.
     * @c 0 is returned for styles that do not specify a selected background
     * color, use the default backgroundColor() in that case.
     */
    QRgb selectedBackgroundColor(Theme::TextStyle style) const;

    /**
     * Returns whether the given style should be shown in bold.
     */
    bool isBold(Theme::TextStyle style) const;

    /**
     * Returns whether the given style should be shown in italic.
     */
    bool isItalic(Theme::TextStyle style) const;

    /**
     * Returns whether the given style should be shown underlined.
     */
    bool isUnderline(Theme::TextStyle style) const;

    /**
     * Returns whether the given style should be shown struck through.
     */
    bool isStrikeThrough(Theme::TextStyle style) const;

public:
    /**
     * Returns the editor color for the requested @p role.
     */
    QRgb editorColor(Theme::EditorColorRole role) const;

    /**
     * Returns the TextStyle override of a specific "itemData" with attributeName
     * in the syntax definition called definitionName.
     *
     * If no override exists, a valid TextStyleData with the respective default
     * TextStyle will be used, so the returned value is always valid.
     */
    TextStyleData textStyleOverride(const QString &definitionName, const QString &attributeName) const;

    /**
     * Returns the TextStyle data for the given @p style.
     */
    TextStyleData textStyle(Theme::TextStyle style) const;

private:
    int m_revision = 0;
    QString m_name;

    //! Path to the file where the theme came from.
    //! This is either a resource location (":/themes/Default.theme"), or a file
    //! on disk (in a read-only or a writeable location).
    QString m_filePath;

    bool m_completelyLoaded = false;

    //! TextStyles
    std::vector<TextStyleData> m_textStyles;

    //! style overrides for individual itemData entries
    //! definition name -> attribute name -> style
    QHash<QString, QHash<QString, TextStyleData>> m_textStyleOverrides;

    //! Editor area colors
    QRgb m_editorColors[Theme::TemplateReadOnlyPlaceholder + 1];
};

}

QT_BEGIN_NAMESPACE
Q_DECLARE_TYPEINFO(KSyntaxHighlighting::TextStyleData, Q_RELOCATABLE_TYPE);
QT_END_NAMESPACE

#endif // KSYNTAXHIGHLIGHTING_THEMEDATA_P_H