* work save: can load color scheme now
This commit is contained in:
parent
bfe1b05394
commit
e3abdb88b7
|
@ -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 \
|
||||
|
|
|
@ -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<ColorSchemeItem>(key);
|
||||
item->read(itemsList[key].toObject());
|
||||
PColorScheme scheme = std::make_shared<ColorScheme>();
|
||||
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<ColorScheme>();
|
||||
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<ColorSchemeItem>();
|
||||
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;i<list.size();i++) {
|
||||
QFileInfo fileInfo = list[i];
|
||||
if (fileInfo.fileName().toLower().endsWith(suffix)) {
|
||||
QString name = fileInfo.fileName().toLower();
|
||||
if (name.endsWith(suffix)) {
|
||||
PColorScheme scheme = ColorScheme::load(fileInfo.absoluteFilePath());
|
||||
mSchemes[scheme->name()]=scheme;
|
||||
name.remove(name.length()-suffix.length(),suffix.length());
|
||||
name.replace('_',' ');
|
||||
mSchemes[name]=scheme;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ColorSchemeItem>;
|
||||
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<ColorSchemeItem>;
|
||||
|
||||
class ColorScheme;
|
||||
using PColorScheme = std::shared_ptr<ColorScheme>;
|
||||
|
@ -70,11 +70,9 @@ public:
|
|||
static PColorScheme load(const QString& filename);
|
||||
|
||||
QMap<QString,PColorSchemeItem> 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<QString,PColorSchemeItem> mItems;
|
||||
QString mName;
|
||||
QString mPreferThemeType;
|
||||
bool mBundled;
|
||||
bool mCustomed;
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -2317,7 +2317,7 @@ void SynEdit::updateCaret()
|
|||
DisplayCoord coord = displayXY();
|
||||
QPoint caretPos = RowColumnToPixels(coord);
|
||||
int caretWidth=mCharWidth;
|
||||
qDebug()<<"caret"<<mCaretX<<mCaretY;
|
||||
//qDebug()<<"caret"<<mCaretX<<mCaretY;
|
||||
if (mCaretY <= mLines->count() && mCaretX <= mLines->getString(mCaretY-1).length()) {
|
||||
caretWidth = charColumns(mLines->getString(mCaretY-1)[mCaretX-1])*mCharWidth;
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox"/>
|
||||
<widget class="QComboBox" name="cbScheme"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton">
|
||||
|
@ -100,20 +100,13 @@
|
|||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QListView" name="listView"/>
|
||||
<widget class="QListView" name="lstItems"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_4" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="checkBox_2">
|
||||
<widget class="QCheckBox" name="cbForeground">
|
||||
<property name="text">
|
||||
<string>Foreground:</string>
|
||||
</property>
|
||||
|
@ -139,21 +132,21 @@
|
|||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_3">
|
||||
<widget class="QCheckBox" name="cbBold">
|
||||
<property name="text">
|
||||
<string>Bold</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_4">
|
||||
<widget class="QCheckBox" name="cbItalic">
|
||||
<property name="text">
|
||||
<string>Italic</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_5">
|
||||
<widget class="QCheckBox" name="cbUnderlined">
|
||||
<property name="text">
|
||||
<string>Underlined</string>
|
||||
</property>
|
||||
|
@ -162,17 +155,30 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="cbBackground">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
<string>Background:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>Background:</string>
|
||||
<item row="0" column="1">
|
||||
<widget class="QFrame" name="colorBackground">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QFrame" name="colorForeground">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
Loading…
Reference in New Issue