File indexing completed on 2024-04-21 03:57:44

0001 /*
0002     SPDX-FileCopyrightText: 2001-2003 Christoph Cullmann <cullmann@kde.org>
0003     SPDX-FileCopyrightText: 2002, 2003 Anders Lund <anders.lund@lund.tdcadsl.dk>
0004     SPDX-FileCopyrightText: 2012-2018 Dominik Haumann <dhaumann@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KATE_SCHEMA_CONFIG_H
0010 #define KATE_SCHEMA_CONFIG_H
0011 
0012 #include "kateconfigpage.h"
0013 #include "kateextendedattribute.h"
0014 
0015 #include <map>
0016 #include <unordered_map>
0017 
0018 class KateStyleTreeWidget;
0019 class KateColorTreeWidget;
0020 class KMessageWidget;
0021 class KateColorItem;
0022 
0023 namespace KTextEditor
0024 {
0025 class ViewPrivate;
0026 class DocumentPrivate;
0027 }
0028 
0029 class QComboBox;
0030 
0031 class KateThemeConfigColorTab : public QWidget
0032 {
0033     Q_OBJECT
0034 
0035 public:
0036     KateThemeConfigColorTab();
0037 
0038     QColor backgroundColor() const;
0039     QColor selectionColor() const;
0040 
0041 public Q_SLOTS:
0042     void apply();
0043     void reload();
0044     void schemaChanged(const QString &newSchema);
0045 
0046 Q_SIGNALS:
0047     void changed();
0048 
0049 private:
0050     // multiple shemas may be edited. Hence, we need one ColorList for each schema
0051     std::map<QString, QList<KateColorItem>> m_schemas;
0052     QString m_currentSchema;
0053     KateColorTreeWidget *ui;
0054 };
0055 
0056 class KateThemeConfigDefaultStylesTab : public QWidget
0057 {
0058     Q_OBJECT
0059 
0060 public:
0061     explicit KateThemeConfigDefaultStylesTab(KateThemeConfigColorTab *colorTab);
0062 
0063 Q_SIGNALS:
0064     void changed();
0065 
0066 public:
0067     void schemaChanged(const QString &schema);
0068     void reload();
0069     void apply();
0070 
0071     KateAttributeList *attributeList(const QString &schema);
0072 
0073 protected:
0074     void showEvent(QShowEvent *event) override;
0075     void updateColorPalette(const QColor &textColor);
0076 
0077 private:
0078     KateStyleTreeWidget *m_defaultStyles;
0079     std::unordered_map<QString, KateAttributeList> m_defaultStyleLists;
0080     KateThemeConfigColorTab *m_colorTab;
0081     QString m_currentSchema;
0082 };
0083 
0084 class KateThemeConfigHighlightTab : public QWidget
0085 {
0086     Q_OBJECT
0087 
0088 public:
0089     explicit KateThemeConfigHighlightTab(KateThemeConfigDefaultStylesTab *page, KateThemeConfigColorTab *colorTab);
0090 
0091     void schemaChanged(const QString &schema);
0092     void reload();
0093     void apply();
0094 
0095 Q_SIGNALS:
0096     void changed();
0097 
0098 protected Q_SLOTS:
0099     void hlChanged(int z);
0100 
0101 protected:
0102     void showEvent(QShowEvent *event) override;
0103     void updateColorPalette(const QColor &textColor);
0104 
0105 private:
0106     KateThemeConfigDefaultStylesTab *m_defaults;
0107     KateThemeConfigColorTab *m_colorTab;
0108 
0109     QComboBox *hlCombo;
0110     KateStyleTreeWidget *m_styles;
0111 
0112     QString m_schema;
0113     int m_hl;
0114 
0115     QHash<QString, QHash<int, QList<KTextEditor::Attribute::Ptr>>> m_hlDict;
0116 
0117     /**
0118      * store attribute we modify
0119      * this unifies them to be unique (aka in all highlighting's the embedded stuff is shared!)
0120      *
0121      * theme => highlighting => attribute => pair of value + default
0122      */
0123     std::map<QString, std::map<QString, std::map<QString, std::pair<KTextEditor::Attribute::Ptr, KTextEditor::Attribute::Ptr>>>> m_uniqueAttributes;
0124 
0125 public:
0126     QList<int> hlsForSchema(const QString &schema);
0127 };
0128 
0129 class KateThemeConfigPage : public KateConfigPage
0130 {
0131 public:
0132     explicit KateThemeConfigPage(QWidget *parent);
0133     QString name() const override;
0134     QString fullName() const override;
0135     QIcon icon() const override;
0136 
0137 public:
0138     void apply() override;
0139     void reload() override;
0140     void reset() override;
0141     void defaults() override;
0142     void exportFullSchema();
0143     void importFullSchema();
0144 
0145 private:
0146     void layoutThemeChooserTab(QWidget *tab);
0147     void layoutThemeEditorTab(QWidget *tab);
0148     void deleteSchema();
0149     bool copyTheme();
0150     void schemaChanged(const QString &schema);
0151     void comboBoxIndexChanged(int currentIndex);
0152 
0153 private:
0154     void refillCombos(const QString &schemaName, const QString &defaultSchemaName);
0155 
0156 private:
0157     QString m_currentSchema;
0158 
0159     KMessageWidget *m_readOnlyThemeLabel = nullptr;
0160     class QPushButton *btndel;
0161     class QComboBox *defaultSchemaCombo;
0162     class QComboBox *schemaCombo;
0163     KateThemeConfigColorTab *m_colorTab;
0164     KateThemeConfigDefaultStylesTab *m_defaultStylesTab;
0165     KateThemeConfigHighlightTab *m_highlightTab;
0166     KTextEditor::DocumentPrivate *m_doc = nullptr;
0167     KTextEditor::ViewPrivate *m_themePreview = nullptr;
0168 };
0169 
0170 #endif