RedPanda-CPP/RedPandaIDE/colorscheme.h

146 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"
#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"
#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-17 10:39:46 +08:00
class ColorSchemeItem {
public:
explicit ColorSchemeItem(const QString& name);
QString name() const;
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);
void read(const QJsonObject& json);
void write(QJsonObject& json);
private:
QString mName;
QColor mForeground;
QColor mBackground;
bool mBold;
bool mItalic;
bool mUnderlined;
bool mStrikeout;
};
using PColorSchemeItem = std::shared_ptr<ColorSchemeItem>;
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();
QString name() const;
void setName(const QString &name);
void read(const QJsonObject& json);
void write(QJsonObject& json);
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 mName;
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
};
#endif // COLORSCHEME_H