- fix: when changing options in the option dialog's color scheme panle, color of the demo editor won't be not correctly updated

- enhancement: Add default color scheme to themes. Change theme option will change color scheme too.
This commit is contained in:
royqh1979@gmail.com 2021-11-07 22:34:19 +08:00
parent b62c166638
commit 3e0925ba70
15 changed files with 105 additions and 49 deletions

View File

@ -1,5 +1,7 @@
Version 0.8.2 For Dev-C++ 7 Beta Version 0.8.2 For Dev-C++ 7 Beta
- fix: highlighter can't correctly find the end of ANSI C-style Comments - fix: highlighter can't correctly find the end of ANSI C-style Comments
- enhancement: Add default color scheme to themes. Change theme option will change color scheme too.
- fix: when changing options in the option dialog's color scheme panle, color of the demo editor won't be not correctly updated
Version 0.8.1 For Dev-C++ 7 Beta Version 0.8.1 For Dev-C++ 7 Beta
- fix: ConsolePaurser.exe only exits when press ENTER - fix: ConsolePaurser.exe only exits when press ENTER

View File

@ -5,6 +5,7 @@
#include "qsynedit/highlighter/asm.h" #include "qsynedit/highlighter/asm.h"
#include "qsynedit/Constants.h" #include "qsynedit/Constants.h"
#include "colorscheme.h" #include "colorscheme.h"
#include <QDebug>
HighlighterManager highlighterManager; HighlighterManager highlighterManager;

View File

