File indexing completed on 2024-05-05 12:22:45

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, QVector<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, QVector<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     Q_OBJECT
0132 
0133 public:
0134     explicit KateThemeConfigPage(QWidget *parent);
0135     QString name() const override;
0136     QString fullName() const override;
0137     QIcon icon() const override;
0138 
0139 public Q_SLOTS:
0140     void apply() override;
0141     void reload() override;
0142     void reset() override;
0143     void defaults() override;
0144     void exportFullSchema();
0145     void importFullSchema();
0146 
0147 private Q_SLOTS:
0148     void layoutThemeChooserTab(QWidget *tab);
0149     void layoutThemeEditorTab(QWidget *tab);
0150     void deleteSchema();
0151     bool copyTheme();
0152     void schemaChanged(const QString &schema);
0153     void comboBoxIndexChanged(int currentIndex);
0154 
0155 private:
0156     void refillCombos(const QString &schemaName, const QString &defaultSchemaName);
0157 
0158 private:
0159     QString m_currentSchema;
0160 
0161     KMessageWidget *m_readOnlyThemeLabel = nullptr;
0162     class QPushButton *btndel;
0163     class QComboBox *defaultSchemaCombo;
0164     class QComboBox *schemaCombo;
0165     KateThemeConfigColorTab *m_colorTab;
0166     KateThemeConfigDefaultStylesTab *m_defaultStylesTab;
0167     KateThemeConfigHighlightTab *m_highlightTab;
0168     KTextEditor::DocumentPrivate *m_doc = nullptr;
0169     KTextEditor::ViewPrivate *m_themePreview = nullptr;
0170 };
0171 
0172 #endif