1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
/*
This file is part of KCachegrind.
SPDX-FileCopyrightText: 2010-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
SPDX-License-Identifier: GPL-2.0-only
*/
/*
* Global configuration for GUI components of KCachegrind
*/
#ifndef GLOBALGUICONFIG_H
#define GLOBALGUICONFIG_H
#include <QColor>
#include <QString>
#include <QHash>
#include "globalconfig.h"
/**
* Color setting for a cost item
* Helper class for color settings in configuration.
*
* Objects can only be instantiated by the singleton GlobalConfig
* and therefore are unique; changes will be saved as configuration.
*/
class ConfigColorSetting
{
friend class GlobalGUIConfig;
friend class ConfigDlg;
public:
QColor color() const { return _color; }
bool automatic() const { return _automatic; }
static QColor colorForName(QString);
// returns automatic color calculated from name, but does not change color
QColor autoColor() const;
// explicitly set a color, switches off automatic mode
void setColor(const QColor&);
// reset to automatic mode
void reset();
private:
explicit ConfigColorSetting(QString n); // color calculated from name
ConfigColorSetting(QString, QColor); // color set explicitly
QString _name;
QColor _color;
bool _automatic;
};
/**
* Extension of global configuration for GUI options.
* A singleton.
*/
class GlobalGUIConfig: public GlobalConfig
{
friend class ConfigDlg;
public:
GlobalGUIConfig();
~GlobalGUIConfig() override;
// gets the singleton instance
static GlobalGUIConfig* config();
void saveOptions() override;
void readOptions() override;
// color for visualization of an object
static QColor functionColor(ProfileContext::Type gt, TraceFunction*);
static QColor groupColor(CostItem*);
static QColor eventTypeColor(EventType*);
static ConfigColorSetting* groupColorSetting(CostItem*);
static ConfigColorSetting* groupColorSetting(ProfileContext::Type, QString);
protected:
static ConfigColorSetting* colorSetting(const QString&, bool createNew = true);
QHash<QString, ConfigColorSetting*> _colors;
};
#endif // GLOBALGUICONFIG_H
|