From 3a6097c40f04094654c251ad2b7690a1f1afdd29 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sat, 25 Sep 2021 23:12:36 +0800 Subject: [PATCH] class browser color ok --- RedPandaIDE/editor.cpp | 55 +---------------- RedPandaIDE/mainwindow.cpp | 63 ++++++++++++++++++++ RedPandaIDE/mainwindow.h | 3 + RedPandaIDE/mainwindow.ui | 4 +- RedPandaIDE/parser/parserutils.h | 3 +- RedPandaIDE/widgets/classbrowser.cpp | 28 +++++++-- RedPandaIDE/widgets/classbrowser.h | 9 +-- RedPandaIDE/widgets/codecompletionlistview.h | 1 - RedPandaIDE/widgets/codecompletionpopup.cpp | 9 ++- RedPandaIDE/widgets/codecompletionpopup.h | 5 +- 10 files changed, 110 insertions(+), 70 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index e038ddae..bfcec8e7 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -715,7 +715,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to kind = StatementKind::skVariable; } } - foreground = mCompletionPopup->colors().value(kind, + foreground = mCompletionPopup->colors()->value(kind, highlighter()->identifierAttribute()->foreground()); return; } @@ -3020,59 +3020,6 @@ void Editor::applyColorScheme(const QString& schemeName) this->mBreakpointForegroundColor = item->foreground(); this->mBreakpointBackgroundColor = item->background(); } - //color for code completion popup - if (mCompletionPopup) { - item = pColorManager->getItem(schemeName, SYNS_AttrFunction); - if (item) { - mCompletionPopup->colors().insert(StatementKind::skFunction,item->foreground()); - mCompletionPopup->colors().insert(StatementKind::skConstructor,item->foreground()); - mCompletionPopup->colors().insert(StatementKind::skDestructor,item->foreground()); - } - item = pColorManager->getItem(schemeName, SYNS_AttrClass); - if (item) { - mCompletionPopup->colors().insert(StatementKind::skClass,item->foreground()); - mCompletionPopup->colors().insert(StatementKind::skTypedef,item->foreground()); - mCompletionPopup->colors().insert(StatementKind::skAlias,item->foreground()); - } - item = pColorManager->getItem(schemeName, SYNS_AttrIdentifier); - if (item) { - mCompletionPopup->colors().insert(StatementKind::skEnumType,item->foreground()); - mCompletionPopup->colors().insert(StatementKind::skEnumClassType,item->foreground()); - } - item = pColorManager->getItem(schemeName, SYNS_AttrVariable); - if (item) { - mCompletionPopup->colors().insert(StatementKind::skVariable,item->foreground()); - } - item = pColorManager->getItem(schemeName, SYNS_AttrLocalVariable); - if (item) { - mCompletionPopup->colors().insert(StatementKind::skLocalVariable,item->foreground()); - mCompletionPopup->colors().insert(StatementKind::skParameter,item->foreground()); - } - item = pColorManager->getItem(schemeName, SYNS_AttrGlobalVariable); - if (item) { - mCompletionPopup->colors().insert(StatementKind::skGlobalVariable,item->foreground()); - } - item = pColorManager->getItem(schemeName, SYNS_AttrGlobalVariable); - if (item) { - mCompletionPopup->colors().insert(StatementKind::skGlobalVariable,item->foreground()); - } - item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor); - if (item) { - mCompletionPopup->colors().insert(StatementKind::skPreprocessor,item->foreground()); - mCompletionPopup->colors().insert(StatementKind::skEnum,item->foreground()); - mHeaderCompletionPopup->setSuggestionColor(item->foreground()); - } - item = pColorManager->getItem(schemeName, SYNS_AttrReservedWord); - if (item) { - mCompletionPopup->colors().insert(StatementKind::skKeyword,item->foreground()); - mCompletionPopup->colors().insert(StatementKind::skUserCodeIn,item->foreground()); - } - item = pColorManager->getItem(schemeName, SYNS_AttrString); - if (item) { - mCompletionPopup->colors().insert(StatementKind::skNamespace,item->foreground()); - mCompletionPopup->colors().insert(StatementKind::skNamespaceAlias,item->foreground()); - } - } this->invalidate(); } diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index f43f997f..7cb66e67 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -147,10 +147,13 @@ MainWindow::MainWindow(QWidget *parent) connect(&mFileSystemWatcher,&QFileSystemWatcher::fileChanged, this, &MainWindow::onFileChanged); + mStatementColors = std::make_shared >(); mCompletionPopup = std::make_shared(); + mCompletionPopup->setColors(mStatementColors); mHeaderCompletionPopup = std::make_shared(); mFunctionTip = std::make_shared(); + mClassBrowserModel.setColors(mStatementColors); updateAppTitle(); connect(&mAutoSaveTimer, &QTimer::timeout, @@ -164,6 +167,8 @@ MainWindow::MainWindow(QWidget *parent) this, &MainWindow::updateProjectActions); buildContextMenus(); + + updateEditorColorSchemes(); } MainWindow::~MainWindow() @@ -322,6 +327,59 @@ void MainWindow::updateCompileActions() void MainWindow::updateEditorColorSchemes() { mEditorList->applyColorSchemes(pSettings->editor().colorScheme()); + QString schemeName = pSettings->editor().colorScheme(); + //color for code completion popup + 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()); + } + 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()); + } + item = pColorManager->getItem(schemeName, SYNS_AttrIdentifier); + if (item) { + mStatementColors->insert(StatementKind::skEnumType,item->foreground()); + mStatementColors->insert(StatementKind::skEnumClassType,item->foreground()); + } + item = pColorManager->getItem(schemeName, SYNS_AttrVariable); + if (item) { + mStatementColors->insert(StatementKind::skVariable,item->foreground()); + } + item = pColorManager->getItem(schemeName, SYNS_AttrLocalVariable); + if (item) { + mStatementColors->insert(StatementKind::skLocalVariable,item->foreground()); + mStatementColors->insert(StatementKind::skParameter,item->foreground()); + } + item = pColorManager->getItem(schemeName, SYNS_AttrGlobalVariable); + if (item) { + mStatementColors->insert(StatementKind::skGlobalVariable,item->foreground()); + } + item = pColorManager->getItem(schemeName, SYNS_AttrGlobalVariable); + if (item) { + mStatementColors->insert(StatementKind::skGlobalVariable,item->foreground()); + } + item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor); + if (item) { + mStatementColors->insert(StatementKind::skPreprocessor,item->foreground()); + mStatementColors->insert(StatementKind::skEnum,item->foreground()); + mHeaderCompletionPopup->setSuggestionColor(item->foreground()); + } + item = pColorManager->getItem(schemeName, SYNS_AttrReservedWord); + if (item) { + mStatementColors->insert(StatementKind::skKeyword,item->foreground()); + mStatementColors->insert(StatementKind::skUserCodeIn,item->foreground()); + } + item = pColorManager->getItem(schemeName, SYNS_AttrString); + if (item) { + mStatementColors->insert(StatementKind::skNamespace,item->foreground()); + mStatementColors->insert(StatementKind::skNamespaceAlias,item->foreground()); + } } void MainWindow::applySettings() @@ -3370,3 +3428,8 @@ void MainWindow::on_actionProject_Open_In_Terminal_triggered() openShell(mProject->directory(),"cmd.exe"); } +const std::shared_ptr > &MainWindow::statementColors() const +{ + return mStatementColors; +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index b3a9ebfe..d11c6e77 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -111,6 +111,8 @@ public: std::shared_ptr project(); + const std::shared_ptr > &statementColors() const; + public slots: void onCompileLog(const QString& msg); void onCompileIssue(PCompileIssue issue); @@ -369,6 +371,7 @@ private: PSearchResultTreeModel mSearchResultTreeModel; PSearchResultTreeViewDelegate mSearchViewDelegate; ClassBrowserModel mClassBrowserModel; + std::shared_ptr> mStatementColors; bool mCheckSyntaxInBack; bool mOpenClosingBottomPanel; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index ae0ce024..2fb1c84a 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -85,7 +85,7 @@ QTabWidget::West - 1 + 2 true @@ -183,7 +183,7 @@ - false + true false diff --git a/RedPandaIDE/parser/parserutils.h b/RedPandaIDE/parser/parserutils.h index cc2f2af8..3d28824e 100644 --- a/RedPandaIDE/parser/parserutils.h +++ b/RedPandaIDE/parser/parserutils.h @@ -42,6 +42,7 @@ enum class SkipType { skNone // It's a keyword but don't process here }; + enum StatementKind { skUnknown, skPreprocessor, @@ -180,7 +181,7 @@ struct FileIncludes { QSet dependedFiles; // the files depends on me }; using PFileIncludes = std::shared_ptr; - +using ColorCallback = std::function; extern QStringList CppDirectives; extern QStringList JavadocTags; diff --git a/RedPandaIDE/widgets/classbrowser.cpp b/RedPandaIDE/widgets/classbrowser.cpp index 9ef9ff7c..654445b7 100644 --- a/RedPandaIDE/widgets/classbrowser.cpp +++ b/RedPandaIDE/widgets/classbrowser.cpp @@ -1,6 +1,9 @@ #include "classbrowser.h" #include "../utils.h" #include +#include +#include +#include "../mainwindow.h" ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent) { @@ -97,11 +100,9 @@ void ClassBrowserModel::fetchMore(const QModelIndex &parent) bool ClassBrowserModel::canFetchMore(const QModelIndex &parent) const { - if (!parent.isValid()) { // top level return false; } - ClassBrowserNode *parentNode = static_cast(parent.internalPointer()); if (!parentNode->childrenFetched) { if (parentNode->statement && !parentNode->statement->children.isEmpty()) @@ -124,6 +125,17 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const if (node->statement) { return node->statement->command; } + } else if (role == Qt::ForegroundRole) { + if (node->statement) { + PStatement statement = (node->statement); + StatementKind kind; + if (mParser) { + kind = mParser->getKindOfStatement(statement); + } else { + kind = statement->kind; + } + return mColors->value(kind,pMainWindow->palette().color(QPalette::Text)); + } } return QVariant(); } @@ -324,6 +336,16 @@ PStatement ClassBrowserModel::createDummy(PStatement statement) return result; } +const std::shared_ptr > &ClassBrowserModel::colors() const +{ + return mColors; +} + +void ClassBrowserModel::setColors(const std::shared_ptr > &newColors) +{ + mColors = newColors; +} + const QString &ClassBrowserModel::currentFile() const { return mCurrentFile; @@ -348,5 +370,3 @@ void ClassBrowserModel::endUpdate() } } } - - diff --git a/RedPandaIDE/widgets/classbrowser.h b/RedPandaIDE/widgets/classbrowser.h index e93e69ca..1cd294e7 100644 --- a/RedPandaIDE/widgets/classbrowser.h +++ b/RedPandaIDE/widgets/classbrowser.h @@ -37,6 +37,10 @@ public: void beginUpdate(); void endUpdate(); + + const std::shared_ptr > &colors() const; + void setColors(const std::shared_ptr > &newColors); + public slots: void fillStatements(); private: @@ -54,10 +58,7 @@ private: QRecursiveMutex mMutex; QString mCurrentFile; bool mShowInheritedMembers; - - - // QAbstractItemModel interface -public: + std::shared_ptr> mColors; }; #endif // CLASSBROWSER_H diff --git a/RedPandaIDE/widgets/codecompletionlistview.h b/RedPandaIDE/widgets/codecompletionlistview.h index cc939a66..36f22473 100644 --- a/RedPandaIDE/widgets/codecompletionlistview.h +++ b/RedPandaIDE/widgets/codecompletionlistview.h @@ -21,6 +21,5 @@ private: KeyPressedCallback mKeypressedCallback; }; -using ColorCallback = std::function; #endif // CODECOMPLETIONLISTVIEW_H diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index 40145a3e..aa9da9c6 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -19,7 +19,7 @@ CodeCompletionPopup::CodeCompletionPopup(QWidget *parent) : } else { kind = statement->kind; } - return mColors.value(kind,palette().color(QPalette::Text)); + return mColors->value(kind,palette().color(QPalette::Text)); }); mListView->setModel(mModel); setLayout(new QVBoxLayout()); @@ -709,6 +709,11 @@ bool CodeCompletionPopup::isIncluded(const QString &fileName) return mIncludedFiles.contains(fileName); } +void CodeCompletionPopup::setColors(const std::shared_ptr > &newColors) +{ + mColors = newColors; +} + const QString &CodeCompletionPopup::phrase() const { return mPhrase; @@ -729,7 +734,7 @@ void CodeCompletionPopup::setCurrentStatement(const PStatement &newCurrentStatem mCurrentStatement = newCurrentStatement; } -QHash &CodeCompletionPopup::colors() +const std::shared_ptr >& CodeCompletionPopup::colors() const { return mColors; } diff --git a/RedPandaIDE/widgets/codecompletionpopup.h b/RedPandaIDE/widgets/codecompletionpopup.h index 8ae280b2..ee6dd64c 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.h +++ b/RedPandaIDE/widgets/codecompletionpopup.h @@ -64,7 +64,8 @@ public: const PStatement ¤tStatement() const; void setCurrentStatement(const PStatement &newCurrentStatement); - QHash& colors(); + 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: QString mPhrase; QHash mSymbolUsage; QRecursiveMutex mMutex; - QHash mColors; + std::shared_ptr> mColors; PCppParser mParser; PStatement mCurrentStatement;