1 | /* |
2 | SPDX-FileCopyrightText: 2001-2003 Christoph Cullmann <cullmann@kde.org> |
3 | SPDX-FileCopyrightText: 2002, 2003 Anders Lund <anders.lund@lund.tdcadsl.dk> |
4 | SPDX-FileCopyrightText: 2012-2018 Dominik Haumann <dhaumann@kde.org> |
5 | |
6 | SPDX-License-Identifier: LGPL-2.0-or-later |
7 | */ |
8 | |
9 | #ifndef KATE_SCHEMA_CONFIG_H |
10 | #define KATE_SCHEMA_CONFIG_H |
11 | |
12 | #include "kateconfigpage.h" |
13 | #include "kateextendedattribute.h" |
14 | |
15 | #include <map> |
16 | #include <unordered_map> |
17 | |
18 | class KateStyleTreeWidget; |
19 | class KateColorTreeWidget; |
20 | class KMessageWidget; |
21 | class KateColorItem; |
22 | |
23 | namespace KTextEditor |
24 | { |
25 | class ViewPrivate; |
26 | class DocumentPrivate; |
27 | } |
28 | |
29 | class QComboBox; |
30 | |
31 | class KateThemeConfigColorTab : public QWidget |
32 | { |
33 | Q_OBJECT |
34 | |
35 | public: |
36 | KateThemeConfigColorTab(); |
37 | |
38 | QColor backgroundColor() const; |
39 | QColor selectionColor() const; |
40 | |
41 | public Q_SLOTS: |
42 | void apply(); |
43 | void reload(); |
44 | void schemaChanged(const QString &newSchema); |
45 | |
46 | Q_SIGNALS: |
47 | void changed(); |
48 | |
49 | private: |
50 | // multiple shemas may be edited. Hence, we need one ColorList for each schema |
51 | std::map<QString, QList<KateColorItem>> m_schemas; |
52 | QString m_currentSchema; |
53 | KateColorTreeWidget *ui; |
54 | }; |
55 | |
56 | class KateThemeConfigDefaultStylesTab : public QWidget |
57 | { |
58 | Q_OBJECT |
59 | |
60 | public: |
61 | explicit KateThemeConfigDefaultStylesTab(KateThemeConfigColorTab *colorTab); |
62 | |
63 | Q_SIGNALS: |
64 | void changed(); |
65 | |
66 | public: |
67 | void schemaChanged(const QString &schema); |
68 | void reload(); |
69 | void apply(); |
70 | |
71 | KateAttributeList *attributeList(const QString &schema); |
72 | |
73 | protected: |
74 | void showEvent(QShowEvent *event) override; |
75 | void updateColorPalette(const QColor &textColor); |
76 | |
77 | private: |
78 | KateStyleTreeWidget *m_defaultStyles; |
79 | std::unordered_map<QString, KateAttributeList> m_defaultStyleLists; |
80 | KateThemeConfigColorTab *m_colorTab; |
81 | QString m_currentSchema; |
82 | }; |
83 | |
84 | class KateThemeConfigHighlightTab : public QWidget |
85 | { |
86 | Q_OBJECT |
87 | |
88 | public: |
89 | explicit KateThemeConfigHighlightTab(KateThemeConfigDefaultStylesTab *page, KateThemeConfigColorTab *colorTab); |
90 | |
91 | void schemaChanged(const QString &schema); |
92 | void reload(); |
93 | void apply(); |
94 | |
95 | Q_SIGNALS: |
96 | void changed(); |
97 | |
98 | protected Q_SLOTS: |
99 | void hlChanged(int z); |
100 | |
101 | protected: |
102 | void showEvent(QShowEvent *event) override; |
103 | void updateColorPalette(const QColor &textColor); |
104 | |
105 | private: |
106 | KateThemeConfigDefaultStylesTab *m_defaults; |
107 | KateThemeConfigColorTab *m_colorTab; |
108 | |
109 | QComboBox *hlCombo; |
110 | KateStyleTreeWidget *m_styles; |
111 | |
112 | QString m_schema; |
113 | int m_hl; |
114 | |
115 | QHash<QString, QHash<int, QList<KTextEditor::Attribute::Ptr>>> m_hlDict; |
116 | |
117 | /** |
118 | * store attribute we modify |
119 | * this unifies them to be unique (aka in all highlighting's the embedded stuff is shared!) |
120 | * |
121 | * theme => highlighting => attribute => pair of value + default |
122 | */ |
123 | std::map<QString, std::map<QString, std::map<QString, std::pair<KTextEditor::Attribute::Ptr, KTextEditor::Attribute::Ptr>>>> m_uniqueAttributes; |
124 | |
125 | public: |
126 | QList<int> hlsForSchema(const QString &schema); |
127 | }; |
128 | |
129 | class KateThemeConfigPage : public KateConfigPage |
130 | { |
131 | public: |
132 | explicit KateThemeConfigPage(QWidget *parent); |
133 | QString name() const override; |
134 | QString fullName() const override; |
135 | QIcon icon() const override; |
136 | |
137 | public: |
138 | void apply() override; |
139 | void reload() override; |
140 | void reset() override; |
141 | void defaults() override; |
142 | void exportFullSchema(); |
143 | void importFullSchema(); |
144 | |
145 | private: |
146 | void layoutThemeChooserTab(QWidget *tab); |
147 | void layoutThemeEditorTab(QWidget *tab); |
148 | void deleteSchema(); |
149 | bool copyTheme(); |
150 | void schemaChanged(const QString &schema); |
151 | void comboBoxIndexChanged(int currentIndex); |
152 | |
153 | private: |
154 | void refillCombos(const QString &schemaName, const QString &defaultSchemaName); |
155 | |
156 | private: |
157 | QString m_currentSchema; |
158 | |
159 | KMessageWidget *m_readOnlyThemeLabel = nullptr; |
160 | class QPushButton *btndel; |
161 | class QComboBox *defaultSchemaCombo; |
162 | class QComboBox *schemaCombo; |
163 | KateThemeConfigColorTab *m_colorTab; |
164 | KateThemeConfigDefaultStylesTab *m_defaultStylesTab; |
165 | KateThemeConfigHighlightTab *m_highlightTab; |
166 | KTextEditor::DocumentPrivate *m_doc = nullptr; |
167 | KTextEditor::ViewPrivate *m_themePreview = nullptr; |
168 | }; |
169 | |
170 | #endif |
171 | |