File indexing completed on 2024-04-28 05:41:33
0001 /* 0002 This file is part of KCachegrind. 0003 0004 SPDX-FileCopyrightText: 2010-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-only 0007 */ 0008 0009 /* 0010 * Global configuration for GUI components of KCachegrind 0011 */ 0012 0013 #ifndef GLOBALGUICONFIG_H 0014 #define GLOBALGUICONFIG_H 0015 0016 #include <QColor> 0017 #include <QString> 0018 #include <QHash> 0019 0020 #include "globalconfig.h" 0021 0022 /** 0023 * Color setting for a cost item 0024 * Helper class for color settings in configuration. 0025 * 0026 * Objects can only be instantiated by the singleton GlobalConfig 0027 * and therefore are unique; changes will be saved as configuration. 0028 */ 0029 class ConfigColorSetting 0030 { 0031 friend class GlobalGUIConfig; 0032 friend class ConfigDlg; 0033 0034 public: 0035 QColor color() const { return _color; } 0036 bool automatic() const { return _automatic; } 0037 0038 static QColor colorForName(QString); 0039 // returns automatic color calculated from name, but does not change color 0040 QColor autoColor() const; 0041 0042 // explicitly set a color, switches off automatic mode 0043 void setColor(const QColor&); 0044 // reset to automatic mode 0045 void reset(); 0046 0047 private: 0048 explicit ConfigColorSetting(QString n); // color calculated from name 0049 ConfigColorSetting(QString, QColor); // color set explicitly 0050 0051 QString _name; 0052 QColor _color; 0053 bool _automatic; 0054 }; 0055 0056 0057 /** 0058 * Extension of global configuration for GUI options. 0059 * A singleton. 0060 */ 0061 class GlobalGUIConfig: public GlobalConfig 0062 { 0063 friend class ConfigDlg; 0064 0065 public: 0066 GlobalGUIConfig(); 0067 ~GlobalGUIConfig() override; 0068 0069 // gets the singleton instance 0070 static GlobalGUIConfig* config(); 0071 0072 void saveOptions() override; 0073 void readOptions() override; 0074 0075 // color for visualization of an object 0076 static QColor functionColor(ProfileContext::Type gt, TraceFunction*); 0077 static QColor groupColor(CostItem*); 0078 static QColor eventTypeColor(EventType*); 0079 static ConfigColorSetting* groupColorSetting(CostItem*); 0080 static ConfigColorSetting* groupColorSetting(ProfileContext::Type, QString); 0081 0082 protected: 0083 static ConfigColorSetting* colorSetting(const QString&, bool createNew = true); 0084 QHash<QString, ConfigColorSetting*> _colors; 0085 }; 0086 0087 #endif // GLOBALGUICONFIG_H