RedPanda-CPP/RedPandaIDE/colorscheme.h

145 lines
3.9 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_SELECTION "Selected text"
#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);
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);
private:
bool mHasBackground;
bool mHasForeground;
2021-06-18 08:09:32 +08:00
bool mHasFontStyle;
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());
2021-06-17 10:39:46 +08:00
bool exists(const QString name);
PColorScheme copy(const QString& source);
bool rename(const QString& oldName, const QString& newName);
PColorScheme remove(const QString& name);
PColorScheme get(const QString& name);
bool isValidName(const QString& name);
void addDefine(const QString& name, bool hasForeground, bool hasBackground, bool hasFontStyle);
bool removeDefine(const QString &name);
PColorSchemeItemDefine getDefine(const QString& name);
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);
void loadSchemesInDir(const QString& dirName, bool isCustomed);
void initItemDefines();
private:
QMap<QString,PColorSchemeItemDefine> mSchemeItemDefine;
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