- 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
- 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
- fix: ConsolePaurser.exe only exits when press ENTER

View File

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

View File

@ -661,6 +661,56 @@ bool ColorManager::saveScheme(const QString &name)
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 filename = generateFilename(name,isCustomed);

View File

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

View File

@ -161,6 +161,7 @@ Editor::Editor(QWidget *parent, const QString& filename,
resetBookmarks();
resetBreakpoints();
}
mStatementColors = pMainWindow->statementColors();
}
Editor::~Editor() {
@ -880,7 +881,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
kind = StatementKind::skVariable;
}
}
PColorSchemeItem item = pMainWindow->statementColors()->value(kind,PColorSchemeItem());
PColorSchemeItem item = mStatementColors->value(kind,PColorSchemeItem());
if (item) {
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
{
return mUseCppSyntax;

View File

@ -272,6 +272,7 @@ private:
QList<PTabStop> mUserCodeInTabStops;
BufferCoord mHighlightCharPos1;
BufferCoord mHighlightCharPos2;
std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mStatementColors;
// QWidget interface
protected:
@ -303,6 +304,9 @@ public:
bool useCppSyntax() const;
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:
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());
QString schemeName = pSettings->editor().colorScheme();
pColorManager->updateStatementColors(mStatementColors,schemeName);
//color for code completion popup
PColorSchemeItem item;
item = pColorManager->getItem(schemeName, SYNS_AttrFunction);
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);
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());
} else {
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);
if (item && haveGoodContrast(item->foreground(), baseColor)) {
mErrorColor = item->foreground();

View File

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

View File

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

View File

@ -5,6 +5,7 @@
#include <QStyleFactory>
#include "../settings.h"
#include "../mainwindow.h"
#include "../thememanager.h"
EnvironmentAppearenceWidget::EnvironmentAppearenceWidget(const QString& name, const QString& group, QWidget *parent) :
SettingsWidget(name,group,parent),
@ -44,6 +45,14 @@ void EnvironmentAppearenceWidget::doLoad()
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().setInterfaceFont(ui->cbFont->currentFont().family());
pSettings->environment().setInterfaceFontSize(ui->spinFontSize->value());

View File

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

View File

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

View File

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

View File

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