diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index c1f1d967..fdbf9e1c 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -109,6 +109,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target RESOURCES += \ + colorschemes.qrc \ themes/dark/dark.qrc \ themes/light/light.qrc \ themes/dracula/dracula.qrc \ diff --git a/RedPandaIDE/colorscheme.cpp b/RedPandaIDE/colorscheme.cpp index e016946d..bbcc4d5e 100644 --- a/RedPandaIDE/colorscheme.cpp +++ b/RedPandaIDE/colorscheme.cpp @@ -15,50 +15,32 @@ ColorScheme::ColorScheme() } -QString ColorScheme::name() const +PColorScheme ColorScheme::fromJson(const QJsonObject &json) { - return mName; -} - -void ColorScheme::setName(const QString &name) -{ - mName = name; -} - -void ColorScheme::read(const QJsonObject &json) -{ - if (json.contains("name") && json["name"].isString()) { - setName(json["name"].toString()); - } else { - setName(""); - } - mItems.clear(); - if (json.contains("items") && json["items"].isObject()) { - QJsonObject itemsList = json["items"].toObject(); - for (QString key:itemsList.keys()) { - PColorSchemeItem item = std::make_shared(key); - item->read(itemsList[key].toObject()); + PColorScheme scheme = std::make_shared(); + scheme->mItems.clear(); + for (QString key:json.keys()) { + if (json[key].isObject()) { + scheme->mItems[key]=ColorSchemeItem::fromJson(json[key].toObject()); } } + return scheme; } -void ColorScheme::write(QJsonObject &json) +void ColorScheme::toJson(QJsonObject &json) { - json["name"] = mName; - QJsonObject itemsList; - for (PColorSchemeItem item:mItems) { - if (!item->name().isEmpty()) { + for (QString key:mItems.keys()) { + PColorSchemeItem item = mItems[key]; + if (item) { QJsonObject itemObject; - item->write(itemObject); - itemsList[item->name()] = itemObject; + item->toJson(itemObject); + json[key] = itemObject; } } - json["items"]=itemsList; } PColorScheme ColorScheme::load(const QString &filename) { - PColorScheme scheme = std::make_shared(); QFile file(filename); if (!file.open(QFile::ReadOnly)) { throw new FileError(QObject::tr("Can't open file '%1' for read").arg(file.fileName())); @@ -74,8 +56,7 @@ PColorScheme ColorScheme::load(const QString &filename) throw new FileError(QObject::tr("Can't parse json file '%1' is not a color schema config file!") .arg(file.fileName())); } - scheme->read(doc.object()); - return scheme; + return ColorScheme::fromJson(doc.object()); } void ColorScheme::save(const QString &filename) @@ -85,7 +66,7 @@ void ColorScheme::save(const QString &filename) throw new FileError(QObject::tr("Can't open file '%1' for write").arg(file.fileName())); } QJsonObject json; - write(json); + toJson(json); QJsonDocument doc(json); QByteArray content = doc.toJson(); file.write(content); @@ -121,8 +102,7 @@ void ColorScheme::setPreferThemeType(const QString &preferThemeType) mPreferThemeType = preferThemeType; } -ColorSchemeItem::ColorSchemeItem(const QString& name): - mName(name), +ColorSchemeItem::ColorSchemeItem(): mForeground(), mBackground(), mBold(false), @@ -133,11 +113,6 @@ ColorSchemeItem::ColorSchemeItem(const QString& name): } -QString ColorSchemeItem::name() const -{ - return mName; -} - QColor ColorSchemeItem::foreground() const { return mForeground; @@ -198,42 +173,43 @@ void ColorSchemeItem::setStrikeout(bool strikeout) mStrikeout = strikeout; } -void ColorSchemeItem::read(const QJsonObject &json) +PColorSchemeItem ColorSchemeItem::fromJson(const QJsonObject &json) { + PColorSchemeItem item = std::make_shared(); if (json.contains("foreground") && json["foreground"].isString()) { - setForeground(json["foreground"].toString()); + item->setForeground(json["foreground"].toString()); } else { - setForeground(QColor()); + item->setForeground(QColor()); } if (json.contains("background") && json["background"].isString()) { - setBackground(json["background"].toString()); + item->setBackground(json["background"].toString()); } else { - setBackground(QColor()); + item->setBackground(QColor()); } if (json.contains("bold") && json["bold"].isBool()) { - setBold(json["bold"].toBool()); + item->setBold(json["bold"].toBool()); } else { - setBold(false); + item->setBold(false); } if (json.contains("italic") && json["italic"].isBool()) { - setBold(json["italic"].toBool()); + item->setBold(json["italic"].toBool()); } else { - setItalic(false); + item->setItalic(false); } if (json.contains("underlined") && json["underlined"].isBool()) { - setBold(json["underlined"].toBool()); + item->setBold(json["underlined"].toBool()); } else { - setUnderlined(false); + item->setUnderlined(false); } if (json.contains("strikeout") && json["strikeout"].isBool()) { - setBold(json["strikeout"].toBool()); + item->setBold(json["strikeout"].toBool()); } else { - setUnderlined(false); + item->setUnderlined(false); } - + return item; } -void ColorSchemeItem::write(QJsonObject &json) +void ColorSchemeItem::toJson(QJsonObject &json) { if (mForeground.isValid()) { json["foreground"] = mForeground.name(); @@ -307,7 +283,6 @@ PColorScheme ColorManager::copy(const QString &sourceName) sourceScheme->save(newFilepath); // then load it to the copied PColorScheme newScheme = ColorScheme::load(newFilepath); - newScheme->setName(newName); newScheme->setBundled(false); newScheme->setCustomed(false); mSchemes[newName]=newScheme; @@ -337,9 +312,12 @@ void ColorManager::loadSchemesInDir(const QString &dirName, bool isCustomed) } for (int i=0;iname()]=scheme; + name.remove(name.length()-suffix.length(),suffix.length()); + name.replace('_',' '); + mSchemes[name]=scheme; } } } diff --git a/RedPandaIDE/colorscheme.h b/RedPandaIDE/colorscheme.h index a40a5239..493a268f 100644 --- a/RedPandaIDE/colorscheme.h +++ b/RedPandaIDE/colorscheme.h @@ -7,25 +7,27 @@ #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_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" + +class ColorSchemeItem; +using PColorSchemeItem = std::shared_ptr; class ColorSchemeItem { public: - explicit ColorSchemeItem(const QString& name); - QString name() const; + explicit ColorSchemeItem(); QColor foreground() const; void setForeground(const QColor &foreground); @@ -45,11 +47,10 @@ public: bool strikeout() const; void setStrikeout(bool strikeout); - void read(const QJsonObject& json); - void write(QJsonObject& json); + static PColorSchemeItem fromJson(const QJsonObject& json); + void toJson(QJsonObject& json); private: - QString mName; QColor mForeground; QColor mBackground; bool mBold; @@ -58,7 +59,6 @@ private: bool mStrikeout; }; -using PColorSchemeItem = std::shared_ptr; class ColorScheme; using PColorScheme = std::shared_ptr; @@ -70,11 +70,9 @@ public: static PColorScheme load(const QString& filename); QMap items(); - QString name() const; - void setName(const QString &name); - void read(const QJsonObject& json); - void write(QJsonObject& json); + static PColorScheme fromJson(const QJsonObject& json); + void toJson(QJsonObject& json); //void load(); void save(const QString& filename); @@ -89,7 +87,6 @@ public: void setPreferThemeType(const QString &preferThemeType); private: QMap mItems; - QString mName; QString mPreferThemeType; bool mBundled; bool mCustomed; diff --git a/RedPandaIDE/colorschemes/vs_code.scheme b/RedPandaIDE/colorschemes/vs_code.scheme new file mode 100644 index 00000000..ddb4786c --- /dev/null +++ b/RedPandaIDE/colorschemes/vs_code.scheme @@ -0,0 +1,184 @@ +{ + "Assembler" : { + "foreground" : "#FF00FF", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Character" : { + "foreground" : "#D69D85", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Class" : { + "foreground" : "#4EC9B0", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Comment" : { + "foreground" : "#6A9955", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Float" : { + "foreground" : "#B5CEA8", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Function" : { + "foreground" : "#BFBFFF", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Global variable" : { + "foreground" : "#BFBFFF", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Hexadecimal" : { + "foreground" : "#B5CEA8", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Identifier" : { + "foreground" : "#DCDCAA", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Illegal Char" : { + "foreground" : "#FF3C3C", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Local Variable" : { + "foreground" : "#9CDCFE", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Number" : { + "foreground" : "#9CDCFE", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Octal" : { + "foreground" : "#B5CEA8", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Preprocessor" : { + "foreground" : "#C586C0", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Reserved Word" : { + "foreground" : "#569CD6", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Space" : { + "foreground" : "#505050", + "background" : "#1E1E1E", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "String" : { + "foreground" : "#D69D85", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Symbol" : { + "foreground" : "#D4D4D4", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Variable" : { + "foreground" : "#9CDCFE", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Escape sequences" : { + "foreground" : "#B5CEA8", + "bold" : false, + "italic" : false, + "underlined" : false, + "strikeout" : false + }, + "Selected text" : { + "foreground" : "#000000", + "background" : "#808080" + }, + "Gutter" : { + "foreground" : "#858585", + "background" : "#1E1E1E" + }, + "Breakpoint": { + }, + "Error" : { + "foreground" : "#C0C0C0" + }, + "Active Breakpoint" : { + "foreground" : "#FFFFCE", + "background" : "#00376F" + }, + "Fold Line" : { + "foreground" : "#C0C0C0" + }, + "Active Line" : { + "background" : "#323232" + }, + "Warning" : { + "foreground" : "#FF8040" + }, + "Indent Guide Line" : { + "foreground" : "#C0C0C0" + }, + "brace/parenthesis/bracket level 1" : { + "foreground" : "#D4D4D4" + }, + "brace/parenthesis/bracket level 2" : { + "foreground" : "#9CDCFE" + }, + "brace/parenthesis/bracket level 3" : { + "foreground" : "#FF00FF" + }, + "brace/parenthesis/bracket level 4" : { + "foreground" : "#C586C0" + } +} \ No newline at end of file diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 89e4e348..8ee7844d 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -2317,7 +2317,7 @@ void SynEdit::updateCaret() DisplayCoord coord = displayXY(); QPoint caretPos = RowColumnToPixels(coord); int caretWidth=mCharWidth; - qDebug()<<"caret"<count() && mCaretX <= mLines->getString(mCaretY-1).length()) { caretWidth = charColumns(mLines->getString(mCaretY-1)[mCaretX-1])*mCharWidth; } diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 7b98d8af..db27b94d 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -107,7 +107,7 @@ QString Settings::Dirs::data(Settings::Dirs::DataType dataType) const case DataType::None: return dataDir; case DataType::ColorSheme: - return includeTrailingPathDelimiter(dataDir)+"scheme"; + return ":/colorschemes/colorschemes"; } } diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp index f0d70bfc..f44bf714 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp @@ -1,11 +1,17 @@ #include "editorcolorschemewidget.h" #include "ui_editorcolorschemewidget.h" +#include "../settings.h" +#include "../colorscheme.h" EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QString& group, QWidget *parent) : SettingsWidget(name,group,parent), ui(new Ui::EditorColorSchemeWidget) { ui->setupUi(this); + + for (QString schemeName: pColorManager->getSchemes()) { + ui->cbScheme->addItem(schemeName); + } } EditorColorSchemeWidget::~EditorColorSchemeWidget() diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui b/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui index fbb327be..99ffbc85 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.ui @@ -31,7 +31,7 @@ - + @@ -100,20 +100,13 @@ 0 - + - - - - TextLabel - - - - + Foreground: @@ -139,21 +132,21 @@ - + Bold - + Italic - + Underlined @@ -162,17 +155,30 @@ - - + + - TextLabel + Background: - - - - Background: + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + QFrame::StyledPanel + + + QFrame::Raised