@ -661,6 +661,56 @@ bool ColorManager::saveScheme(const QString &name)
return true; return true;
} }
void ColorManager::updateStatementColors(std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > statementColors, const QString &schemeName)
{
PColorSchemeItem item;
item = getItem(schemeName, SYNS_AttrFunction);
if (item) {
statementColors->insert(StatementKind::skFunction,item);
statementColors->insert(StatementKind::skConstructor,item);
statementColors->insert(StatementKind::skDestructor,item);
}
item = getItem(schemeName, SYNS_AttrClass);
if (item) {
statementColors->insert(StatementKind::skClass,item);
statementColors->insert(StatementKind::skTypedef,item);
statementColors->insert(StatementKind::skAlias,item);
}
item = getItem(schemeName, SYNS_AttrIdentifier);
if (item) {
statementColors->insert(StatementKind::skEnumType,item);
statementColors->insert(StatementKind::skEnumClassType,item);
}
item = getItem(schemeName, SYNS_AttrVariable);
if (item) {
statementColors->insert(StatementKind::skVariable,item);
}
item = getItem(schemeName, SYNS_AttrLocalVariable);
if (item) {
statementColors->insert(StatementKind::skLocalVariable,item);
statementColors->insert(StatementKind::skParameter,item);
}
item = getItem(schemeName, SYNS_AttrGlobalVariable);
if (item) {
statementColors->insert(StatementKind::skGlobalVariable,item);
}
item = getItem(schemeName, SYNS_AttrPreprocessor);
if (item) {
statementColors->insert(StatementKind::skPreprocessor,item);
statementColors->insert(StatementKind::skEnum,item);
}
item = getItem(schemeName, SYNS_AttrReservedWord);
if (item) {
statementColors->insert(StatementKind::skKeyword,item);
statementColors->insert(StatementKind::skUserCodeSnippet,item);
}
item = getItem(schemeName, SYNS_AttrString);
if (item) {
statementColors->insert(StatementKind::skNamespace,item);
statementColors->insert(StatementKind::skNamespaceAlias,item);
}
}
QString ColorManager::generateFullPathname(const QString &name, bool isBundled, bool isCustomed) QString ColorManager::generateFullPathname(const QString &name, bool isBundled, bool isCustomed)
{ {
QString filename = generateFilename(name,isCustomed); QString filename = generateFilename(name,isCustomed);

View File

@ -2,7 +2,8 @@
#define COLORSCHEME_H #define COLORSCHEME_H
#include <QColor> #include <QColor>
#include <qsynedit/highlighter/base.h> #include "qsynedit/highlighter/base.h"
#include "parser/statementmodel.h"
#define EXT_COLOR_SCHEME ".scheme" #define EXT_COLOR_SCHEME ".scheme"
#define EXT_PREFIX_CUSTOM ".custom" #define EXT_PREFIX_CUSTOM ".custom"
@ -146,6 +147,9 @@ public:
bool removeDefine(const QString &name); bool removeDefine(const QString &name);
PColorSchemeItemDefine getDefine(const QString& name); PColorSchemeItemDefine getDefine(const QString& name);
bool saveScheme(const QString &name); bool saveScheme(const QString &name);
void updateStatementColors(
std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > statementColors,
const QString& schemeName);
private: private:
QString generateFullPathname(const QString& name, bool isBundled, bool isCustomed); QString generateFullPathname(const QString& name, bool isBundled, bool isCustomed);
QString generateFilename(const QString& name, bool isCustomed); QString generateFilename(const QString& name, bool isCustomed);

View File

@ -161,6 +161,7 @@ Editor::Editor(QWidget *parent, const QString& filename,
resetBookmarks(); resetBookmarks();
resetBreakpoints(); resetBreakpoints();
} }
mStatementColors = pMainWindow->statementColors();
} }
Editor::~Editor() { Editor::~Editor() {
@ -880,7 +881,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
kind = StatementKind::skVariable; kind = StatementKind::skVariable;
} }
} }
PColorSchemeItem item = pMainWindow->statementColors()->value(kind,PColorSchemeItem()); PColorSchemeItem item = mStatementColors->value(kind,PColorSchemeItem());
if (item) { if (item) {
foreground = item->foreground(); foreground = item->foreground();
@ -3138,6 +3139,16 @@ void Editor::onExportedFormatToken(PSynHighlighter syntaxHighlighter, int Line,
} }
} }
const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &Editor::statementColors() const
{
return mStatementColors;
}
void Editor::setStatementColors(const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &newStatementColors)
{
mStatementColors = newStatementColors;
}
bool Editor::useCppSyntax() const bool Editor::useCppSyntax() const
{ {
return mUseCppSyntax; return mUseCppSyntax;

View File

@ -272,6 +272,7 @@ private:
QList<PTabStop> mUserCodeInTabStops; QList<PTabStop> mUserCodeInTabStops;
BufferCoord mHighlightCharPos1; BufferCoord mHighlightCharPos1;
BufferCoord mHighlightCharPos2; BufferCoord mHighlightCharPos2;
std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mStatementColors;
// QWidget interface // QWidget interface
protected: protected:
@ -303,6 +304,9 @@ public:
bool useCppSyntax() const; bool useCppSyntax() const;
void setUseCppSyntax(bool newUseCppSyntax); void setUseCppSyntax(bool newUseCppSyntax);
const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &statementColors() const;
void setStatementColors(const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &newStatementColors);
protected: protected:
void mouseReleaseEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 893 B

After

Width:  |  Height:  |  Size: 484 B

View File

@ -459,62 +459,16 @@ void MainWindow::updateEditorColorSchemes()
mEditorList->applyColorSchemes(pSettings->editor().colorScheme()); mEditorList->applyColorSchemes(pSettings->editor().colorScheme());
QString schemeName = pSettings->editor().colorScheme(); QString schemeName = pSettings->editor().colorScheme();
pColorManager->updateStatementColors(mStatementColors,schemeName);
//color for code completion popup //color for code completion popup
PColorSchemeItem item; PColorSchemeItem item;
item = pColorManager->getItem(schemeName, SYNS_AttrFunction);
QColor baseColor = palette().color(QPalette::Base); QColor baseColor = palette().color(QPalette::Base);
if (item) {
mStatementColors->insert(StatementKind::skFunction,item);
mStatementColors->insert(StatementKind::skConstructor,item);
mStatementColors->insert(StatementKind::skDestructor,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrClass);
if (item) {
mStatementColors->insert(StatementKind::skClass,item);
mStatementColors->insert(StatementKind::skTypedef,item);
mStatementColors->insert(StatementKind::skAlias,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrIdentifier);
if (item) {
mStatementColors->insert(StatementKind::skEnumType,item);
mStatementColors->insert(StatementKind::skEnumClassType,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrVariable);
if (item) {
mStatementColors->insert(StatementKind::skVariable,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrLocalVariable);
if (item) {
mStatementColors->insert(StatementKind::skLocalVariable,item);
mStatementColors->insert(StatementKind::skParameter,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrGlobalVariable);
if (item) {
mStatementColors->insert(StatementKind::skGlobalVariable,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor); item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor);
if (item) { if (item) {
mStatementColors->insert(StatementKind::skPreprocessor,item);
mStatementColors->insert(StatementKind::skEnum,item);
// if (haveGoodContrast(item->foreground(), baseColor)) {
// mHeaderCompletionPopup->setSuggestionColor(item->foreground());
// } else {
// mHeaderCompletionPopup->setSuggestionColor(palette().color(QPalette::Text));
// }
mHeaderCompletionPopup->setSuggestionColor(item->foreground()); mHeaderCompletionPopup->setSuggestionColor(item->foreground());
} else { } else {
mHeaderCompletionPopup->setSuggestionColor(palette().color(QPalette::Text)); mHeaderCompletionPopup->setSuggestionColor(palette().color(QPalette::Text));
} }
item = pColorManager->getItem(schemeName, SYNS_AttrReservedWord);
if (item) {
mStatementColors->insert(StatementKind::skKeyword,item);
mStatementColors->insert(StatementKind::skUserCodeSnippet,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrString);
if (item) {
mStatementColors->insert(StatementKind::skNamespace,item);
mStatementColors->insert(StatementKind::skNamespaceAlias,item);
}
item = pColorManager->getItem(schemeName, COLOR_SCHEME_ERROR); item = pColorManager->getItem(schemeName, COLOR_SCHEME_ERROR);
if (item && haveGoodContrast(item->foreground(), baseColor)) { if (item && haveGoodContrast(item->foreground(), baseColor)) {
mErrorColor = item->foreground(); mErrorColor = item->foreground();

View File

@ -15,6 +15,7 @@ EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QStr
ui(new Ui::EditorColorSchemeWidget) ui(new Ui::EditorColorSchemeWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
mStatementColors = std::make_shared<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> >>();
mDefaultSchemeComboFont = ui->cbScheme->font(); mDefaultSchemeComboFont = ui->cbScheme->font();
mModifiedSchemeComboFont = mDefaultSchemeComboFont; mModifiedSchemeComboFont = mDefaultSchemeComboFont;
@ -67,6 +68,7 @@ EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QStr
"}\n" "}\n"
); );
ui->editDemo->setReadOnly(true); ui->editDemo->setReadOnly(true);
ui->editDemo->setStatementColors(mStatementColors);
onItemSelectionChanged(); onItemSelectionChanged();
} }
@ -225,6 +227,7 @@ void EditorColorSchemeWidget::onItemSelectionChanged()
void EditorColorSchemeWidget::onSettingChanged() void EditorColorSchemeWidget::onSettingChanged()
{ {
pColorManager->updateStatementColors(mStatementColors,ui->cbScheme->currentText());
ui->editDemo->applyColorScheme(ui->cbScheme->currentText()); ui->editDemo->applyColorScheme(ui->cbScheme->currentText());
} }

View File

@ -45,6 +45,7 @@ private:
QFont mModifiedSchemeComboFont; QFont mModifiedSchemeComboFont;
QSet<QString> mModifiedSchemes; QSet<QString> mModifiedSchemes;
QMenu mMenu; QMenu mMenu;
std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mStatementColors;
// SettingsWidget interface // SettingsWidget interface
protected: protected:

View File

@ -5,6 +5,7 @@
#include <QStyleFactory> #include <QStyleFactory>
#include "../settings.h" #include "../settings.h"
#include "../mainwindow.h" #include "../mainwindow.h"
#include "../thememanager.h"
EnvironmentAppearenceWidget::EnvironmentAppearenceWidget(const QString& name, const QString& group, QWidget *parent) : EnvironmentAppearenceWidget::EnvironmentAppearenceWidget(const QString& name, const QString& group, QWidget *parent) :
SettingsWidget(name,group,parent), SettingsWidget(name,group,parent),
@ -44,6 +45,14 @@ void EnvironmentAppearenceWidget::doLoad()
void EnvironmentAppearenceWidget::doSave() void EnvironmentAppearenceWidget::doSave()
{ {
if (pSettings->environment().theme()!=ui->cbTheme->currentText()) {
ThemeManager themeManager;
PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentText());
if (appTheme && !appTheme->defaultColorScheme().isEmpty()) {
pSettings->editor().setColorScheme(appTheme->defaultColorScheme());
pMainWindow->updateEditorColorSchemes();
}
}
pSettings->environment().setTheme(ui->cbTheme->currentText()); pSettings->environment().setTheme(ui->cbTheme->currentText());
pSettings->environment().setInterfaceFont(ui->cbFont->currentFont().family()); pSettings->environment().setInterfaceFont(ui->cbFont->currentFont().family());
pSettings->environment().setInterfaceFontSize(ui->spinFontSize->value()); pSettings->environment().setInterfaceFontSize(ui->spinFontSize->value());

View File

@ -115,6 +115,7 @@ void AppTheme::load(const QString &filename)
QJsonObject obj=doc.object(); QJsonObject obj=doc.object();
mName = obj["name"].toString(); mName = obj["name"].toString();
mIsDark = obj["isDark"].toBool(false); mIsDark = obj["isDark"].toBool(false);
mDefaultColorScheme = obj["default scheme"].toString();
QJsonObject colors = obj["palette"].toObject(); QJsonObject colors = obj["palette"].toObject();
const QMetaObject &m = *metaObject(); const QMetaObject &m = *metaObject();
QMetaEnum e = m.enumerator(m.indexOfEnumerator("ColorRole")); QMetaEnum e = m.enumerator(m.indexOfEnumerator("ColorRole"));
@ -156,6 +157,16 @@ QPalette AppTheme::initialPalette()
return palette; return palette;
} }
const QString &AppTheme::defaultColorScheme() const
{
return mDefaultColorScheme;
}
void AppTheme::setDefaultColorScheme(const QString &newDefaultColorScheme)
{
mDefaultColorScheme = newDefaultColorScheme;
}
bool AppTheme::isDark() const bool AppTheme::isDark() const
{ {
return mIsDark; return mIsDark;

View File

@ -66,12 +66,16 @@ public:
bool isDark() const; bool isDark() const;
const QString &defaultColorScheme() const;
void setDefaultColorScheme(const QString &newDefaultColorScheme);
private: private:
static QPalette initialPalette(); static QPalette initialPalette();
private: private:
QHash<int,QColor> mColors; QHash<int,QColor> mColors;
QString mName; QString mName;
bool mIsDark; bool mIsDark;
QString mDefaultColorScheme;
}; };
using PAppTheme = std::shared_ptr<AppTheme>; using PAppTheme = std::shared_ptr<AppTheme>;

View File

@ -1,6 +1,7 @@
{ {
"name":"dark", "name":"dark",
"isDark": true, "isDark": true,
"default scheme": "VS Code",
"palette": { "palette": {
"PaletteWindow":"#19232D", "PaletteWindow":"#19232D",
"PaletteWindowText":"#E0E1E3", "PaletteWindowText":"#E0E1E3",

View File

@ -1,6 +1,7 @@
{ {
"name":"default", "name":"default",
"isDark":false, "isDark":false,
"default scheme": "Intellij Classic",
"palette": { "palette": {
} }
} }