2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-06-17 10:39:46 +08:00
|
|
|
#ifndef COLORSCHEME_H
|
|
|
|
#define COLORSCHEME_H
|
|
|
|
|
|
|
|
#include <QColor>
|
2022-12-10 21:23:49 +08:00
|
|
|
#include "qsynedit/syntaxer/syntaxer.h"
|
2021-11-07 22:34:19 +08:00
|
|
|
#include "parser/statementmodel.h"
|
2021-06-17 10:39:46 +08:00
|
|
|
|
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"
|
2021-11-03 18:09:12 +08:00
|
|
|
#define COLOR_SCHEME_GUTTER_ACTIVE_LINE "Gutter Active Line"
|
2021-06-18 22:57:19 +08:00
|
|
|
#define COLOR_SCHEME_SELECTION "Selected text"
|
2021-11-03 18:09:12 +08:00
|
|
|
#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);
|
|
|
|
|
2021-11-03 18:09:12 +08:00
|
|
|
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);
|
|
|
|
|
2021-06-19 22:58:35 +08:00
|
|
|
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;
|
2021-06-19 22:58:35 +08:00
|
|
|
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());
|
2021-06-19 22:58:35 +08:00
|
|
|
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);
|
2021-06-19 22:58:35 +08:00
|
|
|
PColorSchemeItem getItem(const QString& schemeName, const QString& itemName);
|
2021-06-17 10:39:46 +08:00
|
|
|
bool isValidName(const QString& name);
|
2021-06-19 22:58:35 +08:00
|
|
|
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-11-07 22:34:19 +08:00
|
|
|
void updateStatementColors(
|
|
|
|
std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > statementColors,
|
|
|
|
const QString& schemeName);
|
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:
|
2021-06-19 22:58:35 +08:00
|
|
|
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
|