From 8599190d13b059e076f7f14c79c122c2fe85f8a6 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sun, 10 Oct 2021 21:23:25 +0800 Subject: [PATCH] - fix: font styles in the color scheme settings not in effect --- NEWS.md | 1 + RedPandaIDE/HighlighterManager.cpp | 17 +++----- RedPandaIDE/editor.cpp | 14 ++++++- RedPandaIDE/mainwindow.cpp | 41 ++++++++++--------- RedPandaIDE/mainwindow.h | 5 ++- .../editorcolorschemewidget.cpp | 6 ++- RedPandaIDE/systemconsts.h | 2 +- RedPandaIDE/widgets/classbrowser.cpp | 11 +++-- RedPandaIDE/widgets/classbrowser.h | 8 ++-- RedPandaIDE/widgets/codecompletionpopup.cpp | 11 +++-- RedPandaIDE/widgets/codecompletionpopup.h | 7 ++-- 11 files changed, 72 insertions(+), 51 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2caa224c..a8c9cbe9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ Version 0.6.4 - fix: code completion popup not show after '->' inputted + - fix: font styles in the color scheme settings not in effect Version 0.6.3 - fix: should use c++ syntax to check ".h" files diff --git a/RedPandaIDE/HighlighterManager.cpp b/RedPandaIDE/HighlighterManager.cpp index eef39a49..0020f149 100644 --- a/RedPandaIDE/HighlighterManager.cpp +++ b/RedPandaIDE/HighlighterManager.cpp @@ -96,18 +96,11 @@ void HighlighterManager::applyColorScheme(PSynHighlighter highlighter, const QSt attr->setBackground(item->background()); attr->setForeground(item->foreground()); SynFontStyles styles = SynFontStyle::fsNone; - if (item->bold()) { - styles.setFlag(SynFontStyle::fsBold); - } - if (item->italic()) { - styles.setFlag(SynFontStyle::fsItalic); - } - if (item->underlined()) { - styles.setFlag(SynFontStyle::fsUnderline); - } - if (item->strikeout()) { - styles.setFlag(SynFontStyle::fsStrikeOut); - } + styles.setFlag(SynFontStyle::fsBold, item->bold()); + styles.setFlag(SynFontStyle::fsItalic, item->italic()); + styles.setFlag(SynFontStyle::fsUnderline, item->underlined()); + styles.setFlag(SynFontStyle::fsStrikeOut, item->strikeout()); + attr->setStyles(styles); } } } diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 8b7305dc..67d89cc9 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -845,8 +845,18 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to kind = StatementKind::skVariable; } } - foreground = mCompletionPopup->colors()->value(kind, - highlighter()->identifierAttribute()->foreground()); + PColorSchemeItem item = pMainWindow->statementColors()->value(kind,PColorSchemeItem()); + + if (item) { + foreground = item->foreground(); + //background = item->background(); + style.setFlag(SynFontStyle::fsBold,item->bold()); + style.setFlag(SynFontStyle::fsItalic,item->italic()); + style.setFlag(SynFontStyle::fsUnderline,item->underlined()); + style.setFlag(SynFontStyle::fsStrikeOut,item->strikeout()); + } else { + foreground = highlighter()->identifierAttribute()->foreground(); + } return; } } diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index aa698b70..0b75b285 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -15,6 +15,7 @@ #include "platform.h" #include "widgets/aboutdialog.h" #include "shortcutmanager.h" +#include "colorscheme.h" #include #include @@ -158,7 +159,7 @@ MainWindow::MainWindow(QWidget *parent) connect(&mFileSystemWatcher,&QFileSystemWatcher::fileChanged, this, &MainWindow::onFileChanged); - mStatementColors = std::make_shared >(); + mStatementColors = std::make_shared >(); mCompletionPopup = std::make_shared(); mCompletionPopup->setColors(mStatementColors); mHeaderCompletionPopup = std::make_shared(); @@ -355,49 +356,49 @@ void MainWindow::updateEditorColorSchemes() PColorSchemeItem item; item = pColorManager->getItem(schemeName, SYNS_AttrFunction); if (item) { - mStatementColors->insert(StatementKind::skFunction,item->foreground()); - mStatementColors->insert(StatementKind::skConstructor,item->foreground()); - mStatementColors->insert(StatementKind::skDestructor,item->foreground()); + 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->foreground()); - mStatementColors->insert(StatementKind::skTypedef,item->foreground()); - mStatementColors->insert(StatementKind::skAlias,item->foreground()); + 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->foreground()); - mStatementColors->insert(StatementKind::skEnumClassType,item->foreground()); + mStatementColors->insert(StatementKind::skEnumType,item); + mStatementColors->insert(StatementKind::skEnumClassType,item); } item = pColorManager->getItem(schemeName, SYNS_AttrVariable); if (item) { - mStatementColors->insert(StatementKind::skVariable,item->foreground()); + mStatementColors->insert(StatementKind::skVariable,item); } item = pColorManager->getItem(schemeName, SYNS_AttrLocalVariable); if (item) { - mStatementColors->insert(StatementKind::skLocalVariable,item->foreground()); - mStatementColors->insert(StatementKind::skParameter,item->foreground()); + mStatementColors->insert(StatementKind::skLocalVariable,item); + mStatementColors->insert(StatementKind::skParameter,item); } item = pColorManager->getItem(schemeName, SYNS_AttrGlobalVariable); if (item) { - mStatementColors->insert(StatementKind::skGlobalVariable,item->foreground()); + mStatementColors->insert(StatementKind::skGlobalVariable,item); } item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor); if (item) { - mStatementColors->insert(StatementKind::skPreprocessor,item->foreground()); - mStatementColors->insert(StatementKind::skEnum,item->foreground()); + mStatementColors->insert(StatementKind::skPreprocessor,item); + mStatementColors->insert(StatementKind::skEnum,item); mHeaderCompletionPopup->setSuggestionColor(item->foreground()); } item = pColorManager->getItem(schemeName, SYNS_AttrReservedWord); if (item) { - mStatementColors->insert(StatementKind::skKeyword,item->foreground()); - mStatementColors->insert(StatementKind::skUserCodeSnippet,item->foreground()); + mStatementColors->insert(StatementKind::skKeyword,item); + mStatementColors->insert(StatementKind::skUserCodeSnippet,item); } item = pColorManager->getItem(schemeName, SYNS_AttrString); if (item) { - mStatementColors->insert(StatementKind::skNamespace,item->foreground()); - mStatementColors->insert(StatementKind::skNamespaceAlias,item->foreground()); + mStatementColors->insert(StatementKind::skNamespace,item); + mStatementColors->insert(StatementKind::skNamespaceAlias,item); } } @@ -3922,7 +3923,7 @@ void MainWindow::on_actionProject_Open_In_Terminal_triggered() openShell(mProject->directory(),"cmd.exe"); } -const std::shared_ptr > &MainWindow::statementColors() const +const std::shared_ptr > > &MainWindow::statementColors() const { return mStatementColors; } diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 8da9a385..8d7fa74f 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -35,6 +35,7 @@ class CPUDialog; class QPlainTextEdit; class SearchDialog; class Project; +class ColorSchemeItem; class MainWindow : public QMainWindow { @@ -123,7 +124,7 @@ public: std::shared_ptr project(); - const std::shared_ptr > &statementColors() const; + const std::shared_ptr > > &statementColors() const; PSymbolUsageManager &symbolUsageManager(); @@ -423,7 +424,7 @@ private: PSearchResultTreeModel mSearchResultTreeModel; PSearchResultTreeViewDelegate mSearchViewDelegate; ClassBrowserModel mClassBrowserModel; - std::shared_ptr> mStatementColors; + std::shared_ptr > > mStatementColors; PSymbolUsageManager mSymbolUsageManager; PCodeSnippetManager mCodeSnippetManager; PTodoParser mTodoParser; diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp index 55dfee99..31811621 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp @@ -146,8 +146,8 @@ void EditorColorSchemeWidget::setCurrentSchemeModified() if (scheme) { scheme->setCustomed(true); } - if (mModifiedSchemes.contains(ui->cbScheme->currentText())) - return; +// if (mModifiedSchemes.contains(ui->cbScheme->currentText())) +// return; mModifiedSchemes.insert(ui->cbScheme->currentText()); ui->cbScheme->setItemData(ui->cbScheme->currentIndex(), mModifiedSchemeComboFont,Qt::FontRole); @@ -441,3 +441,5 @@ void EditorColorSchemeWidget::on_actionDelete_Scheme_triggered() QMessageBox::critical(this,tr("Error"),e.reason()); } } + + diff --git a/RedPandaIDE/systemconsts.h b/RedPandaIDE/systemconsts.h index 470f34c6..d383de1b 100644 --- a/RedPandaIDE/systemconsts.h +++ b/RedPandaIDE/systemconsts.h @@ -3,7 +3,7 @@ #include -#define DEVCPP_VERSION "0.6.3" +#define DEVCPP_VERSION "0.6.4" #ifdef Q_OS_WIN #define APP_SETTSINGS_FILENAME "redpandacpp.ini" diff --git a/RedPandaIDE/widgets/classbrowser.cpp b/RedPandaIDE/widgets/classbrowser.cpp index 21b33181..6040e97e 100644 --- a/RedPandaIDE/widgets/classbrowser.cpp +++ b/RedPandaIDE/widgets/classbrowser.cpp @@ -5,6 +5,7 @@ #include #include "../mainwindow.h" #include "../settings.h" +#include "../colorscheme.h" ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent) { @@ -138,7 +139,11 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const if (statement->command.startsWith('#')) kind = StatementKind::skPreprocessor; } - return mColors->value(kind,pMainWindow->palette().color(QPalette::Text)); + PColorSchemeItem item = mColors->value(kind,PColorSchemeItem()); + if (item) { + return item->foreground(); + } + return pMainWindow->palette().color(QPalette::Text); } } else if (role == Qt::DecorationRole) { if (node->statement) { @@ -424,12 +429,12 @@ PStatement ClassBrowserModel::createDummy(PStatement statement) return result; } -const std::shared_ptr > &ClassBrowserModel::colors() const +const std::shared_ptr > > &ClassBrowserModel::colors() const { return mColors; } -void ClassBrowserModel::setColors(const std::shared_ptr > &newColors) +void ClassBrowserModel::setColors(const std::shared_ptr > > &newColors) { mColors = newColors; } diff --git a/RedPandaIDE/widgets/classbrowser.h b/RedPandaIDE/widgets/classbrowser.h index 0e8cd6e6..50346aed 100644 --- a/RedPandaIDE/widgets/classbrowser.h +++ b/RedPandaIDE/widgets/classbrowser.h @@ -13,6 +13,8 @@ struct ClassBrowserNode { using PClassBrowserNode = std::shared_ptr; +class ColorSchemeItem; + class ClassBrowserModel : public QAbstractItemModel{ Q_OBJECT // QAbstractItemModel interface @@ -38,8 +40,8 @@ public: void endUpdate(); - const std::shared_ptr > &colors() const; - void setColors(const std::shared_ptr > &newColors); + const std::shared_ptr > > &colors() const; + void setColors(const std::shared_ptr > > &newColors); public slots: void fillStatements(); @@ -57,7 +59,7 @@ private: int mUpdateCount; QRecursiveMutex mMutex; QString mCurrentFile; - std::shared_ptr> mColors; + std::shared_ptr > > mColors; }; diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index 107c25dc..0b193e94 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -4,6 +4,7 @@ #include "../editor.h" #include "../editorlist.h" #include "../symbolusagemanager.h" +#include "../colorscheme.h" #include #include @@ -23,7 +24,11 @@ CodeCompletionPopup::CodeCompletionPopup(QWidget *parent) : } else { kind = statement->kind; } - return mColors->value(kind,palette().color(QPalette::Text)); + PColorSchemeItem item = mColors->value(kind,PColorSchemeItem()); + if (item) { + return item->foreground(); + } + return palette().color(QPalette::Text); }); mListView->setModel(mModel); setLayout(new QVBoxLayout()); @@ -748,7 +753,7 @@ void CodeCompletionPopup::setCodeSnippets(const QList &newCodeSnip mCodeSnippets = newCodeSnippets; } -void CodeCompletionPopup::setColors(const std::shared_ptr > &newColors) +void CodeCompletionPopup::setColors(const std::shared_ptr > > &newColors) { mColors = newColors; } @@ -773,7 +778,7 @@ void CodeCompletionPopup::setCurrentStatement(const PStatement &newCurrentStatem mCurrentStatement = newCurrentStatement; } -const std::shared_ptr >& CodeCompletionPopup::colors() const +const std::shared_ptr > >& CodeCompletionPopup::colors() const { return mColors; } diff --git a/RedPandaIDE/widgets/codecompletionpopup.h b/RedPandaIDE/widgets/codecompletionpopup.h index 7ab3a202..1f94db9b 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.h +++ b/RedPandaIDE/widgets/codecompletionpopup.h @@ -6,6 +6,7 @@ #include "parser/cppparser.h" #include "codecompletionlistview.h" +class ColorSchemeItem; class CodeCompletionListModel : public QAbstractListModel { Q_OBJECT public: @@ -64,8 +65,8 @@ public: const PStatement ¤tStatement() const; void setCurrentStatement(const PStatement &newCurrentStatement); - const std::shared_ptr >& colors() const; - void setColors(const std::shared_ptr > &newColors); + const std::shared_ptr > >& colors() const; + void setColors(const std::shared_ptr > > &newColors); private: void addChildren(PStatement scopeStatement, const QString& fileName, @@ -86,7 +87,7 @@ private: QSet mAddedStatements; QString mPhrase; QRecursiveMutex mMutex; - std::shared_ptr> mColors; + std::shared_ptr > > mColors; PCppParser mParser; PStatement mCurrentStatement;