File indexing completed on 2024-04-28 07:46:40
0001 /* 0002 SPDX-FileCopyrightText: 2012-2018 Dominik Haumann <dhaumann@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KATE_COLOR_TREE_WIDGET_H 0008 #define KATE_COLOR_TREE_WIDGET_H 0009 0010 #include <QTreeWidget> 0011 0012 #include <KSyntaxHighlighting/Theme> 0013 0014 class KateColorItem 0015 { 0016 public: 0017 KateColorItem(KSyntaxHighlighting::Theme::EditorColorRole _role = KSyntaxHighlighting::Theme::BackgroundColor) 0018 : role(_role) 0019 { 0020 } 0021 0022 KSyntaxHighlighting::Theme::EditorColorRole role; 0023 QString name; // translated name 0024 QString category; // translated category for tree view hierarchy 0025 QString whatsThis; // what's this info 0026 QString key; // untranslated id, used as key to save/load from KConfig 0027 QColor color; // user visible color 0028 QColor defaultColor; // used when "Default" is clicked 0029 bool useDefault = true; // flag whether to use the default color 0030 }; 0031 0032 class KateColorTreeWidget : public QTreeWidget 0033 { 0034 Q_OBJECT 0035 friend class KateColorTreeItem; 0036 friend class KateColorTreeDelegate; 0037 0038 public: 0039 explicit KateColorTreeWidget(QWidget *parent = nullptr); 0040 0041 public: 0042 void addColorItem(const KateColorItem &colorItem); 0043 void addColorItems(const QList<KateColorItem> &colorItems); 0044 0045 QList<KateColorItem> colorItems() const; 0046 0047 QColor findColor(const QString &key) const; 0048 0049 bool readOnly() const; 0050 void setReadOnly(bool readOnly); 0051 0052 public Q_SLOTS: 0053 void selectDefaults(); 0054 0055 Q_SIGNALS: 0056 void changed(); 0057 0058 protected: 0059 bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event) override; 0060 void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const override; 0061 0062 private: 0063 bool m_readOnly = false; 0064 }; 0065 0066 #endif