RedPanda-CPP/RedPandaIDE/colorscheme.h

163 lines
4.6 KiB
C
Raw Normal View History

2021-06-17 10:39:46 +08:00
#ifndef COLORSCHEME_H
#define COLORSCHEME_H
#include <QColor>
#include <qsynedit/highlighter/base.h>
2021-06-18 08:09:32 +08:00
#define EXT_COLOR_SCHEME ".scheme"
#define EXT_PREFIX_CUSTOM ".custom"
2021-06-18 22:57:19 +08:00
#define COLOR_SCHEME_BREAKPOINT "Breakpoint"
#define COLOR_SCHEME_ERROR "Error"
#define COLOR_SCHEME_ACTIVE_BREAKPOINT "Active Breakpoint"
#define COLOR_SCHEME_GUTTER "Gutter"
#define COLOR_SCHEME_GUTTER_ACTIVE_LINE "Gutter Active Line"
2021-06-18 22:57:19 +08:00
#define COLOR_SCHEME_SELECTION "Selected text"
#define COLOR_SCHEME_TEXT "Editor Text"
#define COLOR_SCHEME_CURRENT_HIGHLIGHTED_WORD "Current Highlighted Word"
2021-06-18 22:57:19 +08:00
#define COLOR_SCHEME_FOLD_LINE "Fold Line"
#define COLOR_SCHEME_ACTIVE_LINE "Active Line"
#define COLOR_SCHEME_WARNING "Warning"
#define COLOR_SCHEME_INDENT_GUIDE_LINE "Indent Guide Line"
2021-06-18 08:09:32 +08:00
#define COLOR_SCHEME_BRACE_1 "brace/parenthesis/bracket level 1"
#define COLOR_SCHEME_BRACE_2 "brace/parenthesis/bracket level 2"
#define COLOR_SCHEME_BRACE_3 "brace/parenthesis/bracket level 3"
#define COLOR_SCHEME_BRACE_4 "brace/parenthesis/bracket level 4"
2021-06-18 22:57:19 +08:00
class ColorSchemeItem;
using PColorSchemeItem = std::shared_ptr<ColorSchemeItem>;
2021-06-17 10:39:46 +08:00
class ColorSchemeItem {
public:
2021-06-18 22:57:19 +08:00
explicit ColorSchemeItem();
2021-06-17 10:39:46 +08:00
QColor foreground() const;
void setForeground(const QColor &foreground);
QColor background() const;
void setBackground(const QColor &background);
bool bold() const;
void setBold(bool bold);
bool italic() const;
void setItalic(bool italic);
bool underlined() const;
void setUnderlined(bool underlined);
bool strikeout() const;
void setStrikeout(bool strikeout);
2021-06-18 22:57:19 +08:00
static PColorSchemeItem fromJson(const QJsonObject& json);
void toJson(QJsonObject& json);
2021-06-17 10:39:46 +08:00
private:
QColor mForeground;
QColor mBackground;
bool mBold;
bool mItalic;
bool mUnderlined;
bool mStrikeout;
};
class ColorScheme;
using PColorScheme = std::shared_ptr<ColorScheme>;
class ColorScheme
{
public:
explicit ColorScheme();
2021-06-18 08:09:32 +08:00
static PColorScheme load(const QString& filename);
void addItem(const QString& name);
2021-06-17 10:39:46 +08:00
QMap<QString,PColorSchemeItem> items();
2021-06-18 22:57:19 +08:00
static PColorScheme fromJson(const QJsonObject& json);
void toJson(QJsonObject& json);
2021-06-17 10:39:46 +08:00
2021-06-18 08:09:32 +08:00
//void load();
2021-06-17 10:39:46 +08:00
void save(const QString& filename);
bool bundled() const;
void setBundled(bool bundled);
2021-06-18 08:09:32 +08:00
bool customed() const;
void setCustomed(bool customed);
2021-06-17 10:39:46 +08:00
QString preferThemeType() const;
void setPreferThemeType(const QString &preferThemeType);
private:
QMap<QString,PColorSchemeItem> mItems;
QString mPreferThemeType;
bool mBundled;
2021-06-18 08:09:32 +08:00
bool mCustomed;
2021-06-17 10:39:46 +08:00
};
class ColorSchemeItemDefine {
public:
2021-06-18 08:09:32 +08:00
explicit ColorSchemeItemDefine();
2021-06-17 10:39:46 +08:00
bool hasBackground() const;
void setHasBackground(bool hasBackground);
bool hasForeground() const;
void setHasForeground(bool hasForeground);
2021-06-18 08:09:32 +08:00
bool hasFontStyle() const;
2021-06-17 10:39:46 +08:00
void setHasFontStyle(bool value);
QString group() const;
void setGroup(const QString &group);
QString displayName() const;
void setDisplayName(const QString &displayName);
2021-06-17 10:39:46 +08:00
private:
bool mHasBackground;
bool mHasForeground;
2021-06-18 08:09:32 +08:00
bool mHasFontStyle;
QString mGroup;
QString mDisplayName;
2021-06-17 10:39:46 +08:00
};
using PColorSchemeItemDefine = std::shared_ptr<ColorSchemeItemDefine>;
class ColorManager {
public:
2021-06-18 08:09:32 +08:00
explicit ColorManager();
2021-06-17 10:39:46 +08:00
void init();
void reload();
2021-06-18 08:09:32 +08:00
QStringList getSchemes(const QString& themeType = QString());
QStringList getDefines();
2021-06-17 10:39:46 +08:00
bool exists(const QString name);
2021-06-20 14:49:38 +08:00
QString copy(const QString& source);
2021-06-20 22:54:16 +08:00
bool restoreToDefault(const QString& name);
bool remove(const QString& name);
2021-06-17 10:39:46 +08:00
bool rename(const QString& oldName, const QString& newName);
2021-06-20 22:54:16 +08:00
bool add(const QString& name, PColorScheme scheme);
2021-06-17 10:39:46 +08:00
PColorScheme get(const QString& name);
PColorSchemeItem getItem(const QString& schemeName, const QString& itemName);
2021-06-17 10:39:46 +08:00
bool isValidName(const QString& name);
void addDefine(const QString& name, const QString& displayName, const QString& group, bool hasForeground, bool hasBackground, bool hasFontStyle);
2021-06-17 10:39:46 +08:00
bool removeDefine(const QString &name);
PColorSchemeItemDefine getDefine(const QString& name);
2021-06-20 14:30:47 +08:00
bool saveScheme(const QString &name);
2021-06-17 10:39:46 +08:00
private:
2021-06-18 08:09:32 +08:00
QString generateFullPathname(const QString& name, bool isBundled, bool isCustomed);
QString generateFilename(const QString& name, bool isCustomed);
2021-06-20 14:30:47 +08:00
void loadSchemesInDir(const QString& dirName, bool isBundled, bool isCustomed);
2021-06-18 08:09:32 +08:00
void initItemDefines();
private:
QMap<QString,PColorSchemeItemDefine> mSchemeItemDefines;
2021-06-17 10:39:46 +08:00
QMap<QString,PColorScheme> mSchemes;
2021-06-18 08:09:32 +08:00
PColorSchemeItemDefine mDefaultSchemeItemDefine;
2021-06-17 10:39:46 +08:00
};
2021-06-18 21:48:40 +08:00
extern ColorManager * pColorManager;
2021-06-17 10:39:46 +08:00
#endif // COLORSCHEME_